add superadmin dashboard. subscriptions
This commit is contained in:
@@ -17,7 +17,14 @@ class AccessService
|
||||
private OrganizationUserModel $orgUserModel;
|
||||
|
||||
/**
|
||||
* Роли и их уровни (для быстрого сравнения)
|
||||
* Системные роли (уровень всей системы, не организации)
|
||||
*/
|
||||
public const SYSTEM_ROLE_USER = 'user';
|
||||
public const SYSTEM_ROLE_ADMIN = 'admin';
|
||||
public const SYSTEM_ROLE_SUPERADMIN = 'superadmin';
|
||||
|
||||
/**
|
||||
* Роли организации (для быстрого сравнения)
|
||||
*/
|
||||
public const ROLE_OWNER = 'owner';
|
||||
public const ROLE_ADMIN = 'admin';
|
||||
@@ -84,6 +91,8 @@ class AccessService
|
||||
],
|
||||
];
|
||||
|
||||
private ?string $cachedSystemRole = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->orgUserModel = new OrganizationUserModel();
|
||||
@@ -195,6 +204,81 @@ class AccessService
|
||||
return in_array($role, [self::ROLE_OWNER, self::ROLE_ADMIN, self::ROLE_MANAGER], true);
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// СИСТЕМНЫЕ РОЛИ (суперадмин)
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* Получение системной роли пользователя
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getSystemRole(): ?string
|
||||
{
|
||||
if ($this->cachedSystemRole !== null) {
|
||||
return $this->cachedSystemRole;
|
||||
}
|
||||
|
||||
$userId = session()->get('user_id');
|
||||
if (!$userId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$userModel = new \App\Models\UserModel();
|
||||
$user = $userModel->find($userId);
|
||||
|
||||
$this->cachedSystemRole = $user['system_role'] ?? null;
|
||||
return $this->cachedSystemRole;
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверка системной роли пользователя
|
||||
*
|
||||
* @param string|array $roles Роль или массив ролей для проверки
|
||||
* @return bool
|
||||
*/
|
||||
public function isSystemRole($roles): bool
|
||||
{
|
||||
$currentRole = $this->getSystemRole();
|
||||
if ($currentRole === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$roles = (array) $roles;
|
||||
return in_array($currentRole, $roles, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверка, является ли пользователь суперадмином
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSuperadmin(): bool
|
||||
{
|
||||
return $this->getSystemRole() === self::SYSTEM_ROLE_SUPERADMIN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверка, является ли пользователь системным администратором
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSystemAdmin(): bool
|
||||
{
|
||||
$role = $this->getSystemRole();
|
||||
return in_array($role, [self::SYSTEM_ROLE_ADMIN, self::SYSTEM_ROLE_SUPERADMIN], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Сброс кэша системной роли
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function resetSystemRoleCache(): void
|
||||
{
|
||||
$this->cachedSystemRole = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверка права на действие
|
||||
*
|
||||
@@ -409,6 +493,7 @@ class AccessService
|
||||
public function resetCache(): void
|
||||
{
|
||||
$this->currentMembership = null;
|
||||
$this->cachedSystemRole = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -459,4 +544,27 @@ class AccessService
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение всех системных ролей с описаниями
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAllSystemRoles(): array
|
||||
{
|
||||
return [
|
||||
self::SYSTEM_ROLE_USER => [
|
||||
'label' => 'Пользователь',
|
||||
'description' => 'Обычный пользователь системы',
|
||||
],
|
||||
self::SYSTEM_ROLE_ADMIN => [
|
||||
'label' => 'Администратор',
|
||||
'description' => 'Администратор системы',
|
||||
],
|
||||
self::SYSTEM_ROLE_SUPERADMIN => [
|
||||
'label' => 'Суперадмин',
|
||||
'description' => 'Полный доступ ко всем функциям системы',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user