66 TransactionManager ,
77)
88from app .application .common .ports .user_command_gateway import UserCommandGateway
9- from app .application .common .services .authorization import AuthorizationService
9+ from app .application .common .services .authorization .authorize import (
10+ authorize ,
11+ )
12+ from app .application .common .services .authorization .permissions import (
13+ CanManageRole ,
14+ CanManageSubordinate ,
15+ RoleManagementContext ,
16+ UserManagementContext ,
17+ )
1018from app .application .common .services .current_user import CurrentUserService
1119from app .domain .entities .user import User
1220from app .domain .enums .user_role import UserRole
@@ -41,14 +49,12 @@ class InactivateUserInteractor:
4149 def __init__ (
4250 self ,
4351 current_user_service : CurrentUserService ,
44- authorization_service : AuthorizationService ,
4552 user_command_gateway : UserCommandGateway ,
4653 user_service : UserService ,
4754 transaction_manager : TransactionManager ,
4855 access_revoker : AccessRevoker ,
4956 ):
5057 self ._current_user_service = current_user_service
51- self ._authorization_service = authorization_service
5258 self ._user_command_gateway = user_command_gateway
5359 self ._user_service = user_service
5460 self ._transaction_manager = transaction_manager
@@ -61,9 +67,13 @@ async def __call__(self, request_data: InactivateUserRequest) -> None:
6167 )
6268
6369 current_user = await self ._current_user_service .get_current_user ()
64- self ._authorization_service .authorize_for_subordinate_role (
65- current_user .role ,
66- target_role = UserRole .USER ,
70+
71+ authorize (
72+ CanManageRole (),
73+ context = RoleManagementContext (
74+ subject = current_user ,
75+ target_role = UserRole .USER ,
76+ ),
6777 )
6878
6979 username = Username (request_data .username )
@@ -74,9 +84,12 @@ async def __call__(self, request_data: InactivateUserRequest) -> None:
7484 if user is None :
7585 raise UserNotFoundByUsernameError (username )
7686
77- self ._authorization_service .authorize_for_subordinate_role (
78- current_user .role ,
79- target_role = user .role ,
87+ authorize (
88+ CanManageSubordinate (),
89+ context = UserManagementContext (
90+ subject = current_user ,
91+ target = user ,
92+ ),
8093 )
8194
8295 self ._user_service .toggle_user_activation (user , is_active = False )
0 commit comments