ldc-supportweb/app/Policies/TicketPolicy.php

79 lines
3.3 KiB
PHP
Raw Normal View History

2021-04-18 20:31:07 +02:00
<?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;
2021-04-18 20:31:07 +02:00
use Illuminate\Auth\Access\HandlesAuthorization;
use Illuminate\Database\Eloquent\Model;
use Kwaadpepper\CrudPolicies\Policies\RootPolicy;
use Kwaadpepper\CrudPolicies\Policies\Rules\StaticRules;
2021-04-18 20:31:07 +02:00
class TicketPolicy extends RootPolicy
2021-04-18 20:31:07 +02:00
{
use HandlesAuthorization;
/**
* Init policies on call
2021-04-18 20:31:07 +02:00
*
2022-05-24 17:23:36 +02:00
* @param User $user
* @param Model $model
* @return void
2021-04-18 20:31:07 +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'),
'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),
2021-09-29 13:09:35 +02:00
'createMessage' => TicketStaticRules::make('ticketIsNotArchived', $model),
'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-04-18 20:31:07 +02:00
}
}