122 lines
3.2 KiB
PHP
122 lines
3.2 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Policies;
|
||
|
|
||
|
use App\Models\Permission;
|
||
|
use Illuminate\Auth\Access\HandlesAuthorization;
|
||
|
use Illuminate\Auth\Access\Response;
|
||
|
use Illuminate\Support\Facades\Auth;
|
||
|
|
||
|
class NotePolicy
|
||
|
{
|
||
|
use HandlesAuthorization;
|
||
|
|
||
|
/**
|
||
|
* Create a new policy instance.
|
||
|
*
|
||
|
* @return void
|
||
|
*/
|
||
|
public function __construct()
|
||
|
{
|
||
|
//
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Determine whether the user can view any notes.
|
||
|
*
|
||
|
* @return Response
|
||
|
*/
|
||
|
public function viewAny(): Response
|
||
|
{
|
||
|
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','notes_viewAny'))
|
||
|
? Response::allow()
|
||
|
: Response::deny('you are not the chosen one');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Determine whether the user can view any notes.
|
||
|
*
|
||
|
* @return Response
|
||
|
*/
|
||
|
public function viewAny_deleted(): Response
|
||
|
{
|
||
|
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','notes_viewAny_deleted'))
|
||
|
? Response::allow()
|
||
|
: Response::deny('you are not the chosen one');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Determine whether the user can view the model.
|
||
|
*
|
||
|
* @return Response
|
||
|
*/
|
||
|
public function view(): Response
|
||
|
{
|
||
|
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','notes_view'))
|
||
|
? Response::allow()
|
||
|
: Response::deny('you are not the chosen one');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Determine whether the user can create notes.
|
||
|
*
|
||
|
* @return Response
|
||
|
*/
|
||
|
public function create(): Response
|
||
|
{
|
||
|
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','notes_create'))
|
||
|
? Response::allow()
|
||
|
: Response::deny('you are not the chosen one');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Determine whether the user can update the model.
|
||
|
*
|
||
|
* @return Response
|
||
|
*/
|
||
|
public function edit(): Response
|
||
|
{
|
||
|
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','notes_edit'))
|
||
|
? Response::allow()
|
||
|
: Response::deny('you are not the chosen one');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Determine whether the user can delete the model.
|
||
|
*
|
||
|
* @return Response
|
||
|
*/
|
||
|
public function delete(): Response
|
||
|
{
|
||
|
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','notes_delete'))
|
||
|
? Response::allow()
|
||
|
: Response::deny('you are not the chosen one');
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Determine whether the user can permanently delete the model.
|
||
|
*
|
||
|
* @return Response|bool
|
||
|
*/
|
||
|
public function delete_force()
|
||
|
{
|
||
|
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','notes_delete_force'))
|
||
|
? Response::allow()
|
||
|
: Response::deny('you are not the chosen one');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Determine whether the user can restore the model.
|
||
|
*
|
||
|
* @return Response|bool
|
||
|
*/
|
||
|
public function restore()
|
||
|
{
|
||
|
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','notes_restore'))
|
||
|
? Response::allow()
|
||
|
: Response::deny('you are not the chosen one');
|
||
|
}
|
||
|
}
|