2023-06-20 11:55:52 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Policies;
|
|
|
|
|
|
2025-07-28 09:46:22 +02:00
|
|
|
use App\Enums\Users\RoleEnum;
|
2023-06-20 11:55:52 +02:00
|
|
|
use App\Models\Question;
|
|
|
|
|
use App\Models\Service;
|
2025-07-28 09:46:22 +02:00
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Policies\Rules\UserStaticRules;
|
2023-06-20 11:55:52 +02:00
|
|
|
|
|
|
|
|
class QuestionPolicy
|
|
|
|
|
{
|
2023-06-20 17:37:15 +02:00
|
|
|
/**
|
|
|
|
|
* View a Question.
|
|
|
|
|
*
|
2025-07-28 09:46:22 +02:00
|
|
|
* @param \App\Models\User $authUser
|
2023-06-20 17:37:15 +02:00
|
|
|
* @return boolean
|
|
|
|
|
*/
|
2025-07-28 09:46:22 +02:00
|
|
|
public function view(User $authUser): bool
|
2023-06-20 17:37:15 +02:00
|
|
|
{
|
2025-07-28 09:46:22 +02:00
|
|
|
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
2023-06-20 17:37:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-09-06 17:24:53 +02:00
|
|
|
* ViewAny a Question.
|
|
|
|
|
*
|
2025-07-28 09:46:22 +02:00
|
|
|
* @param \App\Models\User $authUser
|
2023-06-20 17:37:15 +02:00
|
|
|
* @return boolean
|
|
|
|
|
*/
|
2025-07-28 09:46:22 +02:00
|
|
|
public function viewAny(User $authUser): bool
|
2023-06-20 17:37:15 +02:00
|
|
|
{
|
2025-07-28 09:46:22 +02:00
|
|
|
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
2023-06-20 17:37:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a Question.
|
|
|
|
|
*
|
2025-07-28 09:46:22 +02:00
|
|
|
* @param \App\Models\User $authUser
|
2023-06-20 17:37:15 +02:00
|
|
|
* @return boolean
|
|
|
|
|
*/
|
2025-07-28 09:46:22 +02:00
|
|
|
public function create(User $authUser): bool
|
2023-06-20 17:37:15 +02:00
|
|
|
{
|
2025-07-28 09:46:22 +02:00
|
|
|
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
2023-06-20 17:37:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update a Question.
|
|
|
|
|
*
|
2025-07-28 09:46:22 +02:00
|
|
|
* @param \App\Models\User $authUser
|
2023-06-20 17:37:15 +02:00
|
|
|
* @return boolean
|
|
|
|
|
*/
|
2025-07-28 09:46:22 +02:00
|
|
|
public function update(User $authUser): bool
|
2023-06-20 17:37:15 +02:00
|
|
|
{
|
2025-07-28 09:46:22 +02:00
|
|
|
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
2023-06-20 17:37:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete a Question.
|
|
|
|
|
*
|
2025-07-28 09:46:22 +02:00
|
|
|
* @param \App\Models\User $authUser
|
2023-06-20 17:37:15 +02:00
|
|
|
* @return boolean
|
|
|
|
|
*/
|
2025-07-28 09:46:22 +02:00
|
|
|
public function delete(User $authUser): bool
|
2023-06-20 17:37:15 +02:00
|
|
|
{
|
2025-07-28 09:46:22 +02:00
|
|
|
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
2023-06-20 17:37:15 +02:00
|
|
|
}
|
|
|
|
|
|
2023-06-20 11:55:52 +02:00
|
|
|
/**
|
2023-09-06 17:24:53 +02:00
|
|
|
* Check if the question belongs to the service.
|
2023-06-20 11:55:52 +02:00
|
|
|
*
|
2023-06-23 17:18:59 +02:00
|
|
|
* @param \App\Models\Service $service
|
|
|
|
|
* @param \App\Models\Question $question
|
2023-06-20 11:55:52 +02:00
|
|
|
* @return boolean
|
|
|
|
|
*/
|
|
|
|
|
public function questionBelongsToService(Service $service, Question $question)
|
|
|
|
|
{
|
|
|
|
|
return $service->brand->id === $question->brand_id;
|
|
|
|
|
}
|
2025-07-28 09:46:22 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Export Customers.
|
|
|
|
|
*
|
|
|
|
|
* @param \App\Models\User $authUser
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
|
|
|
|
public function export(User $authUser): bool
|
|
|
|
|
{
|
|
|
|
|
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
|
|
|
|
}
|
2023-06-20 11:55:52 +02:00
|
|
|
}
|