Skip to content

Commit 85b4f8b

Browse files
committed
refactor: remove unused role assignment functions from user and roles api
1 parent 7b82c9f commit 85b4f8b

4 files changed

Lines changed: 0 additions & 70 deletions

File tree

openedx_authz/api/roles.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -410,23 +410,6 @@ def get_subject_role_assignments_in_scope(subject: SubjectData, scope: ScopeData
410410
return role_assignments
411411

412412

413-
def get_subject_role_assignments_for_role(subject: SubjectData, role: RoleData) -> list[RoleAssignmentData]:
414-
"""Get role assignments for a subject filtered by a specific role across all scopes.
415-
416-
Args:
417-
subject: The SubjectData object representing the subject.
418-
role: The RoleData object representing the role to filter by.
419-
420-
Returns:
421-
list[RoleAssignmentData]: A list of assignments where the subject has the specified role.
422-
"""
423-
return [
424-
assignment
425-
for assignment in get_subject_role_assignments(subject)
426-
if any(assigned_role.namespaced_key == role.namespaced_key for assigned_role in assignment.roles)
427-
]
428-
429-
430413
def get_subject_role_assignments_for_role_in_scope(role: RoleData, scope: ScopeData) -> list[RoleAssignmentData]:
431414
"""Get the subjects assigned to a specific role in a specific scope.
432415

openedx_authz/api/users.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
get_role_assignments,
2727
get_scopes_for_subject_and_permission,
2828
get_subject_role_assignments,
29-
get_subject_role_assignments_for_role,
3029
get_subject_role_assignments_for_role_in_scope,
3130
get_subject_role_assignments_in_scope,
3231
get_subjects_for_role_in_scope,
@@ -48,7 +47,6 @@
4847
"get_scopes_for_user_and_permission",
4948
"get_users_for_role_in_scope",
5049
"unassign_all_roles_from_user",
51-
"get_user_role_assignments_for_role",
5250
]
5351

5452

@@ -132,22 +130,6 @@ def get_user_role_assignments(user_external_key: str) -> list[RoleAssignmentData
132130
return get_subject_role_assignments(UserData(external_key=user_external_key))
133131

134132

135-
def get_user_role_assignments_for_role(user_external_key: str, role_external_key: str) -> list[RoleAssignmentData]:
136-
"""Get role assignments for a user filtered by a specific role across all scopes.
137-
138-
Args:
139-
user_external_key (str): ID of the user (e.g., 'john_doe').
140-
role_external_key (str): Name of the role (e.g., 'instructor').
141-
142-
Returns:
143-
list[RoleAssignmentData]: A list of role assignments for the given user and role.
144-
"""
145-
return get_subject_role_assignments_for_role(
146-
UserData(external_key=user_external_key),
147-
RoleData(external_key=role_external_key),
148-
)
149-
150-
151133
def get_user_role_assignments_in_scope(user_external_key: str, scope_external_key: str) -> list[RoleAssignmentData]:
152134
"""Get the roles assigned to a user in a specific scope.
153135

openedx_authz/tests/api/test_roles.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
get_role_definitions_in_scope,
3232
get_scopes_for_subject_and_permission,
3333
get_subject_role_assignments,
34-
get_subject_role_assignments_for_role,
3534
get_subject_role_assignments_for_role_in_scope,
3635
get_subject_role_assignments_in_scope,
3736
get_subjects_for_role_in_scope,

openedx_authz/tests/api/test_users.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
batch_unassign_role_from_users,
1010
get_all_user_role_assignments_in_scope,
1111
get_user_role_assignments,
12-
get_user_role_assignments_for_role,
1312
get_user_role_assignments_for_role_in_scope,
1413
get_user_role_assignments_in_scope,
1514
is_user_allowed,
@@ -53,39 +52,6 @@ def _assign_roles_to_users(
5352
class TestUserRoleAssignments(UserAssignmentsSetupMixin):
5453
"""Test suite for user-role assignment API functions."""
5554

56-
@data(
57-
("alice", roles.LIBRARY_ADMIN.external_key, 1, {"lib:Org1:math_101"}),
58-
("eve", roles.LIBRARY_ADMIN.external_key, 1, {"lib:Org2:physics_401"}),
59-
(
60-
"liam",
61-
roles.LIBRARY_AUTHOR.external_key,
62-
3,
63-
{"lib:Org4:art_101", "lib:Org4:art_201", "lib:Org4:art_301"},
64-
),
65-
("alice", roles.LIBRARY_AUTHOR.external_key, 0, set()),
66-
("non_existent_user", roles.LIBRARY_ADMIN.external_key, 0, set()),
67-
)
68-
@unpack
69-
def test_get_user_role_assignments_for_role(
70-
self,
71-
username,
72-
role_external_key,
73-
expected_count,
74-
expected_scopes,
75-
):
76-
role_assignments = get_user_role_assignments_for_role(
77-
user_external_key=username,
78-
role_external_key=role_external_key,
79-
)
80-
81-
self.assertEqual(len(role_assignments), expected_count)
82-
83-
role_names = {r.external_key for assignment in role_assignments for r in assignment.roles}
84-
self.assertEqual(role_names, set() if expected_count == 0 else {role_external_key})
85-
86-
scopes = {assignment.scope.external_key for assignment in role_assignments}
87-
self.assertEqual(scopes, expected_scopes)
88-
8955
@data(
9056
("john", roles.LIBRARY_ADMIN.external_key, "lib:Org1:math_101", False),
9157
("jane", roles.LIBRARY_USER.external_key, "lib:Org1:english_101", False),

0 commit comments

Comments
 (0)