Skip to content
Snippets Groups Projects
Commit 5a5667f9 authored by Benjamin Ledel's avatar Benjamin Ledel
Browse files

* avoid debug logs

parent 5bc2a214
Branches
No related tags found
No related merge requests found
......@@ -3,12 +3,13 @@ from django.core.management import call_command
from django.db import connections
from django.db.migrations.executor import MigrationExecutor
from django.contrib.auth.models import Permission, ContentType, Group
from users.models import CustomUser # Adjust this import based on your actual user model
from django.conf import settings # Import settings
class Command(BaseCommand):
help = 'Check and apply necessary migrations and ensure roles, permissions, and groups are set up correctly'
def handle(self, *args, **kwargs):
if settings.DEBUG:
self.stdout.write(self.style.NOTICE('Checking for pending migrations...'))
connection = connections['default']
......@@ -16,12 +17,16 @@ class Command(BaseCommand):
targets = executor.loader.graph.leaf_nodes()
if executor.migration_plan(targets):
if settings.DEBUG:
self.stdout.write(self.style.WARNING('Pending migrations found. Applying migrations...'))
call_command('migrate')
if settings.DEBUG:
self.stdout.write(self.style.SUCCESS('All migrations applied successfully.'))
else:
if settings.DEBUG:
self.stdout.write(self.style.SUCCESS('No pending migrations found.'))
if settings.DEBUG:
self.stdout.write(self.style.NOTICE('Checking roles and permissions...'))
# Ensure necessary permissions exist
......@@ -45,12 +50,12 @@ class Command(BaseCommand):
defaults={'name': name}
)
permission_objects[codename] = permission
if settings.DEBUG:
if created:
self.stdout.write(self.style.SUCCESS(f'Permission created: {name}'))
else:
self.stdout.write(self.style.NOTICE(f'Permission already exists: {name}'))
# Ensure auth groups exist and assign permissions
groups_permissions = {
"polaris_administrator": ["create_user","edit_user","create_provider","change_provider","manage_provider_keys","manage_analytics_tokens","create_user_consent","request_user_data"],
......@@ -61,6 +66,7 @@ class Command(BaseCommand):
for group_name, perms in groups_permissions.items():
group, created = Group.objects.get_or_create(name=group_name)
if settings.DEBUG:
if created:
self.stdout.write(self.style.SUCCESS(f'Group created: {group_name}'))
else:
......@@ -70,6 +76,8 @@ class Command(BaseCommand):
for perm in perms:
if perm in permission_objects:
group.permissions.add(permission_objects[perm])
if settings.DEBUG:
self.stdout.write(self.style.SUCCESS(f'Assigned permission {perm} to group {group_name}'))
if settings.DEBUG:
self.stdout.write(self.style.SUCCESS('Roles, permissions, and groups check completed.'))
......@@ -34,8 +34,8 @@ mimetypes.add_type("text/javascript", ".js", True)
SECRET_KEY = "django-insecure-4%wn*pt3vpdgk#==(qbtocdh#-2wr58py(ri=(0a^15&&n*gl9"
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env("DEBUG", default=False) == True
DEBUG_PROPAGATE_EXCEPTIONS = env("DEBUG_PROPAGATE_EXCEPTIONS", default=False) == True
DEBUG = (env("DEBUG", default=False) == True)
DEBUG_PROPAGATE_EXCEPTIONS = (env("DEBUG_PROPAGATE_EXCEPTIONS", default=False) == True)
TESTING = env("TESTING", default="False")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment