73 lines
2.4 KiB
PHP
Executable File
73 lines
2.4 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Models\PromptGeneration;
|
|
use App\Models\User;
|
|
use Illuminate\Auth\Access\Response;
|
|
|
|
class PromptGenerationPolicy
|
|
{
|
|
/**
|
|
* Determine whether the user can view any prompt generations.
|
|
*/
|
|
public function viewAny(User $user): Response
|
|
{
|
|
return in_array($user->role, ['superadmin', 'user'], true)
|
|
? Response::allow()
|
|
: Response::deny('You do not have permission to view prompt generations.');
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can view the prompt generation.
|
|
*/
|
|
public function view(User $user, PromptGeneration $promptGeneration): Response
|
|
{
|
|
return $user->role === 'superadmin' || $promptGeneration->user_id === $user->id
|
|
? Response::allow()
|
|
: Response::deny('You do not have permission to view this prompt generation.');
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can create prompt generations.
|
|
*/
|
|
public function create(User $user): Response
|
|
{
|
|
return $user->role === 'superadmin' || $user->role === 'user'
|
|
? Response::allow()
|
|
: Response::deny('You do not have permission to create prompt generations.');
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can delete the prompt generation.
|
|
*/
|
|
public function delete(User $user, PromptGeneration $promptGeneration): Response
|
|
{
|
|
return $user->role === 'superadmin' || $promptGeneration->user_id === $user->id
|
|
? Response::allow()
|
|
: Response::deny('You do not have permission to delete this prompt generation.');
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can restore the prompt generation.
|
|
*/
|
|
public function restore(User $user, PromptGeneration $promptGeneration): Response
|
|
{
|
|
return $user->role === 'superadmin' || $promptGeneration->user_id === $user->id
|
|
? Response::allow()
|
|
: Response::deny('You do not have permission to restore this prompt generation.');
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can permanently delete the prompt generation.
|
|
*/
|
|
public function forceDelete(User $user, PromptGeneration $promptGeneration): Response
|
|
{
|
|
return $user->role === 'superadmin'
|
|
? Response::allow()
|
|
: Response::deny('You do not have permission to permanently delete this prompt generation.');
|
|
}
|
|
}
|