Skip to content

Commit c456157

Browse files
committed
squash!: Use MANAGE_*_TEAM instead of VIEW permissions to filter assignments that a user can view
1 parent be74b96 commit c456157

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

openedx_authz/api/users.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
unassign_subject_from_all_roles,
4040
)
4141
from openedx_authz.api.utils import filter_user_assignments, get_user_assignment_map
42-
from openedx_authz.constants.permissions import COURSES_VIEW_COURSE, VIEW_LIBRARY
42+
from openedx_authz.constants.permissions import COURSES_MANAGE_COURSE_TEAM, MANAGE_LIBRARY_TEAM
4343

4444
__all__ = [
4545
"assign_role_to_user_in_scope",
@@ -226,9 +226,9 @@ def _filter_allowed_assignments(
226226

227227
# For CourseOverviewData and ContentLibraryData, check for the view permission
228228
if isinstance(assignment.scope, (CourseOverviewData, OrgCourseOverviewGlobData)):
229-
permission = COURSES_VIEW_COURSE.identifier
229+
permission = COURSES_MANAGE_COURSE_TEAM.identifier
230230
elif isinstance(assignment.scope, (ContentLibraryData, OrgContentLibraryGlobData)):
231-
permission = VIEW_LIBRARY.identifier
231+
permission = MANAGE_LIBRARY_TEAM.identifier
232232

233233
if permission and is_user_allowed(
234234
user_external_key=user_external_key,

openedx_authz/tests/rest_api/test_views.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -868,9 +868,10 @@ class TestTeamMembersAPIView(ViewTestMixin):
868868
(admin_1..3 are staff/superuser; regular_1..8 are plain users)
869869
870870
Visibility via filter_allowed_assignments:
871-
- Staff/superuser: sees all 11 users (is_admin_or_superuser_check grants VIEW_LIBRARY on lib scopes)
872-
- regular_1 (library_user in Org1:LIB1): VIEW_LIBRARY granted → sees Org1 members (3)
873-
- regular_3 (library_user in Org2:LIB2): VIEW_LIBRARY granted → sees Org2 members (3)
871+
- Staff/superuser: sees all 11 users (is_admin_or_superuser_check grants MANAGE_LIBRARY_TEAM on lib scopes)
872+
- regular_5 (library_admin in Org3:LIB3): MANAGE_LIBRARY_TEAM granted → sees Org3 members (5)
873+
- regular_1 (library_user in Org1:LIB1): no MANAGE_LIBRARY_TEAM → sees 0
874+
- regular_3 (library_user in Org2:LIB2): no MANAGE_LIBRARY_TEAM → sees 0
874875
- regular_9 (no assignments): sees 0 users
875876
"""
876877

@@ -892,21 +893,23 @@ def setUp(self):
892893
@data(
893894
# Staff/superuser sees all users across all scopes
894895
("admin_1", 11),
895-
# regular_1 has LIBRARY_USER in lib:Org1:LIB1 (VIEW_LIBRARY granted) → sees only Org1 members
896-
("regular_1", 3),
897-
# regular_3 has LIBRARY_USER in lib:Org2:LIB2 → sees only Org2 members
898-
("regular_3", 3),
896+
# regular_5 has LIBRARY_ADMIN in lib:Org3:LIB3 (MANAGE_LIBRARY_TEAM granted) → sees only Org3 members
897+
("regular_5", 5),
898+
# regular_1 has LIBRARY_USER in lib:Org1:LIB1 (no MANAGE_LIBRARY_TEAM) → sees nothing
899+
("regular_1", 0),
900+
# regular_3 has LIBRARY_USER in lib:Org2:LIB2 (no MANAGE_LIBRARY_TEAM) → sees nothing
901+
("regular_3", 0),
899902
# regular_9 has no assignments → sees nothing
900903
("regular_9", 0),
901904
)
902905
@unpack
903906
def test_visibility_limited_to_accessible_scopes(self, username: str, expected_count: int):
904-
"""Calling user only sees assignments for scopes it has view access to.
907+
"""Calling user only sees assignments for scopes it has MANAGE_*_TEAM access to.
905908
906909
Expected result:
907910
- Staff/superuser sees all users across all scopes.
908-
- Regular users only see members of scopes they can view.
909-
- Users with no assignments see no results.
911+
- Regular users only see members of scopes they can manage the team for.
912+
- Users without MANAGE_*_TEAM permission see no results.
910913
"""
911914
user = User.objects.get(username=username)
912915
self.client.force_authenticate(user=user)

0 commit comments

Comments
 (0)