Skip to content

Commit 76f3a65

Browse files
committed
squash!: Apply suggestions
1 parent 73bc75e commit 76f3a65

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
@@ -205,7 +205,7 @@ def get_visible_specific_user_role_assignments_for_user(
205205
)
206206
if orgs:
207207
# Filter by orgs
208-
user_role_assignments = [a for a in user_role_assignments if a.scope.org in orgs]
208+
user_role_assignments = [a for a in user_role_assignments if getattr(a.scope, "org", None) in orgs]
209209
if roles:
210210
# Filter by roles
211211
user_role_assignments = [
@@ -426,7 +426,11 @@ def get_superadmin_assignments(user_external_keys: list[str] | None = None) -> l
426426
list[SuperAdminAssignmentData]: The superadmin data
427427
"""
428428
# Retrieve user data to check if they are a superusers
429-
requested_users = User.objects.filter(username__in=user_external_keys, is_active=True)
429+
if user_external_keys is None:
430+
requested_users = User.objects.filter(is_active=True)
431+
else:
432+
requested_users = User.objects.filter(username__in=user_external_keys, is_active=True)
433+
430434
superadmin_assignments: list[SuperAdminAssignmentData] = []
431435
for requested_user in requested_users:
432436
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
@@ -15,5 +15,7 @@
1515
path("orgs/", views.AdminConsoleOrgsAPIView.as_view(), name="orgs-list"),
1616
path("users/", views.TeamMembersAPIView.as_view(), name="user-list"),
1717
path("users/validate/", views.UserValidationAPIView.as_view(), name="user-validation"),
18-
path("users/<str:username>/assignments", views.TeamMemberAssignmentsAPIView.as_view(), name="user-assignment-list"),
18+
path(
19+
"users/<str:username>/assignments/", views.TeamMemberAssignmentsAPIView.as_view(), name="user-assignment-list"
20+
),
1921
]

openedx_authz/tests/rest_api/test_views.py

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

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

0 commit comments

Comments
 (0)