diff --git a/backend/users/management/commands/create_staffusers.py b/backend/users/management/commands/create_staffusers.py index 0ceff37c4b..29cc805d11 100644 --- a/backend/users/management/commands/create_staffusers.py +++ b/backend/users/management/commands/create_staffusers.py @@ -1,3 +1,4 @@ +# flake8: noqa from django.conf import settings from django.contrib.auth import get_user_model from django.contrib.auth.models import Group, Permission @@ -16,6 +17,9 @@ class Command(BaseCommand): def handle(self, *args, **kwargs): """Create a group with readonly permissions.""" + logger.info(f"Permission dump ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") + logger.info(Permission.objects.all().values()) + group_readonly, created = Group.objects.get_or_create(name="Read-only") readonly_codenames = [ "view_access", @@ -40,7 +44,10 @@ def handle(self, *args, **kwargs): ] group_readonly.permissions.clear() for code in readonly_codenames: - group_readonly.permissions.add(Permission.objects.get(codename=code)) + try: + group_readonly.permissions.add(Permission.objects.get(codename=code)) + except Exception as e: + logger.error(f"1. Failed to get ({code}) -- {e}") group_readonly.save() """Create a group with helpdesk permissions.""" @@ -58,7 +65,10 @@ def handle(self, *args, **kwargs): ] group_helpdesk.permissions.clear() for code in helpdesk_codenames: - group_helpdesk.permissions.add(Permission.objects.get(codename=code)) + try: + group_helpdesk.permissions.add(Permission.objects.get(codename=code)) + except Exception as e: + logger.error(f"2. Failed to get ({code}) -- {e}") group_helpdesk.save() # read in staffusers JSON. @@ -99,7 +109,6 @@ def handle(self, *args, **kwargs): case "readonly": user.groups.add(group_readonly) case "helpdesk": - user.groups.clear() user.groups.add(group_helpdesk) case "superuser": user.is_superuser = True