|
26 | 26 | from openedx_authz.constants import roles |
27 | 27 | from openedx_authz.constants.permissions import ( |
28 | 28 | COURSES_CREATE_FILES, |
| 29 | + COURSES_MANAGE_ADVANCED_SETTINGS, |
| 30 | + COURSES_VIEW_ADVANCED_SETTINGS, |
29 | 31 | COURSES_VIEW_COURSE, |
30 | 32 | MANAGE_LIBRARY_TEAM, |
31 | 33 | VIEW_LIBRARY, |
@@ -897,3 +899,56 @@ def test_is_admin_or_superuser_check( |
897 | 899 | """ |
898 | 900 | request = {"subject": subject, "action": action, "scope": scope, "expected_result": expected_result} |
899 | 901 | self._test_enforcement(self.POLICY, request) |
| 902 | + |
| 903 | + |
| 904 | +@ddt |
| 905 | +class AdvancedSettingsPermissionsTests(CasbinEnforcementTestCase): |
| 906 | + """ |
| 907 | + Tests for advanced settings permissions for course_auditor and course_editor roles. |
| 908 | +
|
| 909 | + Verifies the two-tier access model: |
| 910 | + - course_auditor: VIEW only (read-only access) |
| 911 | + - course_editor: both VIEW and MANAGE (full access) |
| 912 | + """ |
| 913 | + |
| 914 | + COURSE = "course-v1:TestOrg+TestCourse+2024_T1" |
| 915 | + |
| 916 | + POLICIES = [ |
| 917 | + make_policy( |
| 918 | + roles.COURSE_AUDITOR.external_key, |
| 919 | + COURSES_VIEW_ADVANCED_SETTINGS.identifier, |
| 920 | + CourseOverviewData.NAMESPACE, |
| 921 | + ), |
| 922 | + make_policy( |
| 923 | + roles.COURSE_EDITOR.external_key, |
| 924 | + COURSES_VIEW_ADVANCED_SETTINGS.identifier, |
| 925 | + CourseOverviewData.NAMESPACE, |
| 926 | + ), |
| 927 | + make_policy( |
| 928 | + roles.COURSE_EDITOR.external_key, |
| 929 | + COURSES_MANAGE_ADVANCED_SETTINGS.identifier, |
| 930 | + CourseOverviewData.NAMESPACE, |
| 931 | + ), |
| 932 | + ] |
| 933 | + |
| 934 | + ASSIGNMENTS = [ |
| 935 | + make_course_assignment("auditor", roles.COURSE_AUDITOR.external_key, COURSE), |
| 936 | + make_course_assignment("editor", roles.COURSE_EDITOR.external_key, COURSE), |
| 937 | + ] |
| 938 | + |
| 939 | + CASES = [ |
| 940 | + # course_auditor: view allowed, manage denied |
| 941 | + make_course_case("auditor", COURSES_VIEW_ADVANCED_SETTINGS.identifier, COURSE, True), |
| 942 | + make_course_case("auditor", COURSES_MANAGE_ADVANCED_SETTINGS.identifier, COURSE, False), |
| 943 | + # course_editor: both view and manage allowed |
| 944 | + make_course_case("editor", COURSES_VIEW_ADVANCED_SETTINGS.identifier, COURSE, True), |
| 945 | + make_course_case("editor", COURSES_MANAGE_ADVANCED_SETTINGS.identifier, COURSE, True), |
| 946 | + # unassigned user: both denied |
| 947 | + make_course_case("other", COURSES_VIEW_ADVANCED_SETTINGS.identifier, COURSE, False), |
| 948 | + make_course_case("other", COURSES_MANAGE_ADVANCED_SETTINGS.identifier, COURSE, False), |
| 949 | + ] |
| 950 | + |
| 951 | + @data(*CASES) |
| 952 | + def test_advanced_settings_enforcement(self, request: AuthRequest): |
| 953 | + """Test that advanced settings permissions are enforced correctly per role.""" |
| 954 | + self._test_enforcement(self.POLICIES + self.ASSIGNMENTS, request) |
0 commit comments