File: D:/HostingSpaces/SBogers10/csb.komma.pro/app/Vat/VatPolicy.php
<?php
namespace App\Vat;
use Komma\KMS\Base\Policy;
use App\Vat\Models\Rate;
use Komma\KMS\Users\Models\KmsUserRole;
use Illuminate\Auth\Access\HandlesAuthorization;
use Komma\KMS\Users\Models\KmsUser;
/**
* Class RatePolicy
*
* @package App\Vat
*/
final class VatPolicy extends Policy
{
use HandlesAuthorization;
protected $modelClassName = Rate::class;
/**
* Create a new policy instance.
*
* @return void
*/
public function __construct()
{
// parent::$DEBUG = RatePolicy::class;
}
/**
* The before method will be executed before any other methods on the policy,
* giving you an opportunity to authorize the action before the
* intended policy method is actually called
*
* @param $user
* @param $ability
* @return bool
*/
public function before(KmsUser $user, $ability)
{
$this->validateThatCorrectlyConstructed();
$result = $user->isAtLeast(KmsUserRole::SuperAdmin);
$this->debug($ability, $result);
if($result) return true;
return null; //Fallback to the intended ability
}
/**
* 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::Admin);
$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
{
$result = $user->isAtLeast(KmsUserRole::Admin);
$this->debug('show', $result);
return $result;
}
/**
* 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
{
$result = $user->isAtLeast(KmsUserRole::Admin);
$this->debug('edit', $result);
return $result;
}
/**
* Determine if it is allowed to show a form for creating a new resource
*
* @param KmsUser|null $user
* @return bool
*/
public function create(KmsUser $user): bool
{
$result = $user->isAtLeast(KmsUserRole::SuperAdmin);
$this->debug('create', $result);
return $result;
}
/**
* Determine if it is allowed to store a new resource
* Usually made using a create form.
*
* @param KmsUser|null $user
* @return bool
*/
public function store(KmsUser $user): bool
{
$result = $user->isAtLeast(KmsUserRole::SuperAdmin);
$this->debug('store', $result);
return $result;
}
/**
* Determine if it is allowed to update an existing resource after editing it
*
* @param KmsUser|null $user
* @return bool
*/
public function update(KmsUser $user): bool
{
$result = $user->isAtLeast(KmsUserRole::Admin);
$this->debug('update', $result);
return $result;
}
/**
* Determine if it is allowed to destroy an existing resource
*
* @param KmsUser|null $user
* @return bool
*/
public function destroy(KmsUser $user, $modelToDestroy): bool
{
$result = $user->isAtLeast(KmsUserRole::SuperAdmin);
$this->debug('destroy', $result);
return $result;
}
/**
* @param KmsUser $user
* @return bool
*/
public function markRateAsDefault(KmsUser $user) {
$result = $user->isAtLeast(KmsUserRole::SuperAdmin);
$this->debug('markRateAsDefault', $result);
return $result;
}
/**
* @param KmsUser $user
* @return bool
*/
public function modifyRateSites(KmsUser $user) {
$result = $user->isAtLeast(KmsUserRole::SuperAdmin);
$this->debug('modifyRateSites', $result);
return $result;
}
}