Skip to content

Commit bc7624d

Browse files
committed
fixup! feat: add course authoring migration and rollback scripts
1 parent af13f30 commit bc7624d

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

openedx_authz/engine/utils.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def migrate_legacy_course_roles_to_authz(course_access_role_model, course_id_lis
187187
- user: subject
188188
- role: role
189189
190-
param course_access_role_model: The CourseAccessRole model to use. This is passed in because the function
190+
param course_access_role_model: It should be the CourseAccessRole model. This is passed in because the function
191191
is intended to run within a Django migration context, where direct model imports can cause issues.
192192
param course_id_list: Optional list of course IDs to filter the migration.
193193
param org_id: Optional organization ID to filter the migration.
@@ -253,6 +253,8 @@ def migrate_legacy_course_roles_to_authz(course_access_role_model, course_id_lis
253253
if delete_after_migration:
254254
# Only delete permissions that were successfully migrated to avoid data loss.
255255
course_access_role_model.objects.filter(id__in=[p.id for p in permissions_with_no_errors]).delete()
256+
logger.info(f"Deleted {len(permissions_with_no_errors)} legacy permissions after successful migration.")
257+
logger.info(f"Retained {len(permissions_with_errors)} legacy permissions that had errors during migration.")
256258

257259
return permissions_with_errors, permissions_with_no_errors
258260

@@ -268,9 +270,10 @@ def migrate_authz_to_legacy_course_roles(
268270
This is essentially the reverse of migrate_legacy_course_roles_to_authz and is intended
269271
for rollback purposes in case of migration issues.
270272
271-
param course_access_role_model: The CourseAccessRole model to use. This is passed in because the function
273+
param course_access_role_model: It should be the CourseAccessRole model. This is passed in because the function
274+
is intended to run within a Django migration context, where direct model imports can cause issues.
275+
param user_subject_model: It should be the UserSubject model. This is passed in because the function
272276
is intended to run within a Django migration context, where direct model imports can cause issues.
273-
param user_subject_model: The UserSubject model to query for users with course-related permissions.
274277
param course_id_list: Optional list of course IDs to filter the migration.
275278
param org_id: Optional organization ID to filter the migration.
276279
param delete_after_migration: Whether to unassign successfully migrated permissions
@@ -347,4 +350,8 @@ def migrate_authz_to_legacy_course_roles(
347350
role_external_key=role.external_key,
348351
scope_external_key=scope,
349352
)
353+
logger.info(
354+
f"Unassigned Role: {role.external_key} from User: {user_external_key} in Scope: {scope}"
355+
f" after successful rollback migration."
356+
)
350357
return roles_with_errors, roles_with_no_errors

openedx_authz/tests/test_migrations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ def test_authz_rollback_course_authoring_command_with_org_and_courses(self):
10421042
@patch("openedx_authz.engine.utils.LEGACY_COURSE_ROLE_EQUIVALENCES", {"instructor": "instructor-role"})
10431043
def test_migrate_legacy_course_roles_to_authz_user_not_added(
10441044
self,
1045-
_, # comes from patch
1045+
_,
10461046
):
10471047
errors, successes = migrate_legacy_course_roles_to_authz(
10481048
self.mock_course_access_role,

0 commit comments

Comments
 (0)