From 8f83dfc86d192fc8ae0364924c65829598c017f0 Mon Sep 17 00:00:00 2001 From: Kevyn Suarez Date: Thu, 29 Oct 2026 12:31:01 -0500 Subject: [PATCH 1/5] 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 | 130 +++++++++++++++++- lms/djangoapps/instructor/views/api_v2.py | 13 +- 3 files changed, 165 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 a37c6087a768..4795dc0e20cf 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 @@ -18,11 +19,13 @@ COURSE_STAFF, COURSES_VIEW_COURSE_INFO, ) +from pytz import UTC from rest_framework import status from rest_framework.test import APIClient from common.djangoapps.student.roles import CourseDataResearcherRole, CourseLimitedStaffRole from common.djangoapps.student.tests.factories import ( + CourseEnrollmentFactory, InstructorFactory, StaffFactory, UserFactory, @@ -30,8 +33,9 @@ from lms.djangoapps.courseware.tabs import get_course_tab_list from lms.djangoapps.instructor.authz import constants from lms.djangoapps.instructor.authz.tests.mixins import InstructorAuthzTestMixin +from openedx.core.djangoapps.course_date_signals.handlers import extract_dates 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" @@ -313,3 +317,127 @@ def test_legacy_without_role_hidden(self): self.set_authz_enabled(False) assert not self._has_instructor_tab(UserFactory()) + + +@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 dbf64692a1b7..47018b8a4ad2 100644 --- a/lms/djangoapps/instructor/views/api_v2.py +++ b/lms/djangoapps/instructor/views/api_v2.py @@ -51,6 +51,10 @@ from edx_when import api as edx_when_api from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey, UsageKey +from openedx_authz.authz import ( + COURSES_MANAGE_LEARNER_EXTENSIONS, + COURSES_VIEW_LEARNER_EXTENSIONS, +) from pytz import UTC from rest_framework import status from rest_framework.exceptions import NotFound, PermissionDenied @@ -489,7 +493,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 @@ -527,7 +532,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): @@ -628,7 +634,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 4fc477a3340353d06360e34422fe3d372bfdd9fd Mon Sep 17 00:00:00 2001 From: Bryann Valderrama Date: Wed, 11 Nov 2026 16:00:00 -0500 Subject: [PATCH 2/5] 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 | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/instructor/tests/test_api_v2_authz.py b/lms/djangoapps/instructor/tests/test_api_v2_authz.py index 4795dc0e20cf..e4de2b0e1c06 100644 --- a/lms/djangoapps/instructor/tests/test_api_v2_authz.py +++ b/lms/djangoapps/instructor/tests/test_api_v2_authz.py @@ -23,7 +23,12 @@ from rest_framework import status from rest_framework.test import APIClient -from common.djangoapps.student.roles import CourseDataResearcherRole, CourseLimitedStaffRole +from common.djangoapps.student.roles import ( + CourseBetaTesterRole, + CourseDataResearcherRole, + CourseLimitedStaffRole, + CourseStaffRole, +) from common.djangoapps.student.tests.factories import ( CourseEnrollmentFactory, InstructorFactory, @@ -431,6 +436,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 8298cfa726e957a4ebf116bcbb2713b9fe3bda5e Mon Sep 17 00:00:00 2001 From: Bryann Valderrama Date: Wed, 11 Nov 2026 16:19:02 -0500 Subject: [PATCH 3/5] 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 e4de2b0e1c06..fe4ee7529409 100644 --- a/lms/djangoapps/instructor/tests/test_api_v2_authz.py +++ b/lms/djangoapps/instructor/tests/test_api_v2_authz.py @@ -17,7 +17,9 @@ COURSE_EDITOR, COURSE_LIMITED_STAFF, COURSE_STAFF, + COURSES_MANAGE_LEARNER_EXTENSIONS, COURSES_VIEW_COURSE_INFO, + COURSES_VIEW_LEARNER_EXTENSIONS, ) from pytz import UTC from rest_framework import status @@ -487,6 +489,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 59c1efa534c4d6db087ef36d24c7b1d157639620 Mon Sep 17 00:00:00 2001 From: Bryann Valderrama Date: Wed, 11 Nov 2026 16:36:00 -0500 Subject: [PATCH 4/5] 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 | 5 ++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lms/djangoapps/instructor/tests/test_api_v2_authz.py b/lms/djangoapps/instructor/tests/test_api_v2_authz.py index fe4ee7529409..c01ed5bde7cc 100644 --- a/lms/djangoapps/instructor/tests/test_api_v2_authz.py +++ b/lms/djangoapps/instructor/tests/test_api_v2_authz.py @@ -331,12 +331,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): @@ -363,6 +363,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 e10305a0423c..d80e3f5d0dfe 100644 --- a/lms/djangoapps/instructor/views/api.py +++ b/lms/djangoapps/instructor/views/api.py @@ -38,6 +38,7 @@ 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_LEARNER_EXTENSIONS 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 @@ -81,6 +82,7 @@ from lms.djangoapps.courseware.models import StudentModule from lms.djangoapps.instructor import enrollment from lms.djangoapps.instructor.access import ROLES, allow_access, list_with_level, revoke_access, update_forum_role +from lms.djangoapps.instructor.authz.permissions import InstructorAuthzPermission from lms.djangoapps.instructor.constants import INVOICE_KEY from lms.djangoapps.instructor.enrollment import ( enroll_email, @@ -3362,7 +3364,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 9a2ebdbb372ef0a9dffcfac29153a16b9c61bfba Mon Sep 17 00:00:00 2001 From: Bryann Valderrama Date: Thu, 12 Nov 2026 09:33:28 -0500 Subject: [PATCH 5/5] 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 c01ed5bde7cc..13301766f427 100644 --- a/lms/djangoapps/instructor/tests/test_api_v2_authz.py +++ b/lms/djangoapps/instructor/tests/test_api_v2_authz.py @@ -330,12 +330,12 @@ def test_legacy_without_role_hidden(self): 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 @@ -369,7 +369,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 47018b8a4ad2..5f9b10e38080 100644 --- a/lms/djangoapps/instructor/views/api_v2.py +++ b/lms/djangoapps/instructor/views/api_v2.py @@ -2572,7 +2572,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(