You've already forked Epicnabbo-Catalogus-Updated-Daily
46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\Miscellaneous\WebsitePermission;
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class PermissionsService
|
|
{
|
|
public ?Collection $permissions;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->permissions = Cache::remember(
|
|
'website_permissions',
|
|
now()->addMinutes(30),
|
|
fn () => WebsitePermission::all()->pluck('min_rank', 'permission')
|
|
);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
return auth()->user()->rank >= (int) $this->permissions->get($permissionName);
|
|
}
|
|
|
|
public function refresh(): void
|
|
{
|
|
Cache::forget('website_permissions');
|
|
|
|
$this->permissions = Cache::remember(
|
|
'website_permissions',
|
|
now()->addMinutes(30),
|
|
fn () => WebsitePermission::all()->pluck('min_rank', 'permission')
|
|
);
|
|
}
|
|
}
|