ldc-groupe/app/Policies/DynamicPagePolicy.php
2025-10-17 14:52:51 +02:00

79 lines
2.2 KiB
PHP

<?php
namespace App\Policies;
use App\Models\DynamicPage;
use Illuminate\Database\Eloquent\Model;
use Uwil\LaravelBackend\Enums\RoleEnum;
use Uwil\LaravelBackend\Policies\Rules\UserStaticRules;
class DynamicPagePolicy
{
/**
* Determine whether the user can view any models.
*
* @param \Illuminate\Database\Eloquent\Model $authModel
* @return boolean
*/
public function viewAny(Model $authModel): bool
{
return UserStaticRules::atLeastRole($authModel, RoleEnum::admin);
}
/**
* Determine whether the user can view the model.
*
* @param \Illuminate\Database\Eloquent\Model $authModel
* @return boolean
*/
public function view(Model $authModel): bool
{
return UserStaticRules::atLeastRole($authModel, RoleEnum::admin);
}
/**
* Determine whether the user can create models.
*
* @param \Illuminate\Database\Eloquent\Model $authModel
* @return boolean
*/
public function create(Model $authModel): bool
{
return UserStaticRules::atLeastRole($authModel, RoleEnum::admin);
}
/**
* Determine whether the user can update the model.
*
* @param \Illuminate\Database\Eloquent\Model $authModel
* @return boolean
*/
public function update(Model $authModel): bool
{
return UserStaticRules::atLeastRole($authModel, RoleEnum::admin);
}
/**
* Determine whether the user can delete the model.
*
* @param \Illuminate\Database\Eloquent\Model $authModel
* @param \App\Models\DynamicPage $dynamicPageModel
* @return boolean
*/
public function delete(Model $authModel, DynamicPage $dynamicPageModel): bool
{
return (!$dynamicPageModel->isLocked && UserStaticRules::atLeastRole($authModel, RoleEnum::admin))
|| UserStaticRules::atLeastRole($authModel, RoleEnum::conceptor);
}
/**
* Determine whether the user can duplicate the model.
*
* @param \Illuminate\Database\Eloquent\Model $authModel
* @return boolean
*/
public function duplicate(Model $authModel): bool
{
return UserStaticRules::atLeastRole($authModel, RoleEnum::admin);
}
}