62 lines
1.6 KiB
PHP
62 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Enums\Users\RoleEnum;
|
|
use App\Models\Section;
|
|
use App\Models\User;
|
|
use App\Policies\Rules\UserStaticRules;
|
|
|
|
class SectionPolicy
|
|
{
|
|
/**
|
|
* Determine whether the user can view any models.
|
|
*
|
|
* @param \App\Models\User $authUser
|
|
* @return boolean
|
|
*/
|
|
public function viewAny(User $authUser): bool
|
|
{
|
|
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can update the model.
|
|
*
|
|
* @param \App\Models\User $authUser
|
|
* @return boolean
|
|
*/
|
|
public function update(User $authUser): bool
|
|
{
|
|
// phpcs:enable
|
|
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
|
}
|
|
|
|
/**
|
|
* Can add part piece
|
|
*
|
|
* @param \App\Models\User $authUser
|
|
* @param \App\Models\Section $section
|
|
* @return boolean
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
|
*/
|
|
public function addPartPiece(User $authUser, Section $section): bool
|
|
{
|
|
// phpcs:enable
|
|
return Section::getAddablePartPieceBlock($section->section) !== null;
|
|
}
|
|
|
|
/**
|
|
* Can remove part piece
|
|
*
|
|
* @param \App\Models\User $authUser
|
|
* @param \App\Models\Section $section
|
|
* @return boolean
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
|
*/
|
|
public function removePartPiece(User $authUser, Section $section): bool
|
|
{
|
|
// phpcs:enable
|
|
return Section::getAddablePartPieceBlock($section->section) !== null;
|
|
}
|
|
}
|