fix(access): When creating permission QuerySet prevent app crash if db not setup

ref: #947 #152
This commit is contained in:
2025-08-10 16:42:33 +09:30
parent 6ff4779cfb
commit 3131258491

View File

@ -1,9 +1,10 @@
from django.apps import apps
from django.conf import settings
from django.contrib.auth.models import (
ContentType,
Permission
)
from django.conf import settings
from django.db.models import QuerySet
def permission_queryset():
@ -61,6 +62,10 @@ def permission_queryset():
if not settings.RUNNING_TESTS:
try:
# This blocks purpose is to cater for fresh install
# so that the app does not crash before the DB is setup.
models = apps.get_models()
for model in models:
@ -105,3 +110,18 @@ def permission_queryset():
).exclude(
codename__in = exclude_permissions
)
except:
pass
return QuerySet()
else:
return Permission.objects.select_related('content_type').filter(
content_type__app_label__in = centurion_apps,
).exclude(
content_type__model__in = exclude_models
).exclude(
codename__in = exclude_permissions
)