feat: add course authoring migration and rollback scripts#218
feat: add course authoring migration and rollback scripts#218dwong2708 wants to merge 10 commits intoopenedx:mainfrom
Conversation
|
Thanks for the pull request, @dwong2708! 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. |
rodmgwgu
left a comment
There was a problem hiding this comment.
We should make sure to only apply the migrations on courses that are covered by the feature flag.
If we cannot access the feature flag from here (as it is defined in edx-platform), we should add a parameter to the migration commands and functions to specify a list of courses to work on, so edx-platform can specify which courses to migrate.
b605933 to
0b8547b
Compare
- Add `authz_migrate_course_authoring` command to migrate legacy CourseAccessRole data to the new Authz (Casbin-based) system - Add `authz_rollback_course_authoring` command to rollback Authz roles back to legacy CourseAccessRole - Support optional `--delete` flag for controlled cleanup of source permissions after successful migration - Add `migrate_legacy_course_roles_to_authz` and `migrate_authz_to_legacy_course_roles` service functions - Add unit tests to verify migration and command behavior
b0463fa to
c8f1c73
Compare
bmtcril
left a comment
There was a problem hiding this comment.
Overall this is looking good. I think there is some tension between the need to use these commands for testing and for production migrations. For instance being able to migrate permissions when the waffle flag is not set which can cause perms to get out of sync and might cause confusion when an operator runs the command but nothing changes on the frontend.
Maybe we can add a flag that makes sure the waffle flag for the course(s) is set correctly for the direction that the migration is happening so the state stays locked to the permissions? I think I would make the operator version the default (change the waffle flag and delete) and make testing the exceptional case. What do you think?
| return permissions_with_errors | ||
|
|
||
|
|
||
| def migrate_legacy_course_roles_to_authz(CourseAccessRole, course_id_list, org_id, delete_after_migration): |
There was a problem hiding this comment.
I can see why CourseAccessRole is named that, but it's pretty confusing to read. Would you be ok renaming it to something like course_access_role_model and putting a note in as to why we pass it this way?
| return permissions_with_errors, permissions_with_no_errors | ||
|
|
||
|
|
||
| def migrate_authz_to_legacy_course_roles(CourseAccessRole, UserSubject, course_id_list, org_id, delete_after_migration): |
There was a problem hiding this comment.
Same thing as above with these names
| continue | ||
|
|
||
| # If we successfully created the legacy role, we can unassign the new role | ||
| if delete_after_migration: |
There was a problem hiding this comment.
In the other direction we only do this on roles_with_no_errors, should we do the same here?
Resolves: #179
Course Authoring Roles Migration to Authz
Overview
This PR introduces migration and rollback support for course authoring roles between the legacy
CourseAccessRolemodel and the new Authz (Casbin-based) authorization system.It provides:
Automated data migration(The Django migration will be added once it is released)What’s Included
1️⃣ Management Commands
authz_migrate_course_authoringMigrates legacy
CourseAccessRoleentries to the new Authz system../manage.py authz_migrate_course_authoring (--course-id-list <id> [<id> ...] | --org-id <org>) [--delete]authz_rollback_course_authoringRolls back Authz course authoring roles into legacy CourseAccessRole.
./manage.py cms authz_rollback_course_authoring (--course-id-list <id> [<id> ...] | --org-id <org>) [--delete]2️⃣ Service Layer
Added two migration service functions:
migrate_legacy_course_roles_to_authzmigrate_authz_to_legacy_course_rolesThese encapsulate the migration logic and are reusable by:
3️⃣
Data MigrationA Django data migration has been added to automatically trigger the forward migration.This ensures legacy course authoring roles are migrated during deployment without requiring manual intervention.4️⃣ Test Coverage
Added comprehensive unit tests that verify:
🧠 Design Considerations
Data migration runs automatically during deployment.✅ Result
This PR provides a safe, reversible, and production-ready migration path from legacy course authoring roles to the new Authz system.
Merge checklist:
Check off if complete or not applicable: