fix(bo): check proper model policy in ranges and pickup exceptions index views
This commit is contained in:
parent
13aec6bad8
commit
4bbea5d285
4 changed files with 90 additions and 2 deletions
|
|
@ -19,7 +19,7 @@
|
|||
</div>
|
||||
<div class="col-3">
|
||||
<div class="input-group justify-content-end">
|
||||
@can('create', \App\Models\Slide::class)
|
||||
@can('create', \App\Models\PickupException::class)
|
||||
<a class="btn btn-primary" href="{{ route('bo.pickup-exceptions.create') }}"
|
||||
title="{{ Str::ucfirst(__('crud.actions.create')) }} {{ Str::ucfirst(trans_choice('models.classes.pickup-exceptions', \INF)) }}"><i
|
||||
class="fa-solid fa-square-plus"></i></a>
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
</div>
|
||||
<h1 class="col-3">
|
||||
<div class="input-group justify-content-end">
|
||||
@can('create', \App\Models\Tag::class)
|
||||
@can('create', \App\Models\Range::class)
|
||||
<a class="btn btn-primary" href="{{ route('bo.ranges.create') }}"
|
||||
title="{{ Str::ucfirst(__('crud.actions.create')) }} {{ __('models.classes.ranges') }}"><i
|
||||
class="fa-solid fa-square-plus"></i></a>
|
||||
|
|
|
|||
|
|
@ -3,9 +3,13 @@
|
|||
declare(strict_types=1);
|
||||
|
||||
use App\Models\PickupException;
|
||||
use App\Models\Slide;
|
||||
use App\Models\User;
|
||||
use Domain\Enums\RepeatFrequency;
|
||||
use Domain\Enums\UserRole;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
use function Pest\Laravel\get;
|
||||
|
||||
describe('PickupExceptionsController', function () {
|
||||
beforeEach(function () {
|
||||
|
|
@ -108,4 +112,45 @@ describe('PickupExceptionsController', function () {
|
|||
expect(PickupException::query()->find($pickupException->id))->toBeNull();
|
||||
$response->assertRedirect('/bo/pickup-exceptions');
|
||||
});
|
||||
|
||||
it('checks PickupExceptionPolicy create permission instead of SlidePolicy on index', function (): void {
|
||||
// GIVEN
|
||||
$deniedSlidePolicy = new class ()
|
||||
{
|
||||
public function create(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Gate::policy(Slide::class, $deniedSlidePolicy::class);
|
||||
|
||||
// WHEN
|
||||
$responseWhenSlideCreateDenied = get(route('bo.pickup-exceptions.index'));
|
||||
|
||||
// THEN
|
||||
$responseWhenSlideCreateDenied->assertOk();
|
||||
$responseWhenSlideCreateDenied->assertSee(route('bo.pickup-exceptions.create'));
|
||||
|
||||
// GIVEN
|
||||
$pickupExceptionPolicyWithoutCreate = new class ()
|
||||
{
|
||||
public function viewAny(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function create(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Gate::policy(PickupException::class, $pickupExceptionPolicyWithoutCreate::class);
|
||||
|
||||
// WHEN
|
||||
$responseWhenPickupExceptionCreateDenied = get(route('bo.pickup-exceptions.index'));
|
||||
|
||||
// THEN
|
||||
$responseWhenPickupExceptionCreateDenied->assertOk();
|
||||
$responseWhenPickupExceptionCreateDenied->assertDontSee(route('bo.pickup-exceptions.create'));
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
use App\Http\Requests\Bo\Ranges\StoreRangeRequest;
|
||||
use App\Models\Range;
|
||||
use App\Models\Tag;
|
||||
use App\Models\User;
|
||||
use Domain\Enums\UserRole;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
|
@ -12,6 +13,7 @@ use Illuminate\Support\Facades\Gate;
|
|||
use Uwil\Storage\Contracts\StorageService;
|
||||
use Uwil\Storage\Lib\ValueObjects\StorageFilePath;
|
||||
|
||||
use function Pest\Laravel\get;
|
||||
use function Pest\Laravel\patch;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
|
@ -189,6 +191,47 @@ describe('RangesController', function () {
|
|||
expect($range->status)->toBeTrue();
|
||||
});
|
||||
|
||||
it('checks RangePolicy create permission instead of TagPolicy on index', function (): void {
|
||||
// GIVEN
|
||||
$deniedTagPolicy = new class ()
|
||||
{
|
||||
public function create(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Gate::policy(Tag::class, $deniedTagPolicy::class);
|
||||
|
||||
// WHEN
|
||||
$responseWhenTagCreateDenied = get(route('bo.ranges.index'));
|
||||
|
||||
// THEN
|
||||
$responseWhenTagCreateDenied->assertOk();
|
||||
$responseWhenTagCreateDenied->assertSee(route('bo.ranges.create'));
|
||||
|
||||
// GIVEN
|
||||
$rangePolicyWithoutCreate = new class ()
|
||||
{
|
||||
public function viewAny(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function create(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Gate::policy(Range::class, $rangePolicyWithoutCreate::class);
|
||||
|
||||
// WHEN
|
||||
$responseWhenRangeCreateDenied = get(route('bo.ranges.index'));
|
||||
|
||||
// THEN
|
||||
$responseWhenRangeCreateDenied->assertOk();
|
||||
$responseWhenRangeCreateDenied->assertDontSee(route('bo.ranges.create'));
|
||||
});
|
||||
|
||||
it('forbids changeOrder when update policy denies access', function (): void {
|
||||
// GIVEN
|
||||
$range = new Range();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue