Repository navigation
Conversation
|
Thanks for the pull request, @BryanttV! 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. |
84c9aab to
535f71c
Compare
291316e to
3900955
Compare
2ebdaa5 to
e06a0ce
Compare
f92f60f to
3c00424
Compare
3c00424 to
c634992
Compare
Migrate the cohorts API views to InstructorAuthzPermission, following openedx-authz#486's shared infrastructure: - CohortSettings, CohortHandler and CohortUsers (openedx.core.djangoapps. course_groups.views) now require courses.view_cohorts for GET and courses.manage_cohorts for every write method, through a per-method authz_permissions mapping. No legacy_permission_check is set for these, so each method falls back to the matching default registered in LEGACY_PERMISSION_CHECKS (has_cohort_view_access/has_cohort_manage_access, already built in #486 to reproduce IsStaffOrAdmin), which is what varies the legacy fallback by method without any new code. - CohortCSV (lms.djangoapps.instructor.views.api) now requires courses.manage_cohorts, with a custom legacy_permission_check that keeps its pre-existing is_staff-only fallback: unlike the rest of the cohorts endpoints, this one was never gated on course staff access. - course_cohort_settings_handler, the legacy function-based view still used by Studio, gets the same permission check via user_has_instructor_permission directly, with an explicit legacy check reproducing its existing get_course_with_access(user, 'staff', ...) call so GET and PATCH keep requiring the same access level they always did (the DRF views' IsStaffOrAdmin-derived checks allow broader GET access, which this endpoint never had). Along the way: - InstructorAuthzPermission assumed the URL kwarg was always named course_id. The cohorts API uses course_key_string, so it gained an optional course_id_url_kwarg attribute (defaults to "course_id"), documented in the README for the other per-tab subtasks too. - Deleted course_groups.permissions.IsStaffOrAdmin: it was this migration's only remaining caller, and legacy.has_cohort_view_access/ has_cohort_manage_access already reproduce its exact logic. Add CohortsAuthzTest, CohortSettingsHandlerAuthzTest and CohortCSVAuthzTest covering Course Admin, Course Staff, a user with no permission, AuthZ denying a legacy instructor, and the legacy path with the flag off (including CohortCSV's narrower is_staff-only fallback). Rebased onto the latest instructor-authz-shared-infra (authz_permission renamed to authz_permissions, always a collection) and updated the cohorts views and tests to match. Closes openedx-authz#492.
Replace the inline legacy_permission_check of CohortCSV with legacy.is_django_staff, a generic equivalent of DRF's IsAdminUser (user.is_staff). It is not registered in LEGACY_PERMISSION_CHECKS, so views opt in explicitly and other endpoints migrated from IsAdminUser can reuse it. Add unit tests for is_django_staff. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
_get_course_with_access ran get_course_with_access(user, 'staff', ...) after InstructorAuthzPermission had already allowed the request. That check only recognizes legacy roles (or AuthZ roles with a legacy equivalent), so a user holding courses.view_cohorts/manage_cohorts through an AuthZ role without a legacy equivalent got a 404. With authz.enable_course_authoring enabled, a 'staff' action now only loads the course, leaving the permission to InstructorAuthzPermission. The 'load' action keeps going through get_course_with_access so the course visibility, start/end dates and prerequisites checks still apply. With the flag disabled the legacy behavior is unchanged: the check is not redundant there, since the legacy view access also admits the forum Administrator, Moderator and Community TA roles and the 'staff' check is what keeps them out of the endpoints that require course staff. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Migrate GroupConfigurationsListView and GroupConfigurationDetailView, used by the Cohorts tab of the Instructor Dashboard, to InstructorAuthzPermission. They require courses.view_cohorts, and keep instructor.dashboard as the legacy fallback used when authz.enable_course_authoring is disabled. They previously used InstructorPermission, which only sees legacy roles, so a user with an AuthZ role without a legacy equivalent got a 403 when the tab loaded the content groups. Update the existing tests to patch InstructorAuthzPermission and add ContentGroupsAuthzTestCase covering Course Staff, an AuthZ role without a legacy equivalent, a user with no permission, and the legacy path with the flag off. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
c634992 to
f9c8340
Compare
Description
Migrates every endpoint behind the Cohorts tab to the shared Instructor Dashboard AuthZ infrastructure, following the migration guide in
lms/djangoapps/instructor/authz/README.rst.With
authz.enable_course_authoringon,InstructorAuthzPermissionis the only permission check, so a user whose AuthZ role has no legacy equivalent can use the whole tab. With the flag off, behavior is unchanged.Affected roles: Course Admin, Course Staff, legacy Instructor, forum Admin/Moderator/Community TA, Django staff.
Endpoints (permissions are
courses.view_cohorts/courses.manage_cohorts)/api/cohorts/v1/settings/<course_id>has_cohort_view_access/has_cohort_manage_access/api/cohorts/v1/courses/<course_id>/cohorts/[<cohort_id>]/api/cohorts/v1/courses/<course_id>/cohorts/<cohort_id>/users/[<username>]/courses/<course_id>/cohorts/settings(legacy view, used by Studio)get_course_with_access(user, 'staff')/api/cohorts/v1/courses/<course_id>/users/(CSV upload)is_staffonly/api/cohorts/v2/courses/<course_id>/group_configurations[/<id>]instructor.dashboardNotes by endpoint group
CohortSettings,CohortHandler,CohortUsers): nolegacy_permission_check, on purpose. The per-method defaults inLEGACY_PERMISSION_CHECKSalready reproduceIsStaffOrAdmin, soIsStaffOrAdminandcourse_groups/permissions.pyare deleted.course_cohort_settings_handler: keeps its narrower legacy check (_legacy_cohort_staff_access), so it is not broadened to the forum roles.CohortCSV: keeps theis_staff-only fallback it had withIsAdminUser. Whether it should bemanage_cohortslong-term is open, see "Other Information".InstructorPermission, which only sees legacy roles, so it returned403for AuthZ-only users. It follows the tab'sview_cohorts, not Studio'sview_group_configurations: that avoids breaking custom roles without the Studio permission and does not widen access to Course Editor or Auditor.Other changes
_get_course_with_accessranget_course_with_access(user, 'staff')after AuthZ had allowed the request, and it only recognizes legacy roles. With the flag on, astaffaction now only loads the course.load(CohortHandler.get) keeps going throughget_course_with_access, so visibility, dates and prerequisites checks stay. With the flag off the check is kept, because it is what stops forum roles from reaching the staff-only GETs.InstructorAuthzPermissiongets an optionalcourse_id_url_kwarg(default"course_id"), because the cohorts API usescourse_key_string. Documented in the README.Supporting Information
course_groupsAPI) openedx-authz#492Testing Instructions
Enable
authz.enable_course_authoringfor a test course and create a cohort.Flag on. Call every endpoint in the table above as each of these users:
403/404.403.403.Flag off. Behavior is unchanged:
403.403for a course instructor, allowed for Django staff.Run the tests:
Automated coverage added:
CohortsAuthzTest(DRF views),CohortSettingsHandlerAuthzTest,CohortCSVAuthzTest,ContentGroupsAuthzTestCase(content groups v2) andtest_custom_course_id_url_kwarg. They cover Course Admin, Course Staff, no permission, an AuthZ role without a legacy equivalent, AuthZ denying a legacy role, and the flag-off path.Deadline
Willow
Other Information
CohortCSVintentionally keeps itsis_staff-only fallback. It is worth a product/security conversation whether it should becomemanage_cohorts.cohort_handlerand the function viewsusers_in_cohort,add_users_to_cohort,remove_user_from_cohort,debug_cohort_mgmt. They do not go throughInstructorAuthzPermission, so AuthZ-only users still cannot use them.IsStaffOrAdmin.