mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-10-18 00:30:47 +02:00
83 lines
2.1 KiB
PHP
83 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Policies\Admin;
|
|
|
|
use App\Enums\Auth\CrudPermission;
|
|
use App\Models\Admin\Feature;
|
|
use App\Models\Auth\User;
|
|
use Filament\Facades\Filament;
|
|
use Illuminate\Auth\Access\HandlesAuthorization;
|
|
use Laravel\Nova\Nova;
|
|
|
|
/**
|
|
* Class FeaturePolicy.
|
|
*/
|
|
class FeaturePolicy
|
|
{
|
|
use HandlesAuthorization;
|
|
|
|
/**
|
|
* Determine whether the user can view any models.
|
|
*
|
|
* @param User|null $user
|
|
* @return bool
|
|
*/
|
|
public function viewAny(?User $user): bool
|
|
{
|
|
return Nova::whenServing(
|
|
fn (): bool => $user !== null && $user->can(CrudPermission::VIEW->format(Feature::class)),
|
|
fn (): bool => Filament::isServing() ? $user !== null && $user->can(CrudPermission::VIEW->format(Feature::class)) : true
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can view the model.
|
|
*
|
|
* @param User|null $user
|
|
* @param Feature $feature
|
|
* @return bool
|
|
*/
|
|
public function view(?User $user, Feature $feature): bool
|
|
{
|
|
return Nova::whenServing(
|
|
fn (): bool => $user !== null && $user->can(CrudPermission::VIEW->format(Feature::class)),
|
|
fn (): bool => Filament::isServing() ? $user !== null && $user->can(CrudPermission::VIEW->format(Feature::class)) : $feature->isNullScope()
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can create models.
|
|
*
|
|
* @param User $user
|
|
* @return bool
|
|
*/
|
|
public function create(User $user): bool
|
|
{
|
|
return $user->can(CrudPermission::CREATE->format(Feature::class));
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can update the model.
|
|
*
|
|
* @param User $user
|
|
* @return bool
|
|
*/
|
|
public function update(User $user): bool
|
|
{
|
|
return $user->can(CrudPermission::UPDATE->format(Feature::class));
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can delete the model.
|
|
*
|
|
* @param User $user
|
|
* @return bool
|
|
*/
|
|
public function delete(User $user): bool
|
|
{
|
|
return $user->can(CrudPermission::DELETE->format(Feature::class));
|
|
}
|
|
}
|