82 lines
3.6 KiB
PHP
82 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Models\User;
|
|
use App\Policies\Rules\SiteStaticRules as SSR;
|
|
use App\Policies\Rules\TicketStaticRules;
|
|
use App\Policies\Rules\UserRoleRules as URR;
|
|
use Illuminate\Auth\Access\HandlesAuthorization;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Kwaadpepper\CrudPolicies\Policies\RootPolicy;
|
|
use Kwaadpepper\CrudPolicies\Policies\Rules\StaticRules;
|
|
|
|
class TicketPolicy extends RootPolicy
|
|
{
|
|
use HandlesAuthorization;
|
|
|
|
/**
|
|
* Init policies on call
|
|
*
|
|
* @param \App\Models\User $user
|
|
* @param \Illuminate\Database\Eloquent\Model $model
|
|
* @return void
|
|
*/
|
|
public function setPolicies(User $user, Model $model = null)
|
|
{
|
|
/**
|
|
* This first rule to return true in a policy action authorises the action
|
|
*/
|
|
$this->policies = [
|
|
'ticket' => [
|
|
'viewAny' => URR::make('allowEveryOne'),
|
|
'view' => URR::make('allowEveryOne'),
|
|
'create' => URR::make('allowEveryOne'),
|
|
'update' => StaticRules::or([
|
|
URR::make('userIsAdmin', $user),
|
|
SSR::make('userSitesHasTicket', $user, $model)
|
|
]),
|
|
'changeStatus' => URR::make('userIsAdmin', $user),
|
|
'changeInternalStatus' => URR::make('userIsAdmin', $user),
|
|
'delete' => URR::make('denyEveryOne'),
|
|
'forceDelete' => URR::make('denyEveryOne'),
|
|
'restore' => StaticRules::or([
|
|
URR::make('userIsAdmin', $user),
|
|
SSR::make('userSitesHasTicket', $user, $model)
|
|
]),
|
|
'suscribeToTicket' => TicketStaticRules::make('ticketIsNotArchived', $model),
|
|
'createMessage' => TicketStaticRules::make('ticketIsNotArchived', $model),
|
|
'createPrivateMessage' => StaticRules::and([
|
|
URR::make('userIsAdmin', $user),
|
|
TicketStaticRules::make('ticketIsNotArchived', $model),
|
|
]),
|
|
'updateMessage' => StaticRules::or([
|
|
URR::make('userIsAdmin', $user),
|
|
TicketStaticRules::make('ticketIsNotArchived', $model),
|
|
]),
|
|
'reopen' => URR::make('userIsClient', $user),
|
|
'assignTo' => StaticRules::and([
|
|
URR::make('userIsAdmin', $user),
|
|
TicketStaticRules::make('ticketIsNotInProduction', $model),
|
|
TicketStaticRules::make('ticketIsNotArchived', $model)
|
|
]),
|
|
'assignTickets' => URR::make('userIsAdmin', $user),
|
|
'assignLabels' => URR::make('userIsAdmin', $user),
|
|
'estimate' => StaticRules::and([
|
|
URR::make('userIsAdmin', $user),
|
|
TicketStaticRules::make('ticketsBrandHasAnAccount', $model),
|
|
TicketStaticRules::make('ticketDoesntHaveEstimation', $model),
|
|
TicketStaticRules::make('ticketIsNotInternal', $model),
|
|
TicketStaticRules::make('ticketIsNotArchived', $model)
|
|
]),
|
|
'validateEstimate' => StaticRules::and([
|
|
URR::make('userIsClient', $user),
|
|
TicketStaticRules::make('ticketsBrandHasAnAccount', $model),
|
|
TicketStaticRules::make('ticketDoesHaveEstimation', $model),
|
|
TicketStaticRules::make('ticketIsNotInternal', $model),
|
|
TicketStaticRules::make('ticketIsNotArchived', $model)
|
|
])
|
|
]
|
|
];
|
|
}
|
|
}
|