-
Notifications
You must be signed in to change notification settings - Fork 5
feat: add course authoring migration and rollback scripts #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rodmgwgu
merged 18 commits into
openedx:main
from
WGU-Open-edX:dwong2708/migration-script-for-course-roles
Mar 4, 2026
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
724662c
feat: add course authoring migration and rollback scripts
dwong2708 bf5d76c
fixup! feat: add course authoring migration and rollback scripts
dwong2708 ac7acef
fixup! feat: add course authoring migration and rollback scripts
dwong2708 e627dd7
fixup! feat: add course authoring migration and rollback scripts
dwong2708 ec9785f
fixup! feat: add course authoring migration and rollback scripts
dwong2708 1cda364
fixup! feat: add course authoring migration and rollback scripts
dwong2708 c8f1c73
fixup! feat: add course authoring migration and rollback scripts
dwong2708 37149a8
fixup! feat: add course authoring migration and rollback scripts
dwong2708 1753f8e
fixup! feat: add course authoring migration and rollback scripts
dwong2708 0a21eb5
fixup! feat: add course authoring migration and rollback scripts
dwong2708 82aed9e
fixup! feat: add course authoring migration and rollback scripts
dwong2708 f290079
fixup! feat: add course authoring migration and rollback scripts
dwong2708 bd4f1a3
fixup! feat: add course authoring migration and rollback scripts
dwong2708 af13f30
fixup! feat: add course authoring migration and rollback scripts
dwong2708 bc7624d
fixup! feat: add course authoring migration and rollback scripts
dwong2708 9fbc920
fixup! feat: add course authoring migration and rollback scripts
dwong2708 ccfea4d
fixup! feat: add course authoring migration and rollback scripts
dwong2708 d830f3c
fixup! feat: add course authoring migration and rollback scripts
dwong2708 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
87 changes: 87 additions & 0 deletions
87
openedx_authz/management/commands/authz_migrate_course_authoring.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| """ | ||
| Django management command to migrate legacy course authoring roles to the new Authz (Casbin-based) authorization system. | ||
| """ | ||
|
|
||
| from django.core.management.base import BaseCommand, CommandError | ||
| from django.db import transaction | ||
|
|
||
| from openedx_authz.engine.utils import migrate_legacy_course_roles_to_authz | ||
|
|
||
| try: | ||
| from common.djangoapps.student.models import CourseAccessRole | ||
| except ImportError: | ||
| CourseAccessRole = None # type: ignore | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| """ | ||
| Django command to migrate legacy CourseAccessRole data | ||
| to the new Authz (Casbin-based) authorization system. | ||
| """ | ||
|
|
||
| help = "Migrate legacy course authoring roles to the new Authz system." | ||
|
|
||
| def add_arguments(self, parser): | ||
| parser.add_argument( | ||
| "--delete", | ||
| action="store_true", | ||
| help="Delete legacy CourseAccessRole records after successful migration.", | ||
| ) | ||
| parser.add_argument( | ||
| "--course-id-list", | ||
| nargs="+", | ||
| type=str, | ||
| help="Optional list of course IDs to filter the migration.", | ||
| ) | ||
|
|
||
| parser.add_argument( | ||
| "--org-id", | ||
| type=str, | ||
| help="Optional organization ID to filter the migration.", | ||
| ) | ||
|
|
||
| def handle(self, *args, **options): | ||
| delete_after_migration = options["delete"] | ||
| course_id_list = options.get("course_id_list") | ||
| org_id = options.get("org_id") | ||
|
|
||
| if not course_id_list and not org_id: | ||
| raise CommandError("You must specify either --course-id-list or --org-id to filter the migration.") | ||
|
|
||
| if course_id_list and org_id: | ||
| raise CommandError("You cannot use --course-id-list and --org-id together.") | ||
|
|
||
| self.stdout.write(self.style.WARNING("Starting legacy → Authz migration...")) | ||
|
|
||
| try: | ||
| if delete_after_migration: | ||
| confirm = input( | ||
| "Are you sure you want to delete successfully migrated legacy roles? Type 'yes' to continue: " | ||
| ) | ||
|
|
||
| if confirm != "yes": | ||
| self.stdout.write(self.style.WARNING("Migration aborted.")) | ||
| return | ||
| with transaction.atomic(): | ||
| errors, success = migrate_legacy_course_roles_to_authz( | ||
| course_access_role_model=CourseAccessRole, | ||
| course_id_list=course_id_list, | ||
| org_id=org_id, | ||
| delete_after_migration=delete_after_migration, | ||
| ) | ||
|
|
||
| if errors: | ||
| self.stdout.write(self.style.ERROR(f"Migration completed with {len(errors)} errors.")) | ||
| else: | ||
| self.stdout.write( | ||
| self.style.SUCCESS(f"Migration completed successfully with {len(success)} roles migrated.") | ||
| ) | ||
|
|
||
| if delete_after_migration: | ||
| self.stdout.write(self.style.SUCCESS(f"{len(success)} Legacy roles deleted successfully.")) | ||
|
|
||
| except Exception as exc: | ||
| self.stdout.write(self.style.ERROR(f"Migration failed due to unexpected error: {exc}")) | ||
| raise | ||
|
|
||
| self.stdout.write(self.style.SUCCESS("Done.")) |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.