mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
Merge branch 'dillon/83-yd-order-tracking-query-ui' into vapor/development
This commit is contained in:
@@ -5,7 +5,6 @@ namespace App\Classes\Modules\Orders\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Orders\Services\ListsOrderTracking;
|
||||
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||
use App\Http\Resources\OrderTrackingResource;
|
||||
use App\Models\Order;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -14,6 +13,7 @@ use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use App\Classes\Modules\Orders\Standards\Rules\CanListTrackings;
|
||||
|
||||
class ListOrderTrackingLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -30,12 +30,17 @@ class ListOrderTrackingLogic extends AbstractControllerLogic
|
||||
/** @var ListsOrderTracking */
|
||||
private $listsOrderTracking;
|
||||
|
||||
/** @var CanListTrackings */
|
||||
private $canListTrackings;
|
||||
|
||||
/**
|
||||
* ListOrderTrackingLogic constructor.
|
||||
* @param CanListTrackings $canListTrackings
|
||||
* @param ListsOrderTracking $listsOrderTracking
|
||||
*/
|
||||
public function __construct(ListsOrderTracking $listsOrderTracking)
|
||||
public function __construct(CanListTrackings $canListTrackings, ListsOrderTracking $listsOrderTracking)
|
||||
{
|
||||
$this->canListTrackings = $canListTrackings;
|
||||
$this->listsOrderTracking = $listsOrderTracking;
|
||||
}
|
||||
|
||||
@@ -50,9 +55,10 @@ class ListOrderTrackingLogic extends AbstractControllerLogic
|
||||
$trackingNo = str_replace('_01', '', $trackingNo);
|
||||
} catch (DecryptException $e) {
|
||||
Log::info('Decryption failed, string might already be decrypted or invalid.');
|
||||
if(!in_array(Auth()->user()->type, [RoleTypes::SHADOW_ADMIN, RoleTypes::SUPER_ADMIN])){
|
||||
abort(404);
|
||||
}
|
||||
$this->canListTrackings->passes();
|
||||
// if(!in_array(Auth()->user()->type, [RoleTypes::SHADOW_ADMIN, RoleTypes::SUPER_ADMIN])){
|
||||
// abort(404);
|
||||
// }
|
||||
}
|
||||
|
||||
if (preg_match('/^\d{9}$/', $trackingNo)) {
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Orders\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||
|
||||
|
||||
class CanListTrackings extends AbstractRule
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
if(Auth()->user()){
|
||||
$roleToCheck = Auth()->user()->type;
|
||||
if (in_array($roleToCheck, RoleTypes::ADMIN_ROLES)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BookingObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BookingObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -2,35 +2,35 @@
|
||||
|
||||
namespace Tests\Unit\App\Classes\Modules\Orders\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\Exceptions\AccessForbiddenException;
|
||||
use App\Classes\Modules\Orders\ControllersLogic\ListOrderTrackingLogic;
|
||||
use App\Classes\Modules\Orders\Services\ListsOrderTracking;
|
||||
use App\Classes\Modules\Orders\Standards\Rules\CanListTrackings;
|
||||
use App\Models\Order;
|
||||
use App\Models\PackingList;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Mockery;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Tests\TestCaseChild;
|
||||
|
||||
class ListOrderTrackingLogicTest extends TestCaseChild
|
||||
{
|
||||
protected $listsOrderTrackingMock;
|
||||
protected $listOrderTrackingLogic;
|
||||
protected $canListTrackingsMock;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->canListTrackingsMock = Mockery::mock(CanListTrackings::class);
|
||||
$this->listsOrderTrackingMock = Mockery::mock(ListsOrderTracking::class);
|
||||
$this->listOrderTrackingLogic = new ListOrderTrackingLogic($this->listsOrderTrackingMock);
|
||||
$this->listOrderTrackingLogic = new ListOrderTrackingLogic($this->canListTrackingsMock, $this->listsOrderTrackingMock);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
@@ -122,8 +122,12 @@ class ListOrderTrackingLogicTest extends TestCaseChild
|
||||
Crypt::shouldReceive('decryptString')->andThrow(DecryptException::class);
|
||||
$request = Request::create('/tracking', 'GET', ['filters' => json_encode(['tracking_no' => 'test'])]);
|
||||
|
||||
$this->canListTrackingsMock
|
||||
->shouldReceive('passes')
|
||||
->andThrow(new AccessForbiddenException("You don't have permission to perform this action"));
|
||||
|
||||
// Assert
|
||||
$this->expectException(NotFoundHttpException::class);
|
||||
$this->expectException(AccessForbiddenException::class);
|
||||
|
||||
// Act
|
||||
$this->listOrderTrackingLogic->logic($request);
|
||||
|
||||
Reference in New Issue
Block a user