Source code for auth.roles
from __future__ import annotations
ROLE_LEVELS: dict[str, int] = {
"Viewer": 1,
"User": 2,
"Operator": 3,
"Engineer": 4,
"Admin": 5,
}
_ROLE_ALIASES: dict[str, str] = {
"viewer": "Viewer",
"user": "User",
"operator": "Operator",
"engineer": "Engineer",
"admin": "Admin",
}
DEFAULT_ROLE = "Viewer"
DEFAULT_ROLE_LEVEL = 0
[docs]
def canonical_role(role: str | None) -> str:
if not role:
return DEFAULT_ROLE
normalized = _ROLE_ALIASES.get(str(role).strip().lower())
return normalized or DEFAULT_ROLE
[docs]
def role_level(role: str | None) -> int:
return ROLE_LEVELS.get(canonical_role(role), DEFAULT_ROLE_LEVEL)
[docs]
def has_required_role_level(role: str | None, minimum: int) -> bool:
return role_level(role) >= int(minimum)