Skip to content

Commit

Permalink
Merge pull request #4515 from unicef/generateroles_handle_2
Browse files Browse the repository at this point in the history
[225556] generateroles in upgrade but skip updating existing roles
  • Loading branch information
pkujawa authored Dec 11, 2024
2 parents 5b15e07 + 3228cd2 commit 6c66922
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,27 +292,20 @@ def handle(self, *args: Any, **options: Any) -> None:
print("Old incompatible roles pairs were deleted.")

roles_created = []
roles_updated = []
for default_role in default_roles_matrix:
role, created = Role.objects.update_or_create(
role, created = Role.objects.get_or_create(
subsystem=Role.HOPE,
name=default_role["name"],
defaults={"permissions": [permission.value for permission in default_role["permissions"]]},
)

if created:
roles_created.append(role.name)
else:
roles_updated.append(role.name)

if roles_created:
print(f"New roles were created: {', '.join(roles_created)}")
else:
print("No new roles were created.")
if roles_updated:
print(f"These roles were updated: {', '.join(roles_updated)}")
else:
print("No roles were updated")

incompatible_roles_created = []
for role_pair in default_incompatible_roles:
Expand Down
1 change: 1 addition & 0 deletions src/hct_mis_api/apps/core/management/commands/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Command(BaseCommand):
def handle(self, *args: Any, **options: Any) -> None:
call_command("migratealldb")
call_command("collectstatic", "--no-default-ignore", interactive=False)
call_command("generateroles")
from adminactions.perms import create_extra_permissions

create_extra_permissions()

0 comments on commit 6c66922

Please sign in to comment.