Coverage for src/lexigram/admin/contributors/exceptions.py: 60%

15 statements  

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

1"""Admin contributor exceptions — raised during contributor action dispatch.""" 

2 

3from __future__ import annotations 

4 

5from lexigram.contracts.admin.errors import AdminError 

6 

7 

8class ContributorPermissionError(AdminError): 

9 """Raised when a user lacks required permissions to execute a contributor action. 

10 

11 Contains the contributor ID, action name, and the missing permissions. 

12 

13 Args: 

14 contributor_id: Identifier of the contributor that owns the action. 

15 action_name: Name of the action that was attempted. 

16 missing_permissions: Permissions the user lacks. 

17 """ 

18 

19 _code: str = "LEX_ERR_ADMIN_020" 

20 

21 def __init__( 

22 self, 

23 contributor_id: str, 

24 action_name: str, 

25 missing_permissions: frozenset[str], 

26 ) -> None: 

27 self.contributor_id = contributor_id 

28 self.action_name = action_name 

29 self.missing_permissions = missing_permissions 

30 super().__init__( 

31 f"Permission denied for action '{action_name}' on contributor " 

32 f"'{contributor_id}'. Missing: {missing_permissions}" 

33 ) 

34 

35 

36class ContributorNotFoundError(AdminError): 

37 """Raised when a contributor ID cannot be found in the assembled dashboard. 

38 

39 Args: 

40 contributor_id: The requested contributor ID that was not found. 

41 """ 

42 

43 _code: str = "LEX_ERR_ADMIN_021" 

44 

45 def __init__(self, contributor_id: str) -> None: 

46 self.contributor_id = contributor_id 

47 super().__init__(f"Contributor '{contributor_id}' not found in dashboard.") 

48 

49 

50__all__ = [ 

51 "ContributorNotFoundError", 

52 "ContributorPermissionError", 

53]