mirror of
https://github.com/jez500/pricebuddy.git
synced 2026-11-24 19:58:13 +01:00
58 lines
1.2 KiB
PHP
58 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Enums\Role;
|
|
use App\Models\User;
|
|
|
|
class UserPolicy
|
|
{
|
|
/**
|
|
* Determine whether the user can view the list of users.
|
|
*/
|
|
public function viewAny(User $user): bool
|
|
{
|
|
return $user->isAdmin();
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can view the model.
|
|
*/
|
|
public function view(User $user, User $model): bool
|
|
{
|
|
return $user->isAdmin() || $user->is($model);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can create users.
|
|
*/
|
|
public function create(User $user): bool
|
|
{
|
|
return $user->isAdmin();
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can update the model.
|
|
*/
|
|
public function update(User $user, User $model): bool
|
|
{
|
|
return $user->isAdmin() || $user->is($model);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can delete the model.
|
|
*/
|
|
public function delete(User $user, User $model): bool
|
|
{
|
|
if ($user->is($model)) {
|
|
return false;
|
|
}
|
|
|
|
if ($model->isAdmin() && User::where('role', Role::Admin)->count() <= 1) {
|
|
return false;
|
|
}
|
|
|
|
return $user->isAdmin();
|
|
}
|
|
}
|