mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-10-24 03:29:23 +02:00
42 lines
1.0 KiB
PHP
42 lines
1.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\GraphQL\Policies\Auth;
|
|
|
|
use App\Enums\Auth\CrudPermission;
|
|
use App\GraphQL\Policies\BasePolicy;
|
|
use App\Models\Auth\Permission;
|
|
use App\Models\Auth\User;
|
|
|
|
/**
|
|
* Class PermissionPolicy.
|
|
*/
|
|
class PermissionPolicy extends BasePolicy
|
|
{
|
|
/**
|
|
* Determine whether the user can view any models.
|
|
*
|
|
* @param User|null $user
|
|
* @param array|null $injected
|
|
* @return bool
|
|
*/
|
|
public function viewAny(?User $user, ?array $injected = null): bool
|
|
{
|
|
return $user !== null && $user->can(CrudPermission::VIEW->format(Permission::class));
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can view the model.
|
|
*
|
|
* @param User|null $user
|
|
* @param array|null $injected
|
|
* @param string|null $keyName
|
|
* @return bool
|
|
*/
|
|
public function view(?User $user, ?array $injected = null, ?string $keyName = 'id'): bool
|
|
{
|
|
return $user !== null && $user->can(CrudPermission::VIEW->format(Permission::class));
|
|
}
|
|
}
|