ldc-com-app-bo/app/Policies/FormularyPolicy.php

98 lines
2.7 KiB
PHP

<?php
namespace App\Policies;
use App\Enums\Formularies\InputStatusEnum;
use App\Models\Formulary;
use App\Models\User;
use App\Policies\Rules\UserStaticRules;
class FormularyPolicy
{
/**
* Determine whether the user can view any models.
*
* @param \App\Models\User $authUser
* @return boolean
*/
public function viewAny(User $authUser): bool
{
return UserStaticRules::restrictTenant($authUser);
}
/**
* Determine whether the user can view the model.
*
* @param \App\Models\User $authUser
* @param \App\Models\Formulary $formulary
* @return boolean
*/
public function view(User $authUser, Formulary $formulary): bool
{
return !$formulary->status->equals(InputStatusEnum::system) &&
UserStaticRules::restrictTenant($authUser);
}
/**
* Determine whether the user can create models.
*
* @param \App\Models\User $authUser
* @return boolean
*/
public function create(User $authUser): bool
{
return UserStaticRules::restrictTenant($authUser);
}
/**
* Determine whether the user can update the model.
*
* @param \App\Models\User $authUser
* @param \App\Models\Formulary $formulary
* @return boolean
*/
public function update(User $authUser, Formulary $formulary): bool
{
return !$formulary->status->equals(InputStatusEnum::system) &&
UserStaticRules::restrictTenant($authUser);
}
/**
* Determine whether the user can delete the model.
*
* @param \App\Models\User $authUser
* @param \App\Models\Formulary $formulary
* @return boolean
*/
public function delete(User $authUser, Formulary $formulary): bool
{
return !$formulary->status->equals(InputStatusEnum::system) &&
!$formulary->status->equals(InputStatusEnum::locked) &&
UserStaticRules::restrictTenant($authUser);
}
/**
* Determine whether the user can duplicate the model.
*
* @param \App\Models\User $authUser
* @param \App\Models\Formulary $formulary
* @return boolean
*/
public function duplicate(User $authUser, Formulary $formulary): bool
{
return !$formulary->status->equals(InputStatusEnum::system) &&
!$formulary->status->equals(InputStatusEnum::locked) &&
UserStaticRules::restrictTenant($authUser);
}
/**
* Determine whether the user can change order of the model.
*
* @param \App\Models\User $authUser
* @return boolean
*/
public function changeOrder(User $authUser): bool
{
return UserStaticRules::restrictTenant($authUser);
}
}