@@ -375,3 +375,51 @@ def test_decorator_with_different_scopes(
375375 )
376376 else :
377377 self .assertEqual (len (permissions ), 0 )
378+
379+ def test_decorator_with_permission_grouping (self ):
380+ """Test decorator behavior with permission grouping in policies.
381+
382+ For example:
383+ - manage_library_team includes view_library_team through g2
384+
385+ This test verifies that when a user has edit permissions, they also implicitly have
386+ delete permissions due to the permission grouping defined in the policy.
387+
388+ Expected result:
389+ - Decorator loads filtered policies for the given scope
390+ - User with manage_library_team role can also view_library_team
391+ - Enforcer is cleared after execution
392+ """
393+ scope = ScopeData (external_key = "lib:Org1:math_101" )
394+ subject = SubjectData (external_key = "alice" )
395+
396+ @manage_policy_lifecycle (filter_on = "scope" )
397+ def check_grouped_permissions (scope_arg , subject_arg ):
398+ """Check if subject has grouped permissions in the given scope.
399+
400+ Expected scenario:
401+ - Alice has library_admin role in lib:Org1:math_101
402+ - library_admin role includes manage_library_team
403+ - manage_library_team includes view_library_team through g2
404+ """
405+ can_manage_team = global_enforcer .enforce (
406+ subject_arg .namespaced_key ,
407+ ActionData (external_key = "manage_library_team" ).namespaced_key ,
408+ scope_arg .namespaced_key ,
409+ )
410+
411+ can_view_team = global_enforcer .enforce (
412+ subject_arg .namespaced_key ,
413+ ActionData (external_key = "view_library_team" ).namespaced_key ,
414+ scope_arg .namespaced_key ,
415+ )
416+
417+ return {
418+ "can_manage_team" : can_manage_team ,
419+ "can_view_team" : can_view_team ,
420+ }
421+
422+ result = check_grouped_permissions (scope , subject )
423+
424+ self .assertTrue (result ["can_manage_team" ], "Alice should be able to manage library team" )
425+ self .assertTrue (result ["can_view_team" ], "Alice should be able to view library team due to grouping" )
0 commit comments