Return the user-facing role name for a user id, or the user id itself.
(user_id: str, *, project_root: Optional[Path] = None)
| 46 | def load_roles_meta(*, project_root: Optional[Path] = None) -> Dict[str, Any]: |
| 47 | path = roles_path(project_root=project_root) |
| 48 | try: |
| 49 | data = json.loads(path.read_text(encoding="utf-8")) |
| 50 | except (OSError, json.JSONDecodeError): |
| 51 | return {"roles": {}, "current_role": None} |
| 52 | return data if isinstance(data, dict) else {"roles": {}, "current_role": None} |
| 53 | |
| 54 | |
| 55 | def role_name_for_user_id(user_id: str, *, project_root: Optional[Path] = None) -> str: |
| 56 | """Return the user-facing role name for a user id, or the user id itself.""" |
| 57 | cleaned_user_id = str(user_id or "").strip() |
| 58 | if not cleaned_user_id: |
| 59 | return "" |
| 60 | |
| 61 | roles = load_roles_meta(project_root=project_root).get("roles") or {} |
| 62 | if not isinstance(roles, dict): |
| 63 | return cleaned_user_id |
| 64 | |
| 65 | for role_name, role_info in roles.items(): |
| 66 | if not isinstance(role_info, dict): |
| 67 | continue |
no test coverage detected