core: add general admin.py loader, remove individual files

This commit is contained in:
Jens Langhammer 2020-05-07 00:05:10 +02:00
parent fff05e35ac
commit 80d90b91e8
22 changed files with 24 additions and 118 deletions

View File

@ -1,5 +0,0 @@
"""passbook audit model admin"""
from passbook.lib.admin import admin_autoregister
admin_autoregister("passbook_audit")

View File

@ -1,5 +1,24 @@
"""passbook core model admin""" """passbook core admin"""
from passbook.lib.admin import admin_autoregister from django.apps import AppConfig, apps
from django.contrib import admin
from django.contrib.admin.sites import AlreadyRegistered
from guardian.admin import GuardedModelAdmin
from structlog import get_logger
admin_autoregister("passbook_core") LOGGER = get_logger()
def admin_autoregister(app: AppConfig):
"""Automatically register all models from app"""
for model in app.get_models():
try:
admin.site.register(model, GuardedModelAdmin)
except AlreadyRegistered:
pass
for app in apps.get_app_configs():
if app.label.startswith("passbook_"):
LOGGER.debug("Registering application for dj-admin", app=app.label)
admin_autoregister(app)

View File

@ -1,5 +0,0 @@
"""passbook crypto model admin"""
from passbook.lib.admin import admin_autoregister
admin_autoregister("passbook_crypto")

View File

@ -1,5 +0,0 @@
"""captcha factor admin"""
from passbook.lib.admin import admin_autoregister
admin_autoregister("passbook_factors_captcha")

View File

@ -1,5 +0,0 @@
"""dummy factor admin"""
from passbook.lib.admin import admin_autoregister
admin_autoregister("passbook_factors_dummy")

View File

@ -1,5 +0,0 @@
"""email factor admin"""
from passbook.lib.admin import admin_autoregister
admin_autoregister("passbook_factors_email")

View File

@ -1,5 +0,0 @@
"""password factor admin"""
from passbook.lib.admin import admin_autoregister
admin_autoregister("passbook_factors_password")

View File

@ -1,22 +0,0 @@
"""passbook core admin"""
from django.apps import apps
from django.contrib import admin
from django.contrib.admin.sites import AlreadyRegistered
from django.contrib.auth.admin import UserAdmin
from guardian.admin import GuardedModelAdmin
from passbook.core.models import User
def admin_autoregister(app):
"""Automatically register all models from app"""
app_models = apps.get_app_config(app).get_models()
for model in app_models:
try:
admin.site.register(model, GuardedModelAdmin)
except AlreadyRegistered:
pass
admin.site.register(User, UserAdmin)

View File

@ -1,5 +0,0 @@
"""Passbook passbook expiry policy Admin"""
from passbook.lib.admin import admin_autoregister
admin_autoregister("passbook_policies_expiry")

View File

@ -1,5 +0,0 @@
"""Passbook passbook expression policy Admin"""
from passbook.lib.admin import admin_autoregister
admin_autoregister("passbook_policies_expression")

View File

@ -1,5 +0,0 @@
"""Passbook HIBP Admin"""
from passbook.lib.admin import admin_autoregister
admin_autoregister("passbook_policies_hibp")

View File

@ -1,4 +0,0 @@
"""autodiscover admin"""
from passbook.lib.admin import admin_autoregister
admin_autoregister("passbook_policies_password")

View File

@ -1,5 +0,0 @@
"""Passbook reputation Admin"""
from passbook.lib.admin import admin_autoregister
admin_autoregister("passbook_policies_reputation")

View File

@ -1,4 +0,0 @@
"""autodiscover admin"""
from passbook.lib.admin import admin_autoregister
admin_autoregister("passbook_policies_webhook")

View File

@ -1,5 +0,0 @@
"""passbook Application Security Gateway model admin"""
from passbook.lib.admin import admin_autoregister
admin_autoregister("passbook_providers_app_gw")

View File

@ -1,4 +0,0 @@
"""oauth provider admin"""
# from passbook.lib.admin import admin_autoregister
# admin_autoregister('passbook_providers_oauth')

View File

@ -1,5 +0,0 @@
"""oidc provider admin"""
from passbook.lib.admin import admin_autoregister
admin_autoregister("passbook_providers_oidc")

View File

@ -1,5 +0,0 @@
"""SAML IDP Admin"""
from passbook.lib.admin import admin_autoregister
admin_autoregister("passbook_providers_saml")

View File

@ -79,7 +79,6 @@ INSTALLED_APPS = [
"drf_yasg", "drf_yasg",
"guardian", "guardian",
"django_prometheus", "django_prometheus",
"passbook.core.apps.PassbookCoreConfig",
"passbook.static.apps.PassbookStaticConfig", "passbook.static.apps.PassbookStaticConfig",
"passbook.admin.apps.PassbookAdminConfig", "passbook.admin.apps.PassbookAdminConfig",
"passbook.api.apps.PassbookAPIConfig", "passbook.api.apps.PassbookAPIConfig",
@ -384,3 +383,5 @@ for _app in INSTALLED_APPS:
if DEBUG: if DEBUG:
INSTALLED_APPS.append("debug_toolbar") INSTALLED_APPS.append("debug_toolbar")
MIDDLEWARE.append("debug_toolbar.middleware.DebugToolbarMiddleware") MIDDLEWARE.append("debug_toolbar.middleware.DebugToolbarMiddleware")
INSTALLED_APPS.append("passbook.core.apps.PassbookCoreConfig")

View File

@ -1,5 +0,0 @@
"""Passbook LDAP Admin"""
from passbook.lib.admin import admin_autoregister
admin_autoregister("passbook_sources_ldap")

View File

@ -1,5 +0,0 @@
"""passbook oauth_client admin"""
from passbook.lib.admin import admin_autoregister
admin_autoregister("passbook_sources_oauth")

View File

@ -1,5 +0,0 @@
"""SAML SP Admin"""
from passbook.lib.admin import admin_autoregister
admin_autoregister("passbook_sources_saml")