Skip to content

Commit 7ffbc8e

Browse files
committed
squash!: Apply suggestions
1 parent 4026a1c commit 7ffbc8e

3 files changed

Lines changed: 17 additions & 11 deletions

File tree

openedx_authz/api/users.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def get_visible_specific_user_role_assignments_for_user(
203203
)
204204
if orgs:
205205
# Filter by orgs
206-
user_role_assignments = [a for a in user_role_assignments if a.scope.org in orgs]
206+
user_role_assignments = [a for a in user_role_assignments if getattr(a.scope, "org", None) in orgs]
207207
if roles:
208208
# Filter by roles
209209
user_role_assignments = [
@@ -398,7 +398,11 @@ def get_superadmin_assignments(user_external_keys: list[str] | None = None) -> l
398398
list[SuperAdminAssignmentData]: The superadmin data
399399
"""
400400
# Retrieve user data to check if they are a superusers
401-
requested_users = User.objects.filter(username__in=user_external_keys, is_active=True)
401+
if user_external_keys is None:
402+
requested_users = User.objects.filter(is_active=True)
403+
else:
404+
requested_users = User.objects.filter(username__in=user_external_keys, is_active=True)
405+
402406
superadmin_assignments: list[SuperAdminAssignmentData] = []
403407
for requested_user in requested_users:
404408
if requested_user.is_staff or requested_user.is_superuser:

openedx_authz/rest_api/v1/urls.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@
1414
path("roles/users/", views.RoleUserAPIView.as_view(), name="role-user-list"),
1515
path("orgs/", views.AdminConsoleOrgsAPIView.as_view(), name="orgs-list"),
1616
path("users/", views.TeamMembersAPIView.as_view(), name="user-list"),
17-
path("users/<str:username>/assignments", views.TeamMemberAssignmentsAPIView.as_view(), name="user-assignment-list"),
17+
path(
18+
"users/<str:username>/assignments/", views.TeamMemberAssignmentsAPIView.as_view(), name="user-assignment-list"
19+
),
1820
]

openedx_authz/tests/rest_api/test_views.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,7 @@ class TestTeamMemberAssignmentsAPIView(ViewTestMixin):
13211321
Response fields per item: is_superadmin, role, org, scope, permission_count
13221322
13231323
Superadmin entry:
1324-
admin_1..3 are staff/superusers. Querying any of them always prepends one
1324+
admin_1..3 are staff/superusers. Querying any of them adds one entry
13251325
SuperAdminAssignmentData entry: role="django.superuser" (or "django.staff"),
13261326
org="*", scope="*", permission_count=None, is_superadmin=True.
13271327
This entry is always included regardless of org/role filters, since those
@@ -1504,21 +1504,21 @@ def test_filter_by_multiple_roles(self):
15041504
)
15051505
@unpack
15061506
def test_sorting(self, sort_by: str, order: str):
1507-
"""Results can be sorted by role, org, or scope in asc/desc order.
1507+
"""Results are sorted by role, org, or scope in asc/desc order.
15081508
1509-
Uses regular_3 and regular_4 who both have library_user in Org2:LIB2,
1510-
and admin_2 who also has library_user in Org2:LIB2 — but we need a user
1511-
with multiple assignments to verify ordering. Use admin_1 (staff) viewing
1512-
regular_5 who has a single assignment; sorting still returns 200 OK.
1509+
Uses admin_3, who has 2 items in the response: a superadmin entry
1510+
(role="django.superuser", org="*", scope="*") and a role assignment
1511+
(role="library_admin", org="Org3", scope="lib:Org3:LIB3"). With two
1512+
distinct values per field the sort order is non-trivial and verifiable.
15131513
15141514
Expected result:
15151515
- Returns 200 OK.
15161516
- Results are ordered according to the requested field and direction.
15171517
"""
1518-
# admin_1 is staff so sees all assignments; regular_5 has 1 assignment
1519-
response = self.client.get(self._url("regular_5"), {"sort_by": sort_by, "order": order})
1518+
response = self.client.get(self._url("admin_3"), {"sort_by": sort_by, "order": order})
15201519

15211520
self.assertEqual(response.status_code, status.HTTP_200_OK)
1521+
self.assertGreater(len(response.data["results"]), 1)
15221522
values = [item[sort_by] for item in response.data["results"]]
15231523
expected = sorted(values, key=lambda v: (v or "").lower(), reverse=order == "desc")
15241524
self.assertEqual(values, expected)

0 commit comments

Comments
 (0)