You've already forked Epicnabbo-Catalogus-Updated-Daily
36 lines
925 B
PHP
36 lines
925 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\WebsiteHousekeepingPermission;
|
|
use Illuminate\Support\Collection;
|
|
|
|
class HousekeepingPermissionsService
|
|
{
|
|
/** @var Collection<string, int>|null */
|
|
public ?Collection $permissions;
|
|
|
|
public function __construct()
|
|
{
|
|
/** @var Collection<string, int> */
|
|
$permissions = WebsiteHousekeepingPermission::pluck('min_rank', 'permission');
|
|
$this->permissions = $permissions;
|
|
}
|
|
|
|
public function getOrDefault(string $permissionName, bool $default = false): bool
|
|
{
|
|
if (! $this->permissions instanceof Collection || ! $this->permissions->has($permissionName)) {
|
|
return $default;
|
|
}
|
|
|
|
if (! auth()->check()) {
|
|
return false;
|
|
}
|
|
|
|
/** @var \App\Models\User $user */
|
|
$user = auth()->user();
|
|
|
|
return $user->rank >= (int) $this->permissions->get($permissionName);
|
|
}
|
|
}
|