2021-09-10 15:43:27 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Policies;
|
|
|
|
|
|
2021-11-05 09:04:24 +01:00
|
|
|
use App\Models\Question;
|
|
|
|
|
use App\Models\Service;
|
2021-09-10 15:43:27 +02:00
|
|
|
use App\Policies\Rules\UserStaticRules as USR;
|
|
|
|
|
use Kwaadpepper\CrudPolicies\Policies\RootPolicy;
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
/**
|
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
|
*/
|
2021-09-10 15:43:27 +02:00
|
|
|
class QuestionPolicy extends RootPolicy
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Init policies on call
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function setPolicies()
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* This first rule to return true in a policy action authorises the action
|
|
|
|
|
*/
|
|
|
|
|
$this->policies = [
|
|
|
|
|
'question' => [
|
|
|
|
|
'viewAny' => USR::make('everyOne'),
|
|
|
|
|
'view' => USR::make('everyOne'),
|
|
|
|
|
'update' => USR::make('everyOne'),
|
|
|
|
|
'create' => USR::make('everyOne'),
|
|
|
|
|
'delete' => USR::make('everyOne')
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
2021-11-05 09:04:24 +01:00
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
/**
|
|
|
|
|
* Check if the question belongs to the service
|
|
|
|
|
*
|
|
|
|
|
* @param Service $service
|
|
|
|
|
* @param Question $question
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
2021-11-05 09:04:24 +01:00
|
|
|
public function questionBelongsToService(Service $service, Question $question)
|
|
|
|
|
{
|
|
|
|
|
return $service->brand->id === $question->brand_id;
|
|
|
|
|
}
|
2021-09-10 15:43:27 +02:00
|
|
|
}
|