2121)
2222from openedx_authz .api .permissions import get_permission_from_policy
2323from openedx_authz .engine .enforcer import enforcer
24+ from openedx_authz .api .decorators import manage_policy_lifecycle
2425
2526__all__ = [
2627 "get_permissions_for_single_role" ,
4849# in this case, ALL the policies, but that might not be the case
4950
5051
52+ @manage_policy_lifecycle ()
5153def get_permissions_for_single_role (
5254 role : RoleData ,
5355) -> list [PermissionData ]:
@@ -63,6 +65,7 @@ def get_permissions_for_single_role(
6365 return [get_permission_from_policy (policy ) for policy in policies ]
6466
6567
68+ @manage_policy_lifecycle ()
6669def get_permissions_for_roles (
6770 roles : list [RoleData ],
6871) -> dict [str , dict [str , list [PermissionData | str ]]]:
@@ -84,6 +87,7 @@ def get_permissions_for_roles(
8487 return permissions_by_role
8588
8689
90+ @manage_policy_lifecycle (filter_on = "scope" )
8791def get_permissions_for_active_roles_in_scope (
8892 scope : ScopeData , role : RoleData | None = None
8993) -> dict [str , dict [str , list [PermissionData | str ]]]:
@@ -133,6 +137,7 @@ def get_permissions_for_active_roles_in_scope(
133137 )
134138
135139
140+ @manage_policy_lifecycle (filter_on = "scope" )
136141def get_role_definitions_in_scope (scope : ScopeData ) -> list [RoleData ]:
137142 """Get all role definitions available in a specific scope.
138143
@@ -171,7 +176,7 @@ def get_role_definitions_in_scope(scope: ScopeData) -> list[RoleData]:
171176 for role , permissions in permissions_per_role .items ()
172177 ]
173178
174-
179+ @ manage_policy_lifecycle ()
175180def get_all_roles_names () -> list [str ]:
176181 """Get all the available roles names in the current environment.
177182
@@ -181,6 +186,7 @@ def get_all_roles_names() -> list[str]:
181186 return enforcer .get_all_subjects ()
182187
183188
189+ @manage_policy_lifecycle (filter_on = "scope" )
184190def get_all_roles_in_scope (scope : ScopeData ) -> list [list [str ]]:
185191 """Get all the available role grouping policies in a specific scope.
186192
@@ -195,6 +201,7 @@ def get_all_roles_in_scope(scope: ScopeData) -> list[list[str]]:
195201 )
196202
197203
204+ @manage_policy_lifecycle (filter_on = "scope" )
198205def assign_role_to_subject_in_scope (
199206 subject : SubjectData , role : RoleData , scope : ScopeData
200207) -> None :
@@ -211,6 +218,7 @@ def assign_role_to_subject_in_scope(
211218 )
212219
213220
221+ @manage_policy_lifecycle (filter_on = "scope" )
214222def batch_assign_role_to_subjects_in_scope (
215223 subjects : list [SubjectData ], role : RoleData , scope : ScopeData
216224) -> None :
@@ -224,6 +232,7 @@ def batch_assign_role_to_subjects_in_scope(
224232 assign_role_to_subject_in_scope (subject , role , scope )
225233
226234
235+ @manage_policy_lifecycle (filter_on = "scope" )
227236def unassign_role_from_subject_in_scope (
228237 subject : SubjectData , role : RoleData , scope : ScopeData
229238) -> None :
@@ -239,6 +248,7 @@ def unassign_role_from_subject_in_scope(
239248 )
240249
241250
251+ @manage_policy_lifecycle (filter_on = "scope" )
242252def batch_unassign_role_from_subjects_in_scope (
243253 subjects : list [SubjectData ], role : RoleData , scope : ScopeData
244254) -> None :
@@ -253,6 +263,7 @@ def batch_unassign_role_from_subjects_in_scope(
253263 unassign_role_from_subject_in_scope (subject , role , scope )
254264
255265
266+ @manage_policy_lifecycle ()
256267def get_subject_role_assignments (subject : SubjectData ) -> list [RoleAssignmentData ]:
257268 """Get all the roles for a subject across all scopes.
258269
@@ -279,6 +290,7 @@ def get_subject_role_assignments(subject: SubjectData) -> list[RoleAssignmentDat
279290 return role_assignments
280291
281292
293+ @manage_policy_lifecycle (filter_on = "scope" )
282294def get_subject_role_assignments_in_scope (
283295 subject : SubjectData , scope : ScopeData
284296) -> list [RoleAssignmentData ]:
@@ -312,6 +324,7 @@ def get_subject_role_assignments_in_scope(
312324 return role_assignments
313325
314326
327+ @manage_policy_lifecycle (filter_on = "scope" )
315328def get_subject_role_assignments_for_role_in_scope (
316329 role : RoleData , scope : ScopeData
317330) -> list [RoleAssignmentData ]:
@@ -348,9 +361,8 @@ def get_subject_role_assignments_for_role_in_scope(
348361 return role_assignments
349362
350363
351- def get_all_subject_role_assignments_in_scope (
352- scope : ScopeData ,
353- ) -> list [RoleAssignmentData ]:
364+ @manage_policy_lifecycle (filter_on = "scope" )
365+ def get_all_subject_role_assignments_in_scope (scope : ScopeData ) -> list [RoleAssignmentData ]:
354366 """Get all the subjects assigned to any role in a specific scope.
355367
356368 Args:
0 commit comments