Coverage for src/lexigram/admin/rbac/super_admin.py: 67%

6 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-24 23:18 +0800

1"""Super-admin detection for the RBAC admin subsystem. 

2 

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""" 

7 

8from __future__ import annotations 

9 

10from typing import Any 

11 

12 

13def is_super_admin(user: Any, super_admin_role: str) -> bool: 

14 """Return True when the user holds the configured super-admin role. 

15 

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. 

19 

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 

25 

26 

27__all__ = ["is_super_admin"]