Merge pull request #6602 from devansh-webkul/issues/6453

HTTP Kernel Updated #6453
This commit is contained in:
Jitendra Singh 2022-08-02 18:55:53 +05:30 committed by GitHub
commit c6c27815a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 68 additions and 48 deletions

View File

@ -16,9 +16,7 @@ jobs:
image: mysql:5.7 image: mysql:5.7
env: env:
MYSQL_ROOT_PASSWORD: root MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: bagisto_testing MYSQL_DATABASE: bagisto
MYSQL_USER: bagisto
MYSQL_PASSWORD: secret
ports: ports:
- 3306 - 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5 options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5
@ -42,11 +40,12 @@ jobs:
run: | run: |
cp .env.example .env.testing cp .env.example .env.testing
set -e set -e
sed -i "s|^\(APP_ENV=\s*\).*$|\1testing|" .env.testing
sed -i "s|^\(DB_HOST=\s*\).*$|\1127.0.0.1|" .env.testing sed -i "s|^\(DB_HOST=\s*\).*$|\1127.0.0.1|" .env.testing
sed -i "s|^\(DB_PORT=\s*\).*$|\1${{ job.services.mysql.ports['3306'] }}|" .env.testing sed -i "s|^\(DB_PORT=\s*\).*$|\1${{ job.services.mysql.ports['3306'] }}|" .env.testing
sed -i "s|^\(DB_DATABASE=\s*\).*$|\1bagisto_testing|" .env.testing sed -i "s|^\(DB_DATABASE=\s*\).*$|\1bagisto|" .env.testing
sed -i "s|^\(DB_USERNAME=\s*\).*$|\1bagisto|" .env.testing sed -i "s|^\(DB_USERNAME=\s*\).*$|\1root|" .env.testing
sed -i "s|^\(DB_PASSWORD=\s*\).*$|\1secret|" .env.testing sed -i "s|^\(DB_PASSWORD=\s*\).*$|\1root|" .env.testing
- name: Key Generate - name: Key Generate
run: set -e && php artisan key:generate --env=testing run: set -e && php artisan key:generate --env=testing

View File

@ -14,11 +14,11 @@ class Kernel extends HttpKernel
* @var array * @var array
*/ */
protected $middleware = [ protected $middleware = [
\App\Http\Middleware\TrustProxies::class,
\Illuminate\Http\Middleware\HandleCors::class, \Illuminate\Http\Middleware\HandleCors::class,
\Webkul\Core\Http\Middleware\CheckForMaintenanceMode::class, \Webkul\Core\Http\Middleware\CheckForMaintenanceMode::class,
\App\Http\Middleware\EncryptCookies::class, \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \App\Http\Middleware\TrimStrings::class,
\Illuminate\Session\Middleware\StartSession::class,
\Webkul\Core\Http\Middleware\SecureHeaders::class, \Webkul\Core\Http\Middleware\SecureHeaders::class,
]; ];
@ -29,7 +29,9 @@ class Kernel extends HttpKernel
*/ */
protected $middlewareGroups = [ protected $middlewareGroups = [
'web' => [ 'web' => [
\Illuminate\Session\Middleware\AuthenticateSession::class, \App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class, \App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class, \Illuminate\Routing\Middleware\SubstituteBindings::class,
@ -52,6 +54,7 @@ class Kernel extends HttpKernel
protected $routeMiddleware = [ protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate::class, 'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class, 'can' => \Illuminate\Auth\Middleware\Authorize::class,

View File

@ -139,14 +139,16 @@
"@php artisan migrate:fresh --env=testing", "@php artisan migrate:fresh --env=testing",
"vendor/bin/codecept run unit", "vendor/bin/codecept run unit",
"vendor/bin/codecept run functional", "vendor/bin/codecept run functional",
"vendor/bin/codecept run trigger" "vendor/bin/codecept run trigger",
"vendor/bin/codecept run api"
], ],
"test-win": [ "test-win": [
"@set -e", "@set -e",
"@php artisan migrate:fresh --env=testing", "@php artisan migrate:fresh --env=testing",
"vendor\\bin\\codecept.bat run unit", "vendor\\bin\\codecept.bat run unit",
"vendor\\bin\\codecept.bat run functional", "vendor\\bin\\codecept.bat run functional",
"vendor\\bin\\codecept.bat run trigger" "vendor\\bin\\codecept.bat run trigger",
"vendor\\bin\\codecept.bat run api"
] ]
}, },
"config": { "config": {

View File

@ -30,8 +30,6 @@ class AddressController extends Controller
public function __construct(protected CustomerAddressRepository $customerAddressRepository) public function __construct(protected CustomerAddressRepository $customerAddressRepository)
{ {
$this->_config = request('_config'); $this->_config = request('_config');
$this->customer = auth()->guard('customer')->user();
} }
/** /**
@ -41,7 +39,9 @@ class AddressController extends Controller
*/ */
public function index() public function index()
{ {
return view($this->_config['view'])->with('addresses', $this->customer->addresses); $customer = auth()->guard('customer')->user();
return view($this->_config['view'])->with('addresses', $customer->addresses);
} }
/** /**
@ -63,12 +63,14 @@ class AddressController extends Controller
*/ */
public function store(CustomerAddressRequest $request) public function store(CustomerAddressRequest $request)
{ {
$customer = auth()->guard('customer')->user();
$data = $request->all(); $data = $request->all();
$data['customer_id'] = $this->customer->id; $data['customer_id'] = $customer->id;
$data['address1'] = implode(PHP_EOL, array_filter(request()->input('address1'))); $data['address1'] = implode(PHP_EOL, array_filter(request()->input('address1')));
if ($this->customer->addresses->count() == 0) { if ($customer->addresses->count() == 0) {
$data['default_address'] = 1; $data['default_address'] = 1;
} }
@ -90,9 +92,11 @@ class AddressController extends Controller
*/ */
public function edit($id) public function edit($id)
{ {
$customer = auth()->guard('customer')->user();
$address = $this->customerAddressRepository->findOneWhere([ $address = $this->customerAddressRepository->findOneWhere([
'id' => $id, 'id' => $id,
'customer_id' => $this->customer->id, 'customer_id' => $customer->id,
]); ]);
if (! $address) { if (! $address) {
@ -112,11 +116,13 @@ class AddressController extends Controller
*/ */
public function update($id, CustomerAddressRequest $request) public function update($id, CustomerAddressRequest $request)
{ {
$customer = auth()->guard('customer')->user();
$data = $request->all(); $data = $request->all();
$data['address1'] = implode(PHP_EOL, array_filter(request()->input('address1'))); $data['address1'] = implode(PHP_EOL, array_filter(request()->input('address1')));
$addresses = $this->customer->addresses; $addresses = $customer->addresses;
foreach ($addresses as $address) { foreach ($addresses as $address) {
if ($id == $address->id) { if ($id == $address->id) {
@ -141,7 +147,9 @@ class AddressController extends Controller
*/ */
public function makeDefault($id) public function makeDefault($id)
{ {
if ($default = $this->customer->default_address) { $customer = auth()->guard('customer')->user();
if ($default = $customer->default_address) {
$this->customerAddressRepository->find($default->id)->update(['default_address' => 0]); $this->customerAddressRepository->find($default->id)->update(['default_address' => 0]);
} }
@ -162,9 +170,11 @@ class AddressController extends Controller
*/ */
public function destroy($id) public function destroy($id)
{ {
$customer = auth()->guard('customer')->user();
$address = $this->customerAddressRepository->findOneWhere([ $address = $this->customerAddressRepository->findOneWhere([
'id' => $id, 'id' => $id,
'customer_id' => $this->customer->id, 'customer_id' => $customer->id,
]); ]);
if (! $address) { if (! $address) {

View File

@ -78,7 +78,7 @@ class SessionController extends Controller
*/ */
Event::dispatch('customer.after.login', $request->get('email')); Event::dispatch('customer.after.login', $request->get('email'));
return redirect()->intended(route($this->_config['redirect'])); return redirect()->route($this->_config['redirect']);
} }
/** /**

View File

@ -36,8 +36,6 @@ class WishlistController extends Controller
) )
{ {
$this->_config = request('_config'); $this->_config = request('_config');
$this->currentCustomer = auth()->guard('customer')->user();
} }
/** /**
@ -47,6 +45,8 @@ class WishlistController extends Controller
*/ */
public function index() public function index()
{ {
$customer = auth()->guard('customer')->user();
if (! core()->getConfigData('general.content.shop.wishlist_option')) { if (! core()->getConfigData('general.content.shop.wishlist_option')) {
abort(404); abort(404);
} }
@ -54,8 +54,8 @@ class WishlistController extends Controller
return view($this->_config['view'], [ return view($this->_config['view'], [
'items' => $this->wishlistRepository->getCustomerWishlist(), 'items' => $this->wishlistRepository->getCustomerWishlist(),
'isSharingEnabled' => $this->isSharingEnabled(), 'isSharingEnabled' => $this->isSharingEnabled(),
'isWishlistShared' => $this->currentCustomer->isWishlistShared(), 'isWishlistShared' => $customer->isWishlistShared(),
'wishlistSharedLink' => $this->currentCustomer->getWishlistSharedLink() 'wishlistSharedLink' => $customer->getWishlistSharedLink()
]); ]);
} }
@ -67,6 +67,8 @@ class WishlistController extends Controller
*/ */
public function add($itemId) public function add($itemId)
{ {
$customer = auth()->guard('customer')->user();
$product = $this->productRepository->find($itemId); $product = $this->productRepository->find($itemId);
if ( $product == null ) { if ( $product == null ) {
@ -79,13 +81,13 @@ class WishlistController extends Controller
$data = [ $data = [
'channel_id' => core()->getCurrentChannel()->id, 'channel_id' => core()->getCurrentChannel()->id,
'product_id' => $itemId, 'product_id' => $itemId,
'customer_id' => $this->currentCustomer->id, 'customer_id' => $customer->id,
]; ];
$checked = $this->wishlistRepository->findWhere([ $checked = $this->wishlistRepository->findWhere([
'channel_id' => core()->getCurrentChannel()->id, 'channel_id' => core()->getCurrentChannel()->id,
'product_id' => $itemId, 'product_id' => $itemId,
'customer_id' => $this->currentCustomer->id, 'customer_id' => $customer->id,
]); ]);
if ( if (
@ -124,20 +126,22 @@ class WishlistController extends Controller
*/ */
public function share() public function share()
{ {
$customer = auth()->guard('customer')->user();
if ($this->isSharingEnabled()) { if ($this->isSharingEnabled()) {
$data = $this->validate(request(), [ $data = $this->validate(request(), [
'shared' => 'required|boolean' 'shared' => 'required|boolean'
]); ]);
$updateCounts = $this->currentCustomer->wishlist_items()->update(['shared' => $data['shared']]); $updateCounts = $customer->wishlist_items()->update(['shared' => $data['shared']]);
if ( if (
$updateCounts $updateCounts
&& $updateCounts > 0 && $updateCounts > 0
) { ) {
return response()->json([ return response()->json([
'isWishlistShared' => $this->currentCustomer->isWishlistShared(), 'isWishlistShared' => $customer->isWishlistShared(),
'wishlistSharedLink' => $this->currentCustomer->getWishlistSharedLink() 'wishlistSharedLink' => $customer->getWishlistSharedLink()
]); ]);
} }
} }
@ -185,7 +189,9 @@ class WishlistController extends Controller
*/ */
public function remove($itemId) public function remove($itemId)
{ {
$customerWishlistItems = $this->currentCustomer->wishlist_items; $customer = auth()->guard('customer')->user();
$customerWishlistItems = $customer->wishlist_items;
foreach ($customerWishlistItems as $customerWishlistItem) { foreach ($customerWishlistItems as $customerWishlistItem) {
if ($itemId == $customerWishlistItem->id) { if ($itemId == $customerWishlistItem->id) {
@ -210,9 +216,11 @@ class WishlistController extends Controller
*/ */
public function move($itemId) public function move($itemId)
{ {
$customer = auth()->guard('customer')->user();
$wishlistItem = $this->wishlistRepository->findOneWhere([ $wishlistItem = $this->wishlistRepository->findOneWhere([
'id' => $itemId, 'id' => $itemId,
'customer_id' => $this->currentCustomer->id, 'customer_id' => $customer->id,
]); ]);
if (! $wishlistItem) { if (! $wishlistItem) {
@ -247,7 +255,9 @@ class WishlistController extends Controller
*/ */
public function removeAll() public function removeAll()
{ {
$wishlistItems = $this->currentCustomer->wishlist_items; $customer = auth()->guard('customer')->user();
$wishlistItems = $customer->wishlist_items;
if ($wishlistItems->count() > 0) { if ($wishlistItems->count() > 0) {
foreach ($wishlistItems as $wishlistItem) { foreach ($wishlistItems as $wishlistItem) {

View File

@ -23,8 +23,6 @@ class OrderController extends Controller
protected InvoiceRepository $invoiceRepository protected InvoiceRepository $invoiceRepository
) )
{ {
$this->currentCustomer = auth()->guard('customer')->user();
parent::__construct(); parent::__construct();
} }
@ -50,8 +48,10 @@ class OrderController extends Controller
*/ */
public function view($id) public function view($id)
{ {
$customer = auth()->guard('customer')->user();
$order = $this->orderRepository->findOneWhere([ $order = $this->orderRepository->findOneWhere([
'customer_id' => $this->currentCustomer->id, 'customer_id' => $customer->id,
'id' => $id, 'id' => $id,
]); ]);
@ -70,9 +70,11 @@ class OrderController extends Controller
*/ */
public function printInvoice($id) public function printInvoice($id)
{ {
$customer = auth()->guard('customer')->user();
$invoice = $this->invoiceRepository->findOrFail($id); $invoice = $this->invoiceRepository->findOrFail($id);
if ($invoice->order->customer_id !== $this->currentCustomer->id) { if ($invoice->order->customer_id !== $customer->id) {
abort(404); abort(404);
} }
@ -90,8 +92,10 @@ class OrderController extends Controller
*/ */
public function cancel($id) public function cancel($id)
{ {
$customer = auth()->guard('customer')->user();
/* find by order id in customer's order */ /* find by order id in customer's order */
$order = $this->currentCustomer->all_orders()->find($id); $order = $customer->all_orders()->find($id);
/* if order id not found then process should be aborted with 404 page */ /* if order id not found then process should be aborted with 404 page */
if (! $order) { if (! $order) {

View File

@ -200,8 +200,6 @@ abstract class DataGrid
public function __construct() public function __construct()
{ {
$this->invoker = $this; $this->invoker = $this;
$this->currentUser = auth()->guard('admin')->user();
} }
/** /**

View File

@ -29,7 +29,7 @@ class AuthCest extends CustomerCest
$I->haveAllNecessaryHeaders(); $I->haveAllNecessaryHeaders();
$I->sendPost($this->getVersionRoute('customer/login'), [ $I->sendPost($this->getVersionRoute('customer/login?accept_token=true'), [
'email' => $customer->email, 'email' => $customer->email,
'password' => json_decode($customer->notes)->plain_password, 'password' => json_decode($customer->notes)->plain_password,
'device_name' => $I->fake()->company, 'device_name' => $I->fake()->company,

View File

@ -65,8 +65,6 @@ class CheckoutCest extends CustomerCest
private function saveShippingMethod(ApiTester $I) private function saveShippingMethod(ApiTester $I)
{ {
$I->haveHttpHeader('X-CSRF-TOKEN', csrf_token());
$I->sendPost($this->getVersionRoute('customer/checkout/save-shipping'), [ $I->sendPost($this->getVersionRoute('customer/checkout/save-shipping'), [
'shipping_method' => 'flatrate_flatrate', 'shipping_method' => 'flatrate_flatrate',
]); ]);
@ -76,8 +74,6 @@ class CheckoutCest extends CustomerCest
private function savePaymentMethod(ApiTester $I) private function savePaymentMethod(ApiTester $I)
{ {
$I->haveHttpHeader('X-CSRF-TOKEN', csrf_token());
$I->sendPost($this->getVersionRoute('customer/checkout/save-payment'), [ $I->sendPost($this->getVersionRoute('customer/checkout/save-payment'), [
'payment' => [ 'payment' => [
'method' => 'cashondelivery', 'method' => 'cashondelivery',
@ -89,8 +85,6 @@ class CheckoutCest extends CustomerCest
private function saveOrder(ApiTester $I) private function saveOrder(ApiTester $I)
{ {
$I->haveHttpHeader('X-CSRF-TOKEN', csrf_token());
$I->sendPost($this->getVersionRoute('customer/checkout/save-order')); $I->sendPost($this->getVersionRoute('customer/checkout/save-order'));
$I->seeAllNecessarySuccessResponse(); $I->seeAllNecessarySuccessResponse();