File: D:/HostingSpaces/farmfun/reserveren.farmfun.be/app/Komma/Users/KmsUserPolicy.php
<?php
namespace App\Komma\Users;
use App\Komma\Base\Policy;
use App\Komma\Users\Models\KmsUser;
use App\Komma\Users\Models\KmsUserRole;
final class KmsUserPolicy extends Policy
{
protected $modelClassName = KmsUser::class;
public static $DEBUG = true;
/*
|--------------------------------------------------------------------------
| Kms sidebar menu actions
|-----------------------------------------------------------------------u---
|
| Here you may set methods which determine if the user may do some actions with the sidebar menu
*/
/**
* Determine if a use may edit sites
*
* @param KmsUser|null $user
* @return bool
*/
public function editSites(?KmsUser $user): bool
{
$result = $user->isAtLeast(KmsUserRole::SuperAdmin);
$this->debug('editSites', $result);
return $result;
}
/**
* Determine if it is allowed to view all resources
*
* @param KmsUser|null $user
* @return bool
*/
public function index(KmsUser $user): bool
{
$result = $user->isAtLeast(KmsUserRole::Editor);
$this->debug('index', $result);
return $result;
}
/**
* Determine if it is allowed to view a specific resource
*
* @param KmsUser|null $user
* @return bool
*/
public function show(KmsUser $user, $modelToShow): bool
{
if ($user->is($modelToShow)) {
return true;
} // Always if the user is the same as $modelToShow
return parent::show($user, $modelToShow);
}
/**
* Determine if it is allowed show a form to edit a resource.
* This usually means that the user did view the model to be edited and got past
* the show authorisation. Then he edited a form to change the model and pressed
* save. After he pressed save he will trigger this edit authorisation
*
* @param KmsUser|null $user
* @return bool
*/
public function edit(KmsUser $user, $modelToEdit): bool
{
if ($user->is($modelToEdit)) {
return true;
} // Always if the user is the same as $modelToEdit
return parent::edit($user, $modelToEdit);
}
/**
* Determine if it is allowed to update an existing resource after editing it
*
* @param KmsUser|null $user
* @return bool
*/
public function update(KmsUser $user, $modelToEdit): bool
{
if ($user->is($modelToEdit)) {
return true;
} // Always if the user is the same as modelToEdit
return parent::update($user, $modelToEdit);
}
}