mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-10-17 08:10:46 +02:00
118 lines
2.8 KiB
PHP
118 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Policies\Document;
|
|
|
|
use App\Enums\Auth\CrudPermission;
|
|
use App\Enums\Auth\ExtendedCrudPermission;
|
|
use App\Models\Auth\User;
|
|
use App\Models\Document\Page;
|
|
use Illuminate\Auth\Access\HandlesAuthorization;
|
|
use Laravel\Nova\Nova;
|
|
|
|
/**
|
|
* Class PagePolicy.
|
|
*/
|
|
class PagePolicy
|
|
{
|
|
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(Page::class)),
|
|
fn (): bool => true
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can view the model.
|
|
*
|
|
* @param User|null $user
|
|
* @return bool
|
|
*/
|
|
public function view(?User $user): bool
|
|
{
|
|
return Nova::whenServing(
|
|
fn (): bool => $user !== null && $user->can(CrudPermission::VIEW->format(Page::class)),
|
|
fn (): bool => true
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can create models.
|
|
*
|
|
* @param User $user
|
|
* @return bool
|
|
*/
|
|
public function create(User $user): bool
|
|
{
|
|
return $user->can(CrudPermission::CREATE->format(Page::class));
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can update the model.
|
|
*
|
|
* @param User $user
|
|
* @param Page $page
|
|
* @return bool
|
|
*/
|
|
public function update(User $user, Page $page): bool
|
|
{
|
|
return ! $page->trashed() && $user->can(CrudPermission::UPDATE->format(Page::class));
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can delete the model.
|
|
*
|
|
* @param User $user
|
|
* @param Page $page
|
|
* @return bool
|
|
*/
|
|
public function delete(User $user, Page $page): bool
|
|
{
|
|
return ! $page->trashed() && $user->can(CrudPermission::DELETE->format(Page::class));
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can restore the model.
|
|
*
|
|
* @param User $user
|
|
* @param Page $page
|
|
* @return bool
|
|
*/
|
|
public function restore(User $user, Page $page): bool
|
|
{
|
|
return $page->trashed() && $user->can(ExtendedCrudPermission::RESTORE->format(Page::class));
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can permanently delete the model.
|
|
*
|
|
* @param User $user
|
|
* @return bool
|
|
*/
|
|
public function forceDelete(User $user): bool
|
|
{
|
|
return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Page::class));
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can permanently delete any model.
|
|
*
|
|
* @param User $user
|
|
* @return bool
|
|
*/
|
|
public function forceDeleteAny(User $user): bool
|
|
{
|
|
return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Page::class));
|
|
}
|
|
}
|