120 lines
3.2 KiB
PHP
120 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Models\Permission;
|
|
use App\Models\User;
|
|
use Illuminate\Auth\Access\HandlesAuthorization;
|
|
use Illuminate\Auth\Access\Response;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class ReservationPolicy
|
|
{
|
|
use HandlesAuthorization;
|
|
|
|
/**
|
|
* Create a new policy instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
//
|
|
}
|
|
/**
|
|
* Determine whether the user can view any models.
|
|
*
|
|
* @return Response
|
|
*/
|
|
public function viewAny(): Response
|
|
{
|
|
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','reservations_viewAny'))
|
|
? Response::allow()
|
|
: Response::deny('you are not the chosen one');
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can create models.
|
|
*
|
|
* @return Response
|
|
*/
|
|
public function create(): Response
|
|
{
|
|
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','reservations_create'))
|
|
? Response::allow()
|
|
: Response::deny('you are not the chosen one');
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can update the model.
|
|
*
|
|
* @return Response
|
|
*/
|
|
public function extend(): Response
|
|
{
|
|
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','reservations_extend'))
|
|
? Response::allow()
|
|
: Response::deny('you are not the chosen one');
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can delete the model.
|
|
*
|
|
* @return Response
|
|
*/
|
|
public function return(): Response
|
|
{
|
|
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','reservations_return'))
|
|
? Response::allow()
|
|
: Response::deny('you are not the chosen one');
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can validate the model.
|
|
*
|
|
* @return Response
|
|
*/
|
|
public function validate(): Response
|
|
{
|
|
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','reservations_validate'))
|
|
? Response::allow()
|
|
: Response::deny('you are not the chosen one');
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can cancel the model.
|
|
*
|
|
* @return Response
|
|
*/
|
|
public function cancel(): Response
|
|
{
|
|
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','reservations_cancel'))
|
|
? Response::allow()
|
|
: Response::deny('you are not the chosen one');
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can delete the model.
|
|
*
|
|
* @return Response
|
|
*/
|
|
public function pickup(): Response
|
|
{
|
|
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','reservations_pickup'))
|
|
? Response::allow()
|
|
: Response::deny('you are not the chosen one');
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can delete the model.
|
|
*
|
|
* @return Response
|
|
*/
|
|
public function setup(): Response
|
|
{
|
|
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','reservations_setup'))
|
|
? Response::allow()
|
|
: Response::deny('you are not the chosen one');
|
|
}
|
|
}
|