You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.3 KiB
57 lines
1.3 KiB
<?php
|
|
|
|
namespace App\Domains\Identity\Policies;
|
|
|
|
use App\Domains\Identity\Enums\RoleType;
|
|
use App\Domains\Identity\Models\User;
|
|
|
|
class UserPolicy
|
|
{
|
|
/**
|
|
* Determine whether the user can view any models.
|
|
*/
|
|
public function viewAny(User $user): bool
|
|
{
|
|
return $user->hasPermissionTo('user.viewAny');
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can view the model.
|
|
*/
|
|
public function view(User $user, User $model): bool
|
|
{
|
|
return $user->hasPermissionTo('user.view');
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can create models.
|
|
*/
|
|
public function create(User $user): bool
|
|
{
|
|
return $user->hasPermissionTo('user.create');
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can update the model.
|
|
*/
|
|
public function update(User $user, User $model): bool
|
|
{
|
|
if ($model->hasRole(RoleType::SYSTEM_ADMIN)) {
|
|
return false;
|
|
}
|
|
|
|
return $user->hasPermissionTo('user.update');
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can delete the model.
|
|
*/
|
|
public function delete(User $user, User $model): bool
|
|
{
|
|
if ($model->hasRole(RoleType::SYSTEM_ADMIN)) {
|
|
return false;
|
|
}
|
|
|
|
return $user->hasPermissionTo('user.delete');
|
|
}
|
|
}
|
|
|