2021-04-18 20:31:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Policies;
|
|
|
|
|
|
|
|
|
|
use App\Models\User;
|
2021-07-24 14:20:56 +02:00
|
|
|
use App\Policies\Rules\SiteStaticRules as SSR;
|
|
|
|
|
use App\Policies\Rules\TicketStaticRules;
|
|
|
|
|
use App\Policies\Rules\UserRoleRules as URR;
|
2021-04-18 20:31:07 +02:00
|
|
|
use Illuminate\Auth\Access\HandlesAuthorization;
|
2021-07-24 14:20:56 +02:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Kwaadpepper\CrudPolicies\Policies\RootPolicy;
|
|
|
|
|
use Kwaadpepper\CrudPolicies\Policies\Rules\StaticRules;
|
2021-04-18 20:31:07 +02:00
|
|
|
|
2021-07-24 14:20:56 +02:00
|
|
|
class TicketPolicy extends RootPolicy
|
2021-04-18 20:31:07 +02:00
|
|
|
{
|
|
|
|
|
use HandlesAuthorization;
|
|
|
|
|
|
|
|
|
|
/**
|
2021-07-24 14:20:56 +02:00
|
|
|
* Init policies on call
|
2021-04-18 20:31:07 +02:00
|
|
|
*
|
2022-05-24 17:23:36 +02:00
|
|
|
* @param User $user
|
2021-07-24 14:20:56 +02:00
|
|
|
* @param Model $model
|
|
|
|
|
* @return void
|
2021-04-18 20:31:07 +02:00
|
|
|
*/
|
2021-07-24 14:20:56 +02:00
|
|
|
public function setPolicies(User $user, Model $model = null)
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* This first rule to return true in a policy action authorises the action
|
|
|
|
|
*/
|
|
|
|
|
$this->policies = [
|
|
|
|
|
'ticket' => [
|
2021-07-27 16:49:14 +02:00
|
|
|
'viewAny' => URR::make('allowEveryOne'),
|
|
|
|
|
'view' => URR::make('allowEveryOne'),
|
2021-07-27 21:59:01 +02:00
|
|
|
'create' => URR::make('allowEveryOne'),
|
2021-07-24 14:20:56 +02:00
|
|
|
'update' => StaticRules::or([
|
|
|
|
|
URR::make('userIsAdmin', $user),
|
|
|
|
|
SSR::make('userSitesHasTicket', $user, $model)
|
|
|
|
|
]),
|
|
|
|
|
'changeStatus' => URR::make('userIsAdmin', $user),
|
2022-02-23 15:15:47 +00:00
|
|
|
'changeInternalStatus' => URR::make('userIsAdmin', $user),
|
2021-07-24 14:20:56 +02:00
|
|
|
'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),
|
2021-09-29 13:09:35 +02:00
|
|
|
'createMessage' => TicketStaticRules::make('ticketIsNotArchived', $model),
|
2022-03-30 12:31:09 +02:00
|
|
|
'updateMessage' => StaticRules::or([
|
|
|
|
|
URR::make('userIsAdmin', $user),
|
|
|
|
|
TicketStaticRules::make('ticketIsNotArchived', $model),
|
|
|
|
|
]),
|
2022-05-24 17:23:36 +02:00
|
|
|
'reopen' => URR::make('userIsClient', $user),
|
|
|
|
|
'assignTo' => StaticRules::and([
|
|
|
|
|
URR::make('userIsAdmin', $user),
|
|
|
|
|
TicketStaticRules::make('ticketIsNotInProduction', $model),
|
|
|
|
|
TicketStaticRules::make('ticketIsNotArchived', $model)
|
2022-05-26 13:22:50 +02:00
|
|
|
]),
|
|
|
|
|
'assignTickets' => URR::make('userIsAdmin', $user),
|
2022-05-31 14:06:07 +02:00
|
|
|
'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)
|
|
|
|
|
])
|
2021-07-24 14:20:56 +02:00
|
|
|
]
|
|
|
|
|
];
|
2021-04-18 20:31:07 +02:00
|
|
|
}
|
|
|
|
|
}
|