feat: add course authoring migration and rollback scripts#218
feat: add course authoring migration and rollback scripts#218dwong2708 wants to merge 4 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. 🔘 Update the status of your PRYour PR is currently marked as a draft. After completing the steps above, update its status by clicking "Ready for Review", or removing "WIP" from the title, as appropriate. Where 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.
| param CourseAccessRole: The CourseAccessRole model to use. | ||
| """ | ||
|
|
||
| legacy_permissions = CourseAccessRole.objects.select_related("user").all() |
There was a problem hiding this comment.
We need to make sure to only do the migration on courses that have the flag enabled.
| for assignment in role_assignments: | ||
| scope = assignment.scope.external_key | ||
|
|
||
| course_overview = assignment.scope.get_object() |
There was a problem hiding this comment.
We should only rollback courses that don't have the flag enabled
- 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 - Add Django data migration to automatically trigger the migration
b605933 to
0b8547b
Compare
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 [--delete]authz_rollback_course_authoringRolls back Authz course authoring roles into legacy CourseAccessRole.
./manage.py cms authz_rollback_course_authoring [--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: