48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
|
<?php declare(strict_types=1);
|
||
|
|
||
|
namespace App\Policies;
|
||
|
|
||
|
use App\Models\CaptchaToken;
|
||
|
use App\Models\User;
|
||
|
|
||
|
final readonly class CaptchaTokenPolicy extends Policy
|
||
|
{
|
||
|
public function viewAny(User $user): bool
|
||
|
{
|
||
|
return $user->hasPermission('captcha_token.view') || $user->hasPermission('captcha_token.view_own');
|
||
|
}
|
||
|
|
||
|
public function viewAnyAll(User $user): bool
|
||
|
{
|
||
|
return $user->hasPermission('captcha_token.view');
|
||
|
}
|
||
|
|
||
|
public function viewAnyOwn(User $user): bool
|
||
|
{
|
||
|
return $user->hasPermission('captcha_token.view_own');
|
||
|
}
|
||
|
|
||
|
public function view(User $user, CaptchaToken $captchaToken): bool
|
||
|
{
|
||
|
return $user->hasPermission('captcha_token.view') ||
|
||
|
$user->hasPermission('captcha_token.view_own') && $captchaToken->user_id === $user->id;
|
||
|
}
|
||
|
|
||
|
public function create(User $user): bool
|
||
|
{
|
||
|
return $user->hasPermission('captcha_token.create');
|
||
|
}
|
||
|
|
||
|
public function update(User $user, CaptchaToken $captchaToken): bool
|
||
|
{
|
||
|
return $user->hasPermission('captcha_token.update') ||
|
||
|
$user->hasPermission('captcha_token.update_own') && $captchaToken->user_id === $user->id;
|
||
|
}
|
||
|
|
||
|
public function delete(User $user, CaptchaToken $captchaToken): bool
|
||
|
{
|
||
|
return $user->hasPermission('captcha_token.delete') ||
|
||
|
$user->hasPermission('captcha_token.delete_own') && $captchaToken->user_id === $user->id;
|
||
|
}
|
||
|
}
|