Repository navigation
feat: enforce AuthZ permissions in the Grading endpoints - #39366
Conversation
Migrate the Grading tab endpoints of the Instructor Dashboard API v2 from InstructorPermission to InstructorAuthzPermission: - LearnerView (GET): courses.view_gradebook - ProblemView (GET): courses.view_gradebook - GradingConfigView (GET): courses.view_grading_settings - ResetAttemptsView (POST): courses.manage_learner_grading - DeleteStateView (DELETE): courses.manage_learner_grading - RescoreView (POST): courses.manage_learner_grading - ScoreOverrideView (PUT): courses.manage_learner_grading
|
Thanks for the pull request, @carlos-marquez-wgu! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
|
Hi @openedx/wg-maintenance-openedx-platform-oncall, this PR is ready for reviews, thanks! |
Description
Migrate the Grading tab endpoints of the Instructor Dashboard API v2 from
InstructorPermissiontoInstructorAuthzPermission:LearnerView(GET):courses.view_gradebookProblemView(GET):courses.view_gradebookGradingConfigView(GET):courses.view_grading_settingsResetAttemptsView(POST):courses.manage_learner_gradingDeleteStateView(DELETE):courses.manage_learner_gradingRescoreView(POST):courses.manage_learner_gradingScoreOverrideView(PUT):courses.manage_learner_gradingThe behavior follows the
authz.enable_course_authoringwaffle flag, as introduced in #39255:course_limited_staff,course_data_researcher,course_beta_tester). Those fall back to the legacy check when AuthZ denies, so they keep their legacy access.courses.manage_learner_gradingcovers both the Single Learner and the All Learners actions.Other changes:
GradingConfigViewusescourses.view_grading_settingsinstead ofcourses.view_grading_configuration. openedx-authz does not define the latter, and it is no longer in the Instructor Dashboard Permissions catalog (see this discussion).courses.manage_learner_gradingwith the flag enabled, and keep the legacy instructor check with it disabled.ScoreOverrideViewno longer runs its extrahas_access(user, 'staff', block)check. The problem key is mapped into the URL's course, so it resolved to the same course-level staff check as the view's legacy permission (OVERRIDE_GRADES). With the flag disabled it was redundant; with it enabled, it madecourses.manage_learner_gradinginsufficient to override scores.Affected roles: Course Admin, Course Staff, legacy course instructors and legacy course staff. The AuthZ Course Limited Staff, Course Data Researcher and Course Beta Tester roles keep the access of their legacy role.
Supporting Information
Testing Instructions
Setup
course-v1:OpenedX+DemoX+DemoCourse, and a problem in it (its usage key, for exampleblock-v1:OpenedX+DemoX+DemoCourse+type@problem+block@<id>).learner, and submit at least one answer to that problem as the learner, so there is state to reset, rescore and delete.legacy_adminas Admin (legacy instructor).legacy_staffas Staff (legacy staff).tutor dev exec lms ./manage.py lms waffle_flag authz.enable_course_authoring --create --everyoneauthz_adminthe Course Admin role.authz_staffthe Course Staff role.Open the Grading tab at
http://apps.local.openedx.io:8080/instructor-dashboard/<course_id>/gradingand use the Single Learner and All Learners actions. To check responses directly, use the browser's network tab or call the endpoints (<problem>is the problem's usage key):GET /api/instructor/v2/courses/<course_id>/learners/<learner>GET /api/instructor/v2/courses/<course_id>/problems/<problem>GET /api/instructor/v2/courses/<course_id>/grading-configPOST /api/instructor/v2/courses/<course_id>/<problem>/grading/attempts/reset?learner=<learner>DELETE /api/instructor/v2/courses/<course_id>/<problem>/grading/state?learner=<learner>POST /api/instructor/v2/courses/<course_id>/<problem>/grading/scores/rescore?learner=<learner>PUT /api/instructor/v2/courses/<course_id>/<problem>/grading/scores?learner=<learner>with{"score": 0.5}POST /api/instructor/v2/courses/<course_id>/<problem>/grading/attempts/resetPOST /api/instructor/v2/courses/<course_id>/<problem>/grading/scores/rescoreWith the flag enabled
authz_adminauthz_stafflegacy_adminWith the flag disabled
Disable the flag:
tutor dev exec lms ./manage.py lms waffle_flag authz.enable_course_authoring --deactivatelegacy_adminlegacy_staffInstructor access required for bulk operations)Users with an AuthZ role keep access while the flag is disabled, because of the compatibility layer between AuthZ roles and legacy roles (see #39255). This is expected.
Automated tests
tutor dev exec lms pytest lms/djangoapps/instructor/tests/test_api_v2_authz.py -k GradingTabDeadline
Willow
Concerns
Behavior changes and known gaps, let me know if the changes are acceptable or do we need a different approach:
courses.manage_learner_gradingcovers both the Single Learner and All Learners actions, so Course Staff can reset attempts and rescore for all learners. Before this change, the All Learners actions required instructor access, in both the v1 and v2 APIs. This follows the Instructor Dashboard Permissions catalog: Single Learner and All Learners share Manage Learner Grading, and the UI should tell individual and course-wide operations apart. With the flag disabled, the legacy rule is unchanged. Is this acceptable?TaskStatusView: not migrated. Its permission is still to be defined, and it is shared with other tabs.Note
Shared test helpers: this PR adds
allowed_onlyandallowed_all_excepttotest_api_v2_authz.py. The Course Team PR (#489) adds the same helpers. Whichever merges second will drop the duplicate.AI Usage Notice
Kiro and Claude were used to help write the code and tests. A person guided the work, reviewed and corrected every change, and checked that it meets the requirements of the linked issue.