Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lms/djangoapps/instructor/authz/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
COURSES_VIEW_ENROLLMENTS,
COURSES_VIEW_GRADEBOOK,
COURSES_VIEW_GRADING_SETTINGS,
COURSES_VIEW_LEARNER_COURSE_STATUS,
COURSES_VIEW_LEARNER_EXTENSIONS,
)

Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions lms/djangoapps/instructor/authz/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
COURSES_VIEW_ENROLLMENTS,
COURSES_VIEW_GRADEBOOK,
COURSES_VIEW_GRADING_SETTINGS,
COURSES_VIEW_LEARNER_COURSE_STATUS,
COURSES_VIEW_LEARNER_EXTENSIONS,
)

Expand Down Expand Up @@ -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,
Expand Down
21 changes: 11 additions & 10 deletions lms/djangoapps/instructor/authz/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions lms/djangoapps/instructor/authz/tests/test_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
COURSES_VIEW_ENROLLMENTS,
COURSES_VIEW_GRADEBOOK,
COURSES_VIEW_GRADING_SETTINGS,
COURSES_VIEW_LEARNER_COURSE_STATUS,
COURSES_VIEW_LEARNER_EXTENSIONS,
)

Expand Down Expand Up @@ -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,
Expand Down
28 changes: 26 additions & 2 deletions lms/djangoapps/instructor/tests/test_api_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Loading
Loading