Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
With
authz.enable_course_authoringon for an organization, a course creator who already holds an organization-widecourse_admingets a 403 from course creation, after the course has been written. Org-widecourse_adminis what the AuthZ migration makes from a legacy organization-wideinstructorrole. Becauseadd_instructorraises partway throughcreate_new_course, the course is left half set up: no enrollment for the creator, no forum role seeding, and the rest of the post-creation steps are skipped.Fixes openedx/openedx-authz#521.
Cause
add_instructoradds the creator toCourseInstructorRoleand then callsauth.add_users(..., CourseStaffRole(...)), whose_check_caller_authorityrequires the caller to hold the course's instructor role.Under AuthZ,
CourseInstructorRole.add_usersgoes throughauthz_add_role, which first askedget_user_role_assignments_in_scope(<new course>)whether the user already hadcourse_adminthere. That call also reports roles inherited from org-wide (course-v1:ORG+*) and platform-wide assignments, so for an org-wide admin it said yes, andauthz_add_rolereturned without making a course-level assignment.The legacy compatibility layer (
RoleCache) maps an org-wide assignment to an org-level role with no course key, andCourseRole.has_useronly looks at course-level roles. Souser_has_role(creator, CourseInstructorRole(course))wasFalse, and_check_caller_authorityraisedPermissionDenied.Measured on a Tutor
mainsandbox (openedx-authz 1.24.0):A creator without an org-wide role is not affected: the pre-check finds nothing and the course assignment is made.
Fix
authz_add_rolenow assigns the role in the course's own scope directly and drops the inheritance-blind pre-check.assign_role_to_user_in_scopealready returnsFalsewhen that exact assignment exists, so the "already has it" case still returns early (and still emits no duplicate event).The creator ends up with both the org-wide and a course-level
course_admin. That matches legacy behavior, where the creator always got an explicit course role, and it means the creator keeps admin on a course they created if the org-wide role is later revoked.Testing instructions
authz.enable_course_authoringfor an organization (waffle flag org override).course_adminin that organization (course-v1:<ORG>+*), for example by migrating a legacy org-wideinstructor.403 {"error": "User does not have the permission to create courses in this organization or course creation is disabled"}; the course exists but the creator is not enrolled.200, and the creator is the course's instructor and staff.Other information
Found by the Open edX end-to-end test suite: TC-00640, finding
RBAC-015indocs/findings.md, tracked as end-to-end-tests#118.🤖 Generated with Claude Opus 5.5.