Add user policy to manage user security
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 34s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m40s
Create Docker Image / Final Docker Image Manifest (push) Successful in 10s

This commit is contained in:
Deon George 2024-04-25 16:08:09 +10:00
parent ac02f37c67
commit f42fe97902

View File

@ -0,0 +1,87 @@
<?php
namespace App\Policies;
use App\Models\User;
class UserPolicy
{
/**
* Does this user have admin privileges
*
* @param User $user
* @return bool
*/
public function admin(User $user): bool
{
return $user->isAdmin();
}
/**
* Does this user own the model?
*
* @param User $user
* @param User $model
* @return bool
*/
public function ownes(User $user,User $model): bool
{
return $user->id === $model->id;
}
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return FALSE;
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, User $model): bool
{
return FALSE;
}
/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return FALSE;
}
/**
* Determine whether the user can update the model, or if the user is an admin, and thus they can update all users.
*/
public function update(User $user, User $model): bool
{
return $user->isAdmin() || ($model->id === $user->id);
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, User $model): bool
{
return FALSE;
}
/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, User $model): bool
{
return FALSE;
}
/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, User $model): bool
{
return FALSE;
}
}