75 lines
1.6 KiB
PHP
75 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Enums\RoleName;
|
|
use App\Models\User;
|
|
use Log;
|
|
|
|
class UserPolicy
|
|
{
|
|
public function before(User $user, string $ability): bool|null
|
|
{
|
|
if (!$user->isAn(RoleName::SuperAdmin, RoleName::Admin)) {
|
|
return false;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function viewAny(User $user): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function view(User $user, User $model): bool
|
|
{
|
|
if($model->isAn(RoleName::SuperAdmin)) {
|
|
return $user->isAn(RoleName::SuperAdmin);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public function create(User $user): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function createSuperAdmin(User $user): bool
|
|
{
|
|
return $user->isAn(RoleName::SuperAdmin);
|
|
}
|
|
|
|
public function update(User $user, User $model): bool
|
|
{
|
|
if($model->isAn(RoleName::SuperAdmin)) {
|
|
return $user->isAn(RoleName::SuperAdmin);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public function delete(User $user, User $model): bool
|
|
{
|
|
if($model->isAn(RoleName::SuperAdmin)) {
|
|
return $user->isAn(RoleName::SuperAdmin);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public function restore(User $user, User $model): bool
|
|
{
|
|
if($model->isAn(RoleName::SuperAdmin)) {
|
|
return $user->isAn(RoleName::SuperAdmin);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public function forceDelete(User $user, User $model): bool
|
|
{
|
|
if($model->isAn(RoleName::SuperAdmin)) {
|
|
return $user->isAn(RoleName::SuperAdmin);
|
|
}
|
|
return true;
|
|
}
|
|
}
|