Skip to content

Commit b245375

Browse files
author
Tycho Hob
committed
refactor: Clarify migration command output
Previously if there were any errors, success messages were eaten. Added message to state why no roles may have been migrated (already migrated, bad ids)
1 parent 39d8a31 commit b245375

3 files changed

Lines changed: 32 additions & 5 deletions

File tree

openedx_authz/engine/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ def migrate_legacy_course_roles_to_authz(course_access_role_model, course_id_lis
258258
if not is_user_added:
259259
logger.error(
260260
f"Failed to migrate permission for User: {permission.user.username} "
261-
f"to Role: {role} in Scope: {permission.course_id}"
261+
f"to Role: {role} in Scope: {permission.course_id} "
262+
"user may already have this permission assigned"
262263
)
263264
permissions_with_errors.append(permission)
264265
continue

openedx_authz/management/commands/authz_migrate_course_authoring.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,25 @@ def handle(self, *args, **options):
7070
delete_after_migration=delete_after_migration,
7171
)
7272

73-
if errors:
73+
if errors and success:
74+
self.stdout.write(
75+
self.style.WARNING(
76+
f"Migration completed with {len(errors)} errors and {len(success)} roles migrated."
77+
)
78+
)
79+
elif errors:
7480
self.stdout.write(self.style.ERROR(f"Migration completed with {len(errors)} errors."))
75-
else:
81+
elif success:
7682
self.stdout.write(
7783
self.style.SUCCESS(f"Migration completed successfully with {len(success)} roles migrated.")
7884
)
85+
else:
86+
self.stdout.write(
87+
self.style.ERROR(
88+
"No legacy roles found for the given scope, course could already be migrated, "
89+
"or there coule be a an error in the course_id_list / org_id."
90+
)
91+
)
7992

8093
if delete_after_migration:
8194
self.stdout.write(self.style.SUCCESS(f"{len(success)} Legacy roles deleted successfully."))

openedx_authz/management/commands/authz_rollback_course_authoring.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,25 @@ def handle(self, *args, **options):
7474
delete_after_migration=delete_after_migration, # control deletion here
7575
)
7676

77-
if errors:
77+
if errors and success:
78+
self.stdout.write(
79+
self.style.WARNING(
80+
f"Rollback completed with {len(errors)} errors and {len(success)} roles migrated."
81+
)
82+
)
83+
elif errors:
7884
self.stdout.write(self.style.ERROR(f"Rollback completed with {len(errors)} errors."))
79-
else:
85+
elif success:
8086
self.stdout.write(
8187
self.style.SUCCESS(f"Rollback completed successfully with {len(success)} roles rolled back.")
8288
)
89+
else:
90+
self.stdout.write(
91+
self.style.ERROR(
92+
"No roles found for the given scope, course could already be rolled back, "
93+
"or there coule be a an error in the course_id_list / org_id."
94+
)
95+
)
8396

8497
if delete_after_migration:
8598
self.stdout.write(

0 commit comments

Comments
 (0)