Coverage for src/lexigram/admin/rbac/super_admin.py: 100%
6 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-21 14:56 +0800
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-21 14:56 +0800
1"""Super-admin detection for the RBAC admin subsystem.
3The super-admin role name is configurable via
4``AdminRbacConfig.super_admin_role`` (default ``"superadmin"`` — the
5string existing controllers and impersonation already special-case).
6"""
8from __future__ import annotations
10from typing import Any
13def is_super_admin(user: Any, super_admin_role: str) -> bool:
14 """Return True when the user holds the configured super-admin role.
16 Args:
17 user: User-like object exposing ``roles`` (list or tuple of str).
18 super_admin_role: Role name that grants super-admin rights.
20 Returns:
21 ``True`` when the role is present in the user's roles.
22 """
23 roles = getattr(user, "roles", None) or ()
24 return super_admin_role in roles
27__all__ = ["is_super_admin"]