Skip to content

Commit be74b96

Browse files
committed
squash!: Remove redundant functions and attend PR comments
1 parent 4e35b06 commit be74b96

5 files changed

Lines changed: 6 additions & 54 deletions

File tree

CHANGELOG.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Added
2121
=====
2222

2323
* Add ADR for global scope support for role assignments.
24-
* Add ``get_all_subject_role_assignments`` and ``get_all_user_role_assignments`` api functions to fetch all user role assignments.
2524
* Add ``users/`` endpoint to fetch all team members, with optional filters for orgs, scopes, search by username user full name or email, sorting and pagination.
2625

2726
Fixed

openedx_authz/api/data.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,8 @@ def __repr__(self):
11871187

11881188
@define
11891189
class UserAssignments:
1190+
"""A user with their role assignments"""
1191+
11901192
user: "User"
11911193
assignments: list[RoleAssignmentData]
11921194

openedx_authz/api/users.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
assign_role_to_subject_in_scope,
2929
batch_assign_role_to_subjects_in_scope,
3030
batch_unassign_role_from_subjects_in_scope,
31-
get_all_subject_role_assignments,
3231
get_all_subject_role_assignments_in_scope,
3332
get_role_assignments,
3433
get_scopes_for_subject_and_permission,
@@ -51,9 +50,8 @@
5150
"get_user_role_assignments_in_scope",
5251
"get_user_role_assignments_for_role_in_scope",
5352
"get_user_role_assignments_filtered",
54-
"get_all_user_role_assignments",
5553
"get_all_user_role_assignments_in_scope",
56-
"get_all_user_role_assignments_by_user_filtered",
54+
"get_visible_role_assignments_for_user",
5755
"is_user_allowed",
5856
"get_scopes_for_user_and_permission",
5957
"get_users_for_role_in_scope",
@@ -202,15 +200,6 @@ def get_user_role_assignments_filtered(
202200
)
203201

204202

205-
def get_all_user_role_assignments() -> list[RoleAssignmentData]:
206-
"""Get all roles for all users across all scopes.
207-
208-
Returns:
209-
list[RoleAssignmentData]: A list of role assignments and all their metadata assigned to the user.
210-
"""
211-
return get_all_subject_role_assignments()
212-
213-
214203
def get_all_user_role_assignments_in_scope(
215204
scope_external_key: str,
216205
) -> list[RoleAssignmentData]:
@@ -251,7 +240,7 @@ def _filter_allowed_assignments(
251240
return allowed_assignments
252241

253242

254-
def get_all_user_role_assignments_by_user_filtered(
243+
def get_visible_role_assignments_for_user(
255244
orgs: list[str] = None,
256245
scopes: list[str] = None,
257246
allowed_for_user_external_key: str = None,
@@ -268,7 +257,7 @@ def get_all_user_role_assignments_by_user_filtered(
268257
Returns:
269258
list[UserAssignments]: A list of users with their role assignments, filtered by orgs/scopes and permissions.
270259
"""
271-
user_role_assignments = get_all_user_role_assignments()
260+
user_role_assignments = get_user_role_assignments_filtered()
272261
# Filter assignments based on the user's permissions
273262
user_role_assignments = _filter_allowed_assignments(
274263
user_external_key=allowed_for_user_external_key,

openedx_authz/rest_api/v1/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ def get(self, request: HttpRequest) -> Response:
487487
serializer.is_valid(raise_exception=True)
488488
query_params = serializer.validated_data
489489

490-
users_with_assignments = api.get_all_user_role_assignments_by_user_filtered(
490+
users_with_assignments = api.get_visible_role_assignments_for_user(
491491
orgs=query_params.get("orgs"),
492492
scopes=query_params.get("scopes"),
493493
allowed_for_user_external_key=request.user.username,

openedx_authz/tests/api/test_users.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
assign_role_to_user_in_scope,
88
batch_assign_role_to_users_in_scope,
99
batch_unassign_role_from_users,
10-
get_all_user_role_assignments,
1110
get_all_user_role_assignments_in_scope,
1211
get_user_role_assignments,
1312
get_user_role_assignments_for_role_in_scope,
@@ -291,43 +290,6 @@ def test_unassign_all_roles_from_user_removes_all_assignments(self, username, sc
291290
)
292291
self.assertEqual(len(scope_assignments), 0)
293292

294-
def test_get_all_user_role_assignments(self):
295-
"""Test retrieving all role assignments across all users and scopes.
296-
297-
Expected result:
298-
- Returns all role assignments present in the system.
299-
- Each assignment includes subject, role, and scope.
300-
- Known assignments from the test setup are present in the result.
301-
"""
302-
role_assignments = get_all_user_role_assignments()
303-
304-
self.assertGreater(len(role_assignments), 0)
305-
306-
# Verify each assignment has the expected structure
307-
for assignment in role_assignments:
308-
self.assertIsNotNone(assignment.subject)
309-
self.assertIsNotNone(assignment.scope)
310-
self.assertGreater(len(assignment.roles), 0)
311-
for role in assignment.roles:
312-
self.assertIsNotNone(role.external_key)
313-
314-
# Verify known assignments from setup are present
315-
user_scope_role_triples = {
316-
(a.subject.username, a.scope.external_key, a.roles[0].external_key) for a in role_assignments
317-
}
318-
self.assertIn(
319-
("alice", "lib:Org1:math_101", roles.LIBRARY_ADMIN.external_key),
320-
user_scope_role_triples,
321-
)
322-
self.assertIn(
323-
("eve", "lib:Org2:physics_401", roles.LIBRARY_ADMIN.external_key),
324-
user_scope_role_triples,
325-
)
326-
self.assertIn(
327-
("liam", "lib:Org4:art_101", roles.LIBRARY_AUTHOR.external_key),
328-
user_scope_role_triples,
329-
)
330-
331293
def test_unassign_all_roles_from_user_with_no_roles_returns_false(self):
332294
"""Test that unassigning a user with no roles returns False.
333295

0 commit comments

Comments
 (0)