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",
"guardian",
"django_prometheus",
"passbook.core.apps.PassbookCoreConfig",
"passbook.static.apps.PassbookStaticConfig",
"passbook.admin.apps.PassbookAdminConfig",
"passbook.api.apps.PassbookAPIConfig",
@ -384,3 +383,5 @@ for _app in INSTALLED_APPS:
if DEBUG:
INSTALLED_APPS.append("debug_toolbar")
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")