Skip to content
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

Hotfix -- staffuser logging #4585

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions backend/users/management/commands/create_staffusers.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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",
Expand All @@ -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."""
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Loading