You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
911 B
PHTML
40 lines
911 B
PHTML
|
2 months ago
|
<?php
|
||
|
|
|
||
|
|
namespace App\Services;
|
||
|
|
|
||
|
|
final class AdminPermission
|
||
|
|
{
|
||
|
|
private static $resolved = false;
|
||
|
|
private static $canManage = false;
|
||
|
|
|
||
|
|
public static function isSuperAdmin()
|
||
|
|
{
|
||
|
|
if (self::$resolved) {
|
||
|
|
return self::$canManage;
|
||
|
|
}
|
||
|
|
self::$resolved = true;
|
||
|
|
|
||
|
|
try {
|
||
|
|
$user = Auth::getUser();
|
||
|
|
$configuredUserIds = (string) Config::get('super_admin');
|
||
|
|
} catch (\Throwable $exception) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!is_object($user) || !isset($user->id)) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
$allowedUserIds = array_filter(
|
||
|
|
array_map('intval', explode(',', $configuredUserIds)),
|
||
|
|
function ($userId) {
|
||
|
|
return $userId > 0;
|
||
|
|
}
|
||
|
|
);
|
||
|
|
|
||
|
|
self::$canManage = in_array((int) $user->id, $allowedUserIds, true);
|
||
|
|
|
||
|
|
return self::$canManage;
|
||
|
|
}
|
||
|
|
}
|