service-captcha/app/Policies/CaptchaTokenPolicy.php

48 lines
1.4 KiB
PHP
Raw Normal View History

2023-08-22 00:15:35 +06:00
<?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;
}
}