From a3388cef3d5998d7aaaf95dca1bf3aa533b00413 Mon Sep 17 00:00:00 2001 From: Kevyn Suarez Date: Thu, 29 Oct 2026 12:31:01 -0500 Subject: [PATCH 01/10] feat: enforce AuthZ permissions in the Date Extensions tab endpoints Migrate ChangeDueDateView, GradedSubsectionsView and UnitExtensionsView to InstructorAuthzPermission, following the shared infrastructure from openedx-authz#486. GET endpoints require courses.view_learner_extensions, the POST endpoint requires courses.manage_learner_extensions. Both already had a matching default legacy check registered in LEGACY_PERMISSION_CHECKS, so the existing permission_name on each view is reused unchanged as the fallback when the authz.enable_course_authoring flag is disabled for the course. Add DateExtensionsAuthzTest covering Course Admin, Course Staff, a user with no permission, AuthZ denying a legacy instructor, and the legacy path with the flag off, for all three endpoints. Closes openedx-authz#491. --- .../instructor/tests/test_api_v2.py | 28 +++- .../instructor/tests/test_api_v2_authz.py | 129 +++++++++++++++++- lms/djangoapps/instructor/views/api_v2.py | 11 +- 3 files changed, 162 insertions(+), 6 deletions(-) diff --git a/lms/djangoapps/instructor/tests/test_api_v2.py b/lms/djangoapps/instructor/tests/test_api_v2.py index 164ce6e87ce6..de00453e6ed1 100644 --- a/lms/djangoapps/instructor/tests/test_api_v2.py +++ b/lms/djangoapps/instructor/tests/test_api_v2.py @@ -1122,14 +1122,26 @@ def test_get_graded_subsections_as_staff(self): def test_get_graded_subsections_nonexistent_course(self): """ Test error handling for non-existent course. + + The permission check does not load the course, so only a user that passes it + (global staff) reaches the view and gets the 404. """ - self.client.force_authenticate(user=self.instructor) + self.client.force_authenticate(user=AdminFactory.create()) nonexistent_course_id = 'course-v1:NonExistent+Course+2024' nonexistent_url = self._get_url(nonexistent_course_id) response = self.client.get(nonexistent_url) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) # noqa: PT009 + def test_get_graded_subsections_nonexistent_course_without_access(self): + """ + A user without access to a non-existent course gets 403, as for any other course. + """ + self.client.force_authenticate(user=self.instructor) + response = self.client.get(self._get_url('course-v1:NonExistent+Course+2024')) + + assert response.status_code == status.HTTP_403_FORBIDDEN + def test_get_graded_subsections_empty_course(self): """ Test graded subsections for course without due dates. @@ -1639,13 +1651,25 @@ def test_get_unit_extensions_unauthenticated(self): def test_get_unit_extensions_nonexistent_course(self): """ Test error handling for non-existent course. + + The permission check does not load the course, so only a user that passes it + (global staff) reaches the view and gets the 404. """ - self.client.force_authenticate(user=self.instructor) + self.client.force_authenticate(user=AdminFactory.create()) nonexistent_course_id = 'course-v1:edX+NonExistent+2024' response = self.client.get(self._get_url(course_id=nonexistent_course_id)) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) # noqa: PT009 + def test_get_unit_extensions_nonexistent_course_without_access(self): + """ + A user without access to a non-existent course gets 403, as for any other course. + """ + self.client.force_authenticate(user=self.instructor) + response = self.client.get(self._get_url(course_id='course-v1:edX+NonExistent+2024')) + + assert response.status_code == status.HTTP_403_FORBIDDEN + def test_get_unit_extensions(self): """ Test retrieving unit extensions. diff --git a/lms/djangoapps/instructor/tests/test_api_v2_authz.py b/lms/djangoapps/instructor/tests/test_api_v2_authz.py index 8dbb4bb26432..f3253afcc7c0 100644 --- a/lms/djangoapps/instructor/tests/test_api_v2_authz.py +++ b/lms/djangoapps/instructor/tests/test_api_v2_authz.py @@ -4,6 +4,7 @@ They cover the tabs, ``authz_enabled`` and the migrated endpoints. """ +from datetime import datetime from unittest.mock import patch import ddt @@ -30,6 +31,7 @@ COURSES_VIEW_GRADEBOOK, ) from openedx_authz.engine.enforcer import AuthzEnforcer +from pytz import UTC from rest_framework import status from rest_framework.test import APIClient @@ -54,6 +56,7 @@ from lms.djangoapps.instructor.authz.api import user_has_instructor_permission from lms.djangoapps.instructor.authz.compat import LEGACY_ROLE_COMPAT_PERMISSIONS from lms.djangoapps.instructor.authz.tests.mixins import InstructorAuthzTestMixin +from openedx.core.djangoapps.course_date_signals.handlers import extract_dates from openedx.core.djangoapps.django_comment_common.models import ( FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_MODERATOR, @@ -61,7 +64,7 @@ ) from openedx.core.djangoapps.django_comment_common.utils import seed_permissions_roles from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory API = "lms.djangoapps.instructor.authz.api" @@ -1329,3 +1332,127 @@ def test_legacy_revoke_staff_role(self, legacy_role, expected_status): assert response.status_code == expected_status assert self._has_course_role(CourseStaffRole, target) == (expected_status != status.HTTP_200_OK) + + +@ddt.ddt +class DateExtensionsAuthzTest(InstructorAuthzTestMixin, SharedModuleStoreTestCase): + """ + AuthZ enforcement of the Date Extensions tab endpoints: ``GradedSubsectionsView`` + and ``UnitExtensionsView`` (``courses.view_learner_extensions``), and + ``ChangeDueDateView`` (``courses.manage_learner_extensions``). + """ + + # (url_name, "get" or "post") + VIEW_ENDPOINTS = (("graded_subsections", "get"), ("unit_extensions", "get")) + MANAGE_ENDPOINTS = (("change_due_date", "post"),) + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.course = CourseFactory.create() + cls.course_key = cls.course.id + cls.chapter = BlockFactory.create(parent=cls.course, category="chapter") + cls.sequential = BlockFactory.create( + parent=cls.chapter, + category="sequential", + due=datetime(2030, 1, 1, tzinfo=UTC), + metadata={"graded": True, "format": "Homework"}, + ) + # ChangeDueDateView extends a date through edx-when, which needs the course's + # dates extracted into its own store before it recognizes this due date exists. + extract_dates(None, cls.course_key) + + def setUp(self): + super().setUp() + self.client = APIClient() + self.learner = UserFactory() + CourseEnrollmentFactory.create(user=self.learner, course_id=self.course_key) + + def _request(self, user, url_name, method): + """Call the given endpoint as ``user``, GET or POST depending on ``method``.""" + self.client.force_authenticate(user=user) + url = reverse(f"instructor_api_v2:{url_name}", kwargs={"course_id": str(self.course_key)}) + if method == "get": + return self.client.get(url) + return self.client.post( + url, + { + "block_id": str(self.sequential.location), + "due_datetime": "01/01/2030 00:00", + "email_or_username": self.learner.username, + }, + format="json", + ) + + @ddt.data(*VIEW_ENDPOINTS, *MANAGE_ENDPOINTS) + @ddt.unpack + def test_authz_course_admin_has_access(self, url_name, method): + """A Course Admin can view and manage date extensions.""" + user = self.create_user_with_authz_role(COURSE_ADMIN.external_key, self.course_key) + + response = self._request(user, url_name, method) + + assert response.status_code == status.HTTP_200_OK + + @ddt.data(*VIEW_ENDPOINTS, *MANAGE_ENDPOINTS) + @ddt.unpack + def test_authz_course_staff_has_access(self, url_name, method): + """A Course Staff can view and manage date extensions.""" + user = self.create_user_with_authz_role(COURSE_STAFF.external_key, self.course_key) + + response = self._request(user, url_name, method) + + assert response.status_code == status.HTTP_200_OK + + @ddt.data(*VIEW_ENDPOINTS, *MANAGE_ENDPOINTS) + @ddt.unpack + def test_authz_user_without_permission_is_denied(self, url_name, method): + """A user with no AuthZ role in the course is denied.""" + user = UserFactory() + + response = self._request(user, url_name, method) + + assert response.status_code == status.HTTP_403_FORBIDDEN + + @ddt.data(*VIEW_ENDPOINTS, *MANAGE_ENDPOINTS) + @ddt.unpack + def test_authz_denied_overrides_legacy_roles(self, url_name, method): + """With the flag on, AuthZ denying a legacy instructor means no access.""" + instructor = InstructorFactory(course_key=self.course_key) + + with patch(f"{API}.authz_api.is_user_allowed", return_value=False): + response = self._request(instructor, url_name, method) + + assert response.status_code == status.HTTP_403_FORBIDDEN + + @ddt.data(*VIEW_ENDPOINTS, *MANAGE_ENDPOINTS) + @ddt.unpack + def test_legacy_instructor_keeps_access(self, url_name, method): + """With the flag off, a legacy instructor keeps the access it always had.""" + self.set_authz_enabled(False) + instructor = InstructorFactory(course_key=self.course_key) + + response = self._request(instructor, url_name, method) + + assert response.status_code == status.HTTP_200_OK + + @ddt.data(*VIEW_ENDPOINTS, *MANAGE_ENDPOINTS) + @ddt.unpack + def test_legacy_student_is_denied(self, url_name, method): + """With the flag off, an enrolled learner with no staff role is denied.""" + self.set_authz_enabled(False) + + response = self._request(self.learner, url_name, method) + + assert response.status_code == status.HTTP_403_FORBIDDEN + + def test_legacy_does_not_query_authz(self): + """With the flag off, AuthZ is not queried.""" + self.set_authz_enabled(False) + instructor = InstructorFactory(course_key=self.course_key) + + with patch(f"{API}.authz_api.is_user_allowed") as is_user_allowed: + response = self._request(instructor, "graded_subsections", "get") + + assert response.status_code == status.HTTP_200_OK + is_user_allowed.assert_not_called() diff --git a/lms/djangoapps/instructor/views/api_v2.py b/lms/djangoapps/instructor/views/api_v2.py index 334ce578f10a..18c3caf2109e 100644 --- a/lms/djangoapps/instructor/views/api_v2.py +++ b/lms/djangoapps/instructor/views/api_v2.py @@ -54,9 +54,11 @@ from openedx_authz.authz import ( COURSES_ENROLL_LEARNERS, COURSES_MANAGE_COURSE_TEAM, + COURSES_MANAGE_LEARNER_EXTENSIONS, COURSES_UNENROLL_LEARNERS, COURSES_VIEW_COURSE_TEAM, COURSES_VIEW_ENROLLMENTS, + COURSES_VIEW_LEARNER_EXTENSIONS, ) from pytz import UTC from rest_framework import status @@ -500,7 +502,8 @@ class ChangeDueDateView(APIView): Grants a due date extension to a student for a particular unit. this version works with a new payload that is JSON and more up to date. """ - permission_classes = (IsAuthenticated, permissions.InstructorPermission) + permission_classes = (IsAuthenticated, InstructorAuthzPermission) + authz_permissions = (COURSES_MANAGE_LEARNER_EXTENSIONS.identifier,) permission_name = permissions.GIVE_STUDENT_EXTENSION serializer_class = BlockDueDateSerializerV2 @@ -538,7 +541,8 @@ def post(self, request, course_id): class GradedSubsectionsView(APIView): """View to retrieve graded subsections with due dates""" - permission_classes = (IsAuthenticated, permissions.InstructorPermission) + permission_classes = (IsAuthenticated, InstructorAuthzPermission) + authz_permissions = (COURSES_VIEW_LEARNER_EXTENSIONS.identifier,) permission_name = permissions.VIEW_DASHBOARD def get(self, request, course_id): @@ -639,7 +643,8 @@ class UnitExtensionsView(ListAPIView): * 403: Forbidden - User lacks instructor permissions * 404: Not Found - Course does not exist """ - permission_classes = (IsAuthenticated, permissions.InstructorPermission) + permission_classes = (IsAuthenticated, InstructorAuthzPermission) + authz_permissions = (COURSES_VIEW_LEARNER_EXTENSIONS.identifier,) permission_name = permissions.VIEW_DASHBOARD serializer_class = UnitExtensionSerializer filter_backends = [] From 663f8637c7dd0f81be192b877b00b55fad722817 Mon Sep 17 00:00:00 2001 From: Bryann Valderrama Date: Wed, 11 Nov 2026 16:00:00 -0500 Subject: [PATCH 02/10] test: cover AuthZ roles without extension permissions and legacy roles in Date Extensions Co-Authored-By: Claude Sonnet 5.5 --- .../instructor/tests/test_api_v2_authz.py | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/lms/djangoapps/instructor/tests/test_api_v2_authz.py b/lms/djangoapps/instructor/tests/test_api_v2_authz.py index f3253afcc7c0..e323bd7fe3dd 100644 --- a/lms/djangoapps/instructor/tests/test_api_v2_authz.py +++ b/lms/djangoapps/instructor/tests/test_api_v2_authz.py @@ -1446,6 +1446,57 @@ def test_legacy_student_is_denied(self, url_name, method): assert response.status_code == status.HTTP_403_FORBIDDEN + @ddt.data(COURSE_AUDITOR.external_key, COURSE_EDITOR.external_key) + def test_authz_roles_without_legacy_equivalent_are_denied(self, role): + """ + With the flag on, the AuthZ roles that have no legacy equivalent hold no date + extensions permission, so they are denied on every endpoint. + """ + user = self.create_user_with_authz_role(role, self.course_key) + + for url_name, method in (*self.VIEW_ENDPOINTS, *self.MANAGE_ENDPOINTS): + response = self._request(user, url_name, method) + + assert response.status_code == status.HTTP_403_FORBIDDEN, url_name + + @ddt.data( + # (AuthZ role, status of the view endpoints, status of the manage endpoint) + (COURSE_LIMITED_STAFF.external_key, status.HTTP_200_OK, status.HTTP_200_OK), + (COURSE_DATA_RESEARCHER.external_key, status.HTTP_200_OK, status.HTTP_403_FORBIDDEN), + (COURSE_BETA_TESTER.external_key, status.HTTP_403_FORBIDDEN, status.HTTP_403_FORBIDDEN), + ) + @ddt.unpack + def test_authz_legacy_roles_keep_their_legacy_access(self, authz_role, view_status, manage_status): + """ + With the flag on, the AuthZ roles that stand for a legacy role are evaluated with + its legacy rule, so they keep exactly the access it had. + """ + user = self.create_user_with_authz_role(authz_role, self.course_key) + + self._assert_statuses(user, view_status, manage_status) + + @ddt.data( + (CourseStaffRole, status.HTTP_200_OK, status.HTTP_200_OK), + (CourseLimitedStaffRole, status.HTTP_200_OK, status.HTTP_200_OK), + (CourseDataResearcherRole, status.HTTP_200_OK, status.HTTP_403_FORBIDDEN), + (CourseBetaTesterRole, status.HTTP_403_FORBIDDEN, status.HTTP_403_FORBIDDEN), + ) + @ddt.unpack + def test_legacy_roles_keep_their_access(self, role_class, view_status, manage_status): + """With the flag off, each legacy role keeps the access it had before AuthZ.""" + self.set_authz_enabled(False) + user = UserFactory() + role_class(self.course_key).add_users(user) + + self._assert_statuses(user, view_status, manage_status) + + def _assert_statuses(self, user, view_status, manage_status): + """Assert the status ``user`` gets on the view endpoints and on the manage endpoint.""" + for url_name, method in self.VIEW_ENDPOINTS: + assert self._request(user, url_name, method).status_code == view_status, url_name + for url_name, method in self.MANAGE_ENDPOINTS: + assert self._request(user, url_name, method).status_code == manage_status, url_name + def test_legacy_does_not_query_authz(self): """With the flag off, AuthZ is not queried.""" self.set_authz_enabled(False) From e5ce3a092ba3419e35c9dbc6d8c4a71031cf5324 Mon Sep 17 00:00:00 2001 From: Bryann Valderrama Date: Wed, 11 Nov 2026 16:19:02 -0500 Subject: [PATCH 03/10] test: cover AuthZ access without a legacy equivalent in Date Extensions Co-Authored-By: Claude Sonnet 5.5 --- .../instructor/tests/test_api_v2_authz.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/lms/djangoapps/instructor/tests/test_api_v2_authz.py b/lms/djangoapps/instructor/tests/test_api_v2_authz.py index e323bd7fe3dd..0823248941c0 100644 --- a/lms/djangoapps/instructor/tests/test_api_v2_authz.py +++ b/lms/djangoapps/instructor/tests/test_api_v2_authz.py @@ -24,11 +24,13 @@ COURSE_STAFF, COURSES_ENROLL_LEARNERS, COURSES_MANAGE_COURSE_TEAM, + COURSES_MANAGE_LEARNER_EXTENSIONS, COURSES_UNENROLL_LEARNERS, COURSES_VIEW_COURSE_INFO, COURSES_VIEW_COURSE_TEAM, COURSES_VIEW_ENROLLMENTS, COURSES_VIEW_GRADEBOOK, + COURSES_VIEW_LEARNER_EXTENSIONS, ) from openedx_authz.engine.enforcer import AuthzEnforcer from pytz import UTC @@ -1497,6 +1499,38 @@ def _assert_statuses(self, user, view_status, manage_status): for url_name, method in self.MANAGE_ENDPOINTS: assert self._request(user, url_name, method).status_code == manage_status, url_name + def test_authz_role_without_legacy_equivalent_can_view_and_manage(self): + """ + With the flag on, AuthZ alone decides: a user holding the date extensions permissions + without any legacy role, nor its compatibility projection, has access to every endpoint. + """ + user = self.create_user_with_authz_role(COURSE_STAFF.external_key, self.course_key) + + with patch( + "common.djangoapps.student.roles.get_authz_compat_course_access_roles_for_user", + return_value=set(), + ): + self._assert_statuses(user, status.HTTP_200_OK, status.HTTP_200_OK) + + @ddt.data( + # (permission the user holds, status of the view endpoints, status of the manage endpoint) + (COURSES_VIEW_LEARNER_EXTENSIONS, status.HTTP_200_OK, status.HTTP_403_FORBIDDEN), + (COURSES_MANAGE_LEARNER_EXTENSIONS, status.HTTP_403_FORBIDDEN, status.HTTP_200_OK), + ) + @ddt.unpack + def test_authz_permission_alone_grants_its_endpoints(self, permission, view_status, manage_status): + """ + With the flag on, a user with no legacy role at all that holds only one of the date + extensions permissions gets exactly the endpoints that permission covers. + """ + user = UserFactory() + + with patch( + f"{API}.authz_api.is_user_allowed", + side_effect=lambda _user, perm, _scope: perm == permission.identifier, + ): + self._assert_statuses(user, view_status, manage_status) + def test_legacy_does_not_query_authz(self): """With the flag off, AuthZ is not queried.""" self.set_authz_enabled(False) From 2a4ae22c378633357439eaa700c7d01045ef6c75 Mon Sep 17 00:00:00 2001 From: Bryann Valderrama Date: Wed, 11 Nov 2026 16:36:00 -0500 Subject: [PATCH 04/10] feat: enforce AuthZ permissions in the reset due date endpoint Co-Authored-By: Claude Sonnet 5.5 --- lms/djangoapps/instructor/tests/test_api_v2_authz.py | 10 ++++++++-- lms/djangoapps/instructor/views/api.py | 9 +++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lms/djangoapps/instructor/tests/test_api_v2_authz.py b/lms/djangoapps/instructor/tests/test_api_v2_authz.py index 0823248941c0..312ee1a2eeec 100644 --- a/lms/djangoapps/instructor/tests/test_api_v2_authz.py +++ b/lms/djangoapps/instructor/tests/test_api_v2_authz.py @@ -1341,12 +1341,12 @@ class DateExtensionsAuthzTest(InstructorAuthzTestMixin, SharedModuleStoreTestCas """ AuthZ enforcement of the Date Extensions tab endpoints: ``GradedSubsectionsView`` and ``UnitExtensionsView`` (``courses.view_learner_extensions``), and - ``ChangeDueDateView`` (``courses.manage_learner_extensions``). + ``ChangeDueDateView`` and the legacy ``ResetDueDate`` (``courses.manage_learner_extensions``). """ # (url_name, "get" or "post") VIEW_ENDPOINTS = (("graded_subsections", "get"), ("unit_extensions", "get")) - MANAGE_ENDPOINTS = (("change_due_date", "post"),) + MANAGE_ENDPOINTS = (("change_due_date", "post"), ("reset_due_date", "post")) @classmethod def setUpClass(cls): @@ -1373,6 +1373,12 @@ def setUp(self): def _request(self, user, url_name, method): """Call the given endpoint as ``user``, GET or POST depending on ``method``.""" self.client.force_authenticate(user=user) + if url_name == "reset_due_date": + # Legacy (v1) endpoint, used by the Date Extensions tab to rescind an extension. + return self.client.post( + reverse(url_name, kwargs={"course_id": str(self.course_key)}), + {"student": self.learner.username, "url": str(self.sequential.location)}, + ) url = reverse(f"instructor_api_v2:{url_name}", kwargs={"course_id": str(self.course_key)}) if method == "get": return self.client.get(url) diff --git a/lms/djangoapps/instructor/views/api.py b/lms/djangoapps/instructor/views/api.py index bcb25d87295a..1cdc657b77d1 100644 --- a/lms/djangoapps/instructor/views/api.py +++ b/lms/djangoapps/instructor/views/api.py @@ -38,7 +38,11 @@ from edx_when.api import get_date_for_block from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey, UsageKey -from openedx_authz.authz import COURSES_MANAGE_COHORTS, COURSES_VIEW_ENROLLMENTS +from openedx_authz.authz import ( + COURSES_MANAGE_COHORTS, + COURSES_MANAGE_LEARNER_EXTENSIONS, + COURSES_VIEW_ENROLLMENTS, +) from rest_framework import serializers, status # pylint: disable=wrong-import-order from rest_framework.exceptions import MethodNotAllowed from rest_framework.permissions import ( # pylint: disable=wrong-import-order @@ -3369,7 +3373,8 @@ class ResetDueDate(APIView): """ Rescinds a due date extension for a student on a particular unit. """ - permission_classes = (IsAuthenticated, permissions.InstructorPermission) + permission_classes = (IsAuthenticated, InstructorAuthzPermission) + authz_permissions = (COURSES_MANAGE_LEARNER_EXTENSIONS.identifier,) permission_name = permissions.GIVE_STUDENT_EXTENSION serializer_class = BlockDueDateSerializer From 6ca9912da569a45466275b8759331a7ad26ff838 Mon Sep 17 00:00:00 2001 From: Bryann Valderrama Date: Thu, 12 Nov 2026 09:33:28 -0500 Subject: [PATCH 05/10] feat: enforce AuthZ permissions in the learner search endpoint LearnerView is shared with other tabs of the Instructor Dashboard MFE. It is migrated using only the Date Extensions permission, courses.view_learner_extensions, with VIEW_DASHBOARD as the legacy fallback. Co-Authored-By: Claude Sonnet 5.5 --- lms/djangoapps/instructor/tests/test_api_v2_authz.py | 9 ++++++--- lms/djangoapps/instructor/views/api_v2.py | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lms/djangoapps/instructor/tests/test_api_v2_authz.py b/lms/djangoapps/instructor/tests/test_api_v2_authz.py index 312ee1a2eeec..aa0fd67f1c87 100644 --- a/lms/djangoapps/instructor/tests/test_api_v2_authz.py +++ b/lms/djangoapps/instructor/tests/test_api_v2_authz.py @@ -1340,12 +1340,12 @@ def test_legacy_revoke_staff_role(self, legacy_role, expected_status): class DateExtensionsAuthzTest(InstructorAuthzTestMixin, SharedModuleStoreTestCase): """ AuthZ enforcement of the Date Extensions tab endpoints: ``GradedSubsectionsView`` - and ``UnitExtensionsView`` (``courses.view_learner_extensions``), and + ``UnitExtensionsView`` and ``LearnerView`` (``courses.view_learner_extensions``), and ``ChangeDueDateView`` and the legacy ``ResetDueDate`` (``courses.manage_learner_extensions``). """ # (url_name, "get" or "post") - VIEW_ENDPOINTS = (("graded_subsections", "get"), ("unit_extensions", "get")) + VIEW_ENDPOINTS = (("graded_subsections", "get"), ("unit_extensions", "get"), ("learner_detail", "get")) MANAGE_ENDPOINTS = (("change_due_date", "post"), ("reset_due_date", "post")) @classmethod @@ -1379,7 +1379,10 @@ def _request(self, user, url_name, method): reverse(url_name, kwargs={"course_id": str(self.course_key)}), {"student": self.learner.username, "url": str(self.sequential.location)}, ) - url = reverse(f"instructor_api_v2:{url_name}", kwargs={"course_id": str(self.course_key)}) + kwargs = {"course_id": str(self.course_key)} + if url_name == "learner_detail": + kwargs["email_or_username"] = self.learner.username + url = reverse(f"instructor_api_v2:{url_name}", kwargs=kwargs) if method == "get": return self.client.get(url) return self.client.post( diff --git a/lms/djangoapps/instructor/views/api_v2.py b/lms/djangoapps/instructor/views/api_v2.py index 18c3caf2109e..6ca97e77269d 100644 --- a/lms/djangoapps/instructor/views/api_v2.py +++ b/lms/djangoapps/instructor/views/api_v2.py @@ -2582,7 +2582,8 @@ class LearnerView(DeveloperErrorViewMixin, APIView): } ``` """ - permission_classes = (IsAuthenticated, permissions.InstructorPermission) + permission_classes = (IsAuthenticated, InstructorAuthzPermission) + authz_permissions = (COURSES_VIEW_LEARNER_EXTENSIONS.identifier,) permission_name = permissions.VIEW_DASHBOARD @extend_schema( From db44bf75f15ca37133353b643d8c17f2b1626d2a Mon Sep 17 00:00:00 2001 From: Bryann Valderrama Date: Thu, 26 Nov 2026 12:49:48 -0500 Subject: [PATCH 06/10] fix: require view_learner_course_status for the learner search The learner search is shared by several Instructor Dashboard tabs, so it checks the permission for viewing a learner's course status instead of the Date Extensions one. With authz.enable_course_authoring disabled it keeps using the legacy dashboard permission. Co-Authored-By: Claude Sonnet 5.5 --- lms/djangoapps/instructor/authz/constants.py | 2 + lms/djangoapps/instructor/authz/legacy.py | 2 + .../instructor/tests/test_api_v2_authz.py | 70 ++++++++++++++----- lms/djangoapps/instructor/views/api_v2.py | 3 +- 4 files changed, 57 insertions(+), 20 deletions(-) diff --git a/lms/djangoapps/instructor/authz/constants.py b/lms/djangoapps/instructor/authz/constants.py index 9bf57f3c86c9..38a48c90a829 100644 --- a/lms/djangoapps/instructor/authz/constants.py +++ b/lms/djangoapps/instructor/authz/constants.py @@ -19,6 +19,7 @@ COURSES_VIEW_ENROLLMENTS, COURSES_VIEW_GRADEBOOK, COURSES_VIEW_GRADING_SETTINGS, + COURSES_VIEW_LEARNER_COURSE_STATUS, COURSES_VIEW_LEARNER_EXTENSIONS, ) @@ -34,6 +35,7 @@ COURSES_VIEW_GRADEBOOK.identifier, COURSES_VIEW_GRADING_SETTINGS.identifier, COURSES_MANAGE_LEARNER_GRADING.identifier, + COURSES_VIEW_LEARNER_COURSE_STATUS.identifier, COURSES_VIEW_LEARNER_EXTENSIONS.identifier, COURSES_MANAGE_LEARNER_EXTENSIONS.identifier, COURSES_VIEW_COHORTS.identifier, diff --git a/lms/djangoapps/instructor/authz/legacy.py b/lms/djangoapps/instructor/authz/legacy.py index faf2252600e4..bbc428b675e9 100644 --- a/lms/djangoapps/instructor/authz/legacy.py +++ b/lms/djangoapps/instructor/authz/legacy.py @@ -21,6 +21,7 @@ COURSES_VIEW_ENROLLMENTS, COURSES_VIEW_GRADEBOOK, COURSES_VIEW_GRADING_SETTINGS, + COURSES_VIEW_LEARNER_COURSE_STATUS, COURSES_VIEW_LEARNER_EXTENSIONS, ) @@ -214,6 +215,7 @@ def _check(user: AbstractUser, course_key: CourseKey) -> bool: COURSES_VIEW_GRADEBOOK.identifier: has_gradebook_access, COURSES_VIEW_GRADING_SETTINGS.identifier: has_grading_settings_access, COURSES_MANAGE_LEARNER_GRADING.identifier: bridgekeeper_check(permissions.OVERRIDE_GRADES), + COURSES_VIEW_LEARNER_COURSE_STATUS.identifier: bridgekeeper_check(permissions.VIEW_DASHBOARD), COURSES_VIEW_LEARNER_EXTENSIONS.identifier: bridgekeeper_check(permissions.VIEW_DASHBOARD), COURSES_MANAGE_LEARNER_EXTENSIONS.identifier: bridgekeeper_check(permissions.GIVE_STUDENT_EXTENSION), COURSES_VIEW_COHORTS.identifier: has_cohort_view_access, diff --git a/lms/djangoapps/instructor/tests/test_api_v2_authz.py b/lms/djangoapps/instructor/tests/test_api_v2_authz.py index aa0fd67f1c87..727196c554c5 100644 --- a/lms/djangoapps/instructor/tests/test_api_v2_authz.py +++ b/lms/djangoapps/instructor/tests/test_api_v2_authz.py @@ -30,6 +30,7 @@ COURSES_VIEW_COURSE_TEAM, COURSES_VIEW_ENROLLMENTS, COURSES_VIEW_GRADEBOOK, + COURSES_VIEW_LEARNER_COURSE_STATUS, COURSES_VIEW_LEARNER_EXTENSIONS, ) from openedx_authz.engine.enforcer import AuthzEnforcer @@ -1340,13 +1341,16 @@ def test_legacy_revoke_staff_role(self, legacy_role, expected_status): class DateExtensionsAuthzTest(InstructorAuthzTestMixin, SharedModuleStoreTestCase): """ AuthZ enforcement of the Date Extensions tab endpoints: ``GradedSubsectionsView`` - ``UnitExtensionsView`` and ``LearnerView`` (``courses.view_learner_extensions``), and - ``ChangeDueDateView`` and the legacy ``ResetDueDate`` (``courses.manage_learner_extensions``). + ``UnitExtensionsView`` (``courses.view_learner_extensions``), ``ChangeDueDateView`` + and the legacy ``ResetDueDate`` (``courses.manage_learner_extensions``), and + ``LearnerView``, the learner search of the tab (``courses.view_learner_course_status``). """ # (url_name, "get" or "post") - VIEW_ENDPOINTS = (("graded_subsections", "get"), ("unit_extensions", "get"), ("learner_detail", "get")) + VIEW_ENDPOINTS = (("graded_subsections", "get"), ("unit_extensions", "get")) MANAGE_ENDPOINTS = (("change_due_date", "post"), ("reset_due_date", "post")) + SEARCH_ENDPOINTS = (("learner_detail", "get"),) + ALL_ENDPOINTS = (*VIEW_ENDPOINTS, *MANAGE_ENDPOINTS, *SEARCH_ENDPOINTS) @classmethod def setUpClass(cls): @@ -1395,7 +1399,7 @@ def _request(self, user, url_name, method): format="json", ) - @ddt.data(*VIEW_ENDPOINTS, *MANAGE_ENDPOINTS) + @ddt.data(*ALL_ENDPOINTS) @ddt.unpack def test_authz_course_admin_has_access(self, url_name, method): """A Course Admin can view and manage date extensions.""" @@ -1405,7 +1409,7 @@ def test_authz_course_admin_has_access(self, url_name, method): assert response.status_code == status.HTTP_200_OK - @ddt.data(*VIEW_ENDPOINTS, *MANAGE_ENDPOINTS) + @ddt.data(*ALL_ENDPOINTS) @ddt.unpack def test_authz_course_staff_has_access(self, url_name, method): """A Course Staff can view and manage date extensions.""" @@ -1415,7 +1419,7 @@ def test_authz_course_staff_has_access(self, url_name, method): assert response.status_code == status.HTTP_200_OK - @ddt.data(*VIEW_ENDPOINTS, *MANAGE_ENDPOINTS) + @ddt.data(*ALL_ENDPOINTS) @ddt.unpack def test_authz_user_without_permission_is_denied(self, url_name, method): """A user with no AuthZ role in the course is denied.""" @@ -1425,7 +1429,7 @@ def test_authz_user_without_permission_is_denied(self, url_name, method): assert response.status_code == status.HTTP_403_FORBIDDEN - @ddt.data(*VIEW_ENDPOINTS, *MANAGE_ENDPOINTS) + @ddt.data(*ALL_ENDPOINTS) @ddt.unpack def test_authz_denied_overrides_legacy_roles(self, url_name, method): """With the flag on, AuthZ denying a legacy instructor means no access.""" @@ -1436,7 +1440,7 @@ def test_authz_denied_overrides_legacy_roles(self, url_name, method): assert response.status_code == status.HTTP_403_FORBIDDEN - @ddt.data(*VIEW_ENDPOINTS, *MANAGE_ENDPOINTS) + @ddt.data(*ALL_ENDPOINTS) @ddt.unpack def test_legacy_instructor_keeps_access(self, url_name, method): """With the flag off, a legacy instructor keeps the access it always had.""" @@ -1447,7 +1451,7 @@ def test_legacy_instructor_keeps_access(self, url_name, method): assert response.status_code == status.HTTP_200_OK - @ddt.data(*VIEW_ENDPOINTS, *MANAGE_ENDPOINTS) + @ddt.data(*ALL_ENDPOINTS) @ddt.unpack def test_legacy_student_is_denied(self, url_name, method): """With the flag off, an enrolled learner with no staff role is denied.""" @@ -1465,7 +1469,7 @@ def test_authz_roles_without_legacy_equivalent_are_denied(self, role): """ user = self.create_user_with_authz_role(role, self.course_key) - for url_name, method in (*self.VIEW_ENDPOINTS, *self.MANAGE_ENDPOINTS): + for url_name, method in self.ALL_ENDPOINTS: response = self._request(user, url_name, method) assert response.status_code == status.HTTP_403_FORBIDDEN, url_name @@ -1501,8 +1505,21 @@ def test_legacy_roles_keep_their_access(self, role_class, view_status, manage_st self._assert_statuses(user, view_status, manage_status) - def _assert_statuses(self, user, view_status, manage_status): - """Assert the status ``user`` gets on the view endpoints and on the manage endpoint.""" + def _assert_statuses(self, user, view_status, manage_status, search_status=None): + """ + Assert the status ``user`` gets on the view endpoints and on the manage endpoints. + + Args: + user (User): The user calling the endpoints. + view_status (int): The expected status of the view endpoints and, unless + ``search_status`` is given, of the learner search. + manage_status (int): The expected status of the manage endpoints. + search_status (int): Optional. The expected status of the learner search, + when it differs from ``view_status``. + """ + for url_name, method in self.SEARCH_ENDPOINTS: + expected_status = view_status if search_status is None else search_status + assert self._request(user, url_name, method).status_code == expected_status, url_name for url_name, method in self.VIEW_ENDPOINTS: assert self._request(user, url_name, method).status_code == view_status, url_name for url_name, method in self.MANAGE_ENDPOINTS: @@ -1522,15 +1539,30 @@ def test_authz_role_without_legacy_equivalent_can_view_and_manage(self): self._assert_statuses(user, status.HTTP_200_OK, status.HTTP_200_OK) @ddt.data( - # (permission the user holds, status of the view endpoints, status of the manage endpoint) - (COURSES_VIEW_LEARNER_EXTENSIONS, status.HTTP_200_OK, status.HTTP_403_FORBIDDEN), - (COURSES_MANAGE_LEARNER_EXTENSIONS, status.HTTP_403_FORBIDDEN, status.HTTP_200_OK), + # (permission the user holds, status of the view, manage and search endpoints) + (COURSES_VIEW_LEARNER_EXTENSIONS, status.HTTP_200_OK, status.HTTP_403_FORBIDDEN, status.HTTP_403_FORBIDDEN), + (COURSES_MANAGE_LEARNER_EXTENSIONS, status.HTTP_403_FORBIDDEN, status.HTTP_200_OK, status.HTTP_403_FORBIDDEN), + ( + COURSES_VIEW_LEARNER_COURSE_STATUS, + status.HTTP_403_FORBIDDEN, + status.HTTP_403_FORBIDDEN, + status.HTTP_200_OK, + ), ) @ddt.unpack - def test_authz_permission_alone_grants_its_endpoints(self, permission, view_status, manage_status): + def test_authz_permission_alone_grants_its_endpoints( + self, permission, view_status, manage_status, search_status + ): """ - With the flag on, a user with no legacy role at all that holds only one of the date - extensions permissions gets exactly the endpoints that permission covers. + With the flag on, a user with no legacy role at all that is allowed only one of the + permissions gets exactly the endpoints that permission covers. The dependencies + between permissions are resolved by openedx-authz, so they don't apply to this mock. + + Args: + permission (PermissionData): The only permission the user is allowed. + view_status (int): The expected status of the view endpoints. + manage_status (int): The expected status of the manage endpoints. + search_status (int): The expected status of the learner search. """ user = UserFactory() @@ -1538,7 +1570,7 @@ def test_authz_permission_alone_grants_its_endpoints(self, permission, view_stat f"{API}.authz_api.is_user_allowed", side_effect=lambda _user, perm, _scope: perm == permission.identifier, ): - self._assert_statuses(user, view_status, manage_status) + self._assert_statuses(user, view_status, manage_status, search_status) def test_legacy_does_not_query_authz(self): """With the flag off, AuthZ is not queried.""" diff --git a/lms/djangoapps/instructor/views/api_v2.py b/lms/djangoapps/instructor/views/api_v2.py index 6ca97e77269d..e331290e4c44 100644 --- a/lms/djangoapps/instructor/views/api_v2.py +++ b/lms/djangoapps/instructor/views/api_v2.py @@ -58,6 +58,7 @@ COURSES_UNENROLL_LEARNERS, COURSES_VIEW_COURSE_TEAM, COURSES_VIEW_ENROLLMENTS, + COURSES_VIEW_LEARNER_COURSE_STATUS, COURSES_VIEW_LEARNER_EXTENSIONS, ) from pytz import UTC @@ -2583,7 +2584,7 @@ class LearnerView(DeveloperErrorViewMixin, APIView): ``` """ permission_classes = (IsAuthenticated, InstructorAuthzPermission) - authz_permissions = (COURSES_VIEW_LEARNER_EXTENSIONS.identifier,) + authz_permissions = (COURSES_VIEW_LEARNER_COURSE_STATUS.identifier,) permission_name = permissions.VIEW_DASHBOARD @extend_schema( From 623f49002d596fa9e52dccfe5c0815b8a2db6701 Mon Sep 17 00:00:00 2001 From: Bryann Valderrama Date: Thu, 26 Nov 2026 13:05:36 -0500 Subject: [PATCH 07/10] fix: return the standard error format in the Date Extensions endpoints Add DeveloperErrorViewMixin to the views that lacked it, so a denied request returns error_code permission_denied. Their other errors raised as exceptions now use developer_message instead of detail. Co-Authored-By: Claude Sonnet 5.5 --- .../instructor/tests/test_api_v2_authz.py | 17 +++++++++++++++++ lms/djangoapps/instructor/views/api.py | 2 +- lms/djangoapps/instructor/views/api_v2.py | 6 +++--- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lms/djangoapps/instructor/tests/test_api_v2_authz.py b/lms/djangoapps/instructor/tests/test_api_v2_authz.py index 727196c554c5..fc2b8f09a28d 100644 --- a/lms/djangoapps/instructor/tests/test_api_v2_authz.py +++ b/lms/djangoapps/instructor/tests/test_api_v2_authz.py @@ -1461,6 +1461,23 @@ def test_legacy_student_is_denied(self, url_name, method): assert response.status_code == status.HTTP_403_FORBIDDEN + @ddt.data(True, False) + def test_denial_uses_the_standard_error_format(self, authz_enabled): + """ + With the flag on or off, every endpoint of the tab denies access with the + ``permission_denied`` error code. + + Args: + authz_enabled (bool): Whether the AuthZ flag is enabled for the course. + """ + self.set_authz_enabled(authz_enabled) + + for url_name, method in self.ALL_ENDPOINTS: + response = self._request(self.learner, url_name, method) + + assert response.status_code == status.HTTP_403_FORBIDDEN, url_name + assert response.data["error_code"] == "permission_denied", url_name + @ddt.data(COURSE_AUDITOR.external_key, COURSE_EDITOR.external_key) def test_authz_roles_without_legacy_equivalent_are_denied(self, role): """ diff --git a/lms/djangoapps/instructor/views/api.py b/lms/djangoapps/instructor/views/api.py index 1cdc657b77d1..e7f33c01a3ec 100644 --- a/lms/djangoapps/instructor/views/api.py +++ b/lms/djangoapps/instructor/views/api.py @@ -3369,7 +3369,7 @@ def post(self, request, course_id): @method_decorator(cache_control(no_cache=True, no_store=True, must_revalidate=True), name='dispatch') -class ResetDueDate(APIView): +class ResetDueDate(DeveloperErrorViewMixin, APIView): """ Rescinds a due date extension for a student on a particular unit. """ diff --git a/lms/djangoapps/instructor/views/api_v2.py b/lms/djangoapps/instructor/views/api_v2.py index e331290e4c44..04a548656816 100644 --- a/lms/djangoapps/instructor/views/api_v2.py +++ b/lms/djangoapps/instructor/views/api_v2.py @@ -498,7 +498,7 @@ def get(self, request, course_id): @method_decorator(cache_control(no_cache=True, no_store=True, must_revalidate=True), name='dispatch') -class ChangeDueDateView(APIView): +class ChangeDueDateView(DeveloperErrorViewMixin, APIView): """ Grants a due date extension to a student for a particular unit. this version works with a new payload that is JSON and more up to date. @@ -540,7 +540,7 @@ def post(self, request, course_id): )}) -class GradedSubsectionsView(APIView): +class GradedSubsectionsView(DeveloperErrorViewMixin, APIView): """View to retrieve graded subsections with due dates""" permission_classes = (IsAuthenticated, InstructorAuthzPermission) authz_permissions = (COURSES_VIEW_LEARNER_EXTENSIONS.identifier,) @@ -600,7 +600,7 @@ def from_course_tuple(cls, row: Tuple, units_dict: dict): # noqa: UP006 ) -class UnitExtensionsView(ListAPIView): +class UnitExtensionsView(DeveloperErrorViewMixin, ListAPIView): """ Retrieve a paginated list of due date extensions for units in a course. From ab9777cb7bc0f303fb1e3823a7d3e12a6679311d Mon Sep 17 00:00:00 2001 From: Bryann Valderrama Date: Tue, 1 Dec 2026 19:43:31 -0500 Subject: [PATCH 08/10] test: add view_learner_course_status to expected legacy AuthZ rules Co-Authored-By: Claude Sonnet 5.5 --- lms/djangoapps/instructor/authz/tests/test_legacy.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lms/djangoapps/instructor/authz/tests/test_legacy.py b/lms/djangoapps/instructor/authz/tests/test_legacy.py index a3e36646e600..d796db35a8ee 100644 --- a/lms/djangoapps/instructor/authz/tests/test_legacy.py +++ b/lms/djangoapps/instructor/authz/tests/test_legacy.py @@ -19,6 +19,7 @@ COURSES_VIEW_ENROLLMENTS, COURSES_VIEW_GRADEBOOK, COURSES_VIEW_GRADING_SETTINGS, + COURSES_VIEW_LEARNER_COURSE_STATUS, COURSES_VIEW_LEARNER_EXTENSIONS, ) @@ -356,6 +357,7 @@ class LegacyPermissionChecksTest(TestCase): COURSES_VIEW_GRADEBOOK.identifier: STAFF_ACCESS, COURSES_VIEW_GRADING_SETTINGS.identifier: STUDIO_READ_ACCESS, COURSES_MANAGE_LEARNER_GRADING.identifier: STAFF_ACCESS, + COURSES_VIEW_LEARNER_COURSE_STATUS.identifier: DASHBOARD_ACCESS, COURSES_VIEW_LEARNER_EXTENSIONS.identifier: DASHBOARD_ACCESS, COURSES_MANAGE_LEARNER_EXTENSIONS.identifier: STAFF_ACCESS, COURSES_VIEW_COHORTS.identifier: COHORT_VIEW_ACCESS, From a7c2eb9a7977e9eccc64c33cc79ed043a49224d1 Mon Sep 17 00:00:00 2001 From: Bryann Valderrama Date: Wed, 2 Dec 2026 09:33:00 -0500 Subject: [PATCH 09/10] build: bump openedx-authz to 5.1.0 Co-Authored-By: Claude Sonnet 5.5 --- requirements/edx/base.txt | 2 +- requirements/edx/development.txt | 2 +- uv.lock | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/requirements/edx/base.txt b/requirements/edx/base.txt index 1c558914f6cd..6edeba971177 100644 --- a/requirements/edx/base.txt +++ b/requirements/edx/base.txt @@ -824,7 +824,7 @@ openedx-atlas==0.7.2 # openedx-authz # openedx-forum # openedx-platform -openedx-authz==4.3.0 +openedx-authz==5.1.0 # via openedx-platform openedx-calc==5.1.0 # via diff --git a/requirements/edx/development.txt b/requirements/edx/development.txt index 62fd6f0a790b..155d72ea6692 100644 --- a/requirements/edx/development.txt +++ b/requirements/edx/development.txt @@ -932,7 +932,7 @@ openedx-atlas==0.7.2 # openedx-authz # openedx-forum # openedx-platform -openedx-authz==4.3.0 +openedx-authz==5.1.0 # via openedx-platform openedx-calc==5.1.0 # via diff --git a/uv.lock b/uv.lock index 0a53ff806aaf..53f025cee7fc 100644 --- a/uv.lock +++ b/uv.lock @@ -4315,7 +4315,7 @@ wheels = [ [[package]] name = "openedx-authz" -version = "4.3.0" +version = "5.1.0" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "attrs" }, @@ -4336,9 +4336,9 @@ dependencies = [ { name = "openedx-filters" }, { name = "pycasbin" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/e5/c9/cc5761a21466ff533c051e8d0db7fcc955ea514499cc467f6caaf2a4b533/openedx_authz-4.3.0.tar.gz", hash = "sha256:a74bba2b28a0660630652d7c37c19771c64b0d2f0970cfdc90e5d9007d75b1b2", size = 934723, upload-time = "2026-11-23T15:20:40.03Z" } +sdist = { url = "https://files.pythonhosted.org/packages/4d/9f/d67c2edc9c0f88e1323703fdae44acbf9e5a5518432be87d200cd4081d6e/openedx_authz-5.1.0.tar.gz", hash = "sha256:c27bea3477489a226f3d06f83afe4d5315361d8d18d623bf0819bf460a480e59", size = 978694, upload-time = "2026-12-02T14:27:07.513Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/03/a0/1e25b437f98df57171723dcebf3be723c7a24158c4c17e1c2eec470785b9/openedx_authz-4.3.0-py3-none-any.whl", hash = "sha256:4088600619fdfab0dd514855096eb3bd55943040cb536a506bfe8b5b93bd115c", size = 242114, upload-time = "2026-11-23T15:20:38.296Z" }, + { url = "https://files.pythonhosted.org/packages/5e/3f/7badb22d42a24daddf9f8b0fdf260f938a1bec87ef3702fa1ce933eaf4cf/openedx_authz-5.1.0-py3-none-any.whl", hash = "sha256:07ba42bcffadada893639bd22535387f5e73fcd9e11cd30d1ba4e83989e22a2a", size = 265701, upload-time = "2026-12-02T14:27:05.579Z" }, ] [[package]] From 3a730cc45d2cff8ce9df603281daa9a4d9bf2ca9 Mon Sep 17 00:00:00 2001 From: Bryann Valderrama Date: Wed, 2 Dec 2026 10:00:37 -0500 Subject: [PATCH 10/10] test: adapt legacy role tests to the Course Limited Staff permissions openedx-authz 5.1.0 grants the Enrollments and other dashboard permissions to course_limited_staff, so AuthZ allows view_enrollments for it and the legacy check is no longer reached. Use Data Researcher, and a permission that AuthZ still denies for Course Limited Staff. Co-Authored-By: Claude Sonnet 5.5 --- .../instructor/authz/tests/test_api.py | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lms/djangoapps/instructor/authz/tests/test_api.py b/lms/djangoapps/instructor/authz/tests/test_api.py index 8a6825f87c2e..ca97d4214905 100644 --- a/lms/djangoapps/instructor/authz/tests/test_api.py +++ b/lms/djangoapps/instructor/authz/tests/test_api.py @@ -58,21 +58,22 @@ def test_flag_enabled_uses_authz(self, role, permission, expected): assert user_has_instructor_permission(self.user, permission, COURSE_KEY) == expected - @ddt.data(COURSE_LIMITED_STAFF.external_key, COURSE_DATA_RESEARCHER.external_key) - def test_flag_enabled_legacy_role_uses_legacy_check(self, role): - """With the flag on, a legacy role without dashboard permissions is decided by the legacy check.""" + @ddt.data( + (COURSE_DATA_RESEARCHER.external_key, COURSES_VIEW_ENROLLMENTS.identifier), + # Course Limited Staff holds the Enrollments permissions, so it needs one that AuthZ denies. + (COURSE_LIMITED_STAFF.external_key, COURSES_MANAGE_COURSE_TEAM.identifier), + ) + @ddt.unpack + def test_flag_enabled_legacy_role_uses_legacy_check(self, role, permission): + """With the flag on, a legacy role is decided by the legacy check for a permission AuthZ denies.""" self.assign_authz_role(self.user, role, COURSE_KEY) - assert user_has_instructor_permission( - self.user, COURSES_VIEW_ENROLLMENTS.identifier, COURSE_KEY, Mock(return_value=True) - ) - assert not user_has_instructor_permission( - self.user, COURSES_VIEW_ENROLLMENTS.identifier, COURSE_KEY, Mock(return_value=False) - ) + assert user_has_instructor_permission(self.user, permission, COURSE_KEY, Mock(return_value=True)) + assert not user_has_instructor_permission(self.user, permission, COURSE_KEY, Mock(return_value=False)) def test_any_permission_flag_enabled_legacy_role_uses_legacy_check_once(self): """With the flag on, a collection is decided by the legacy check, evaluated once.""" - self.assign_authz_role(self.user, COURSE_LIMITED_STAFF.external_key, COURSE_KEY) + self.assign_authz_role(self.user, COURSE_DATA_RESEARCHER.external_key, COURSE_KEY) legacy_check = Mock(return_value=True) assert user_has_any_instructor_permission(