core: add general admin.py loader, remove individual files
This commit is contained in:
parent
fff05e35ac
commit
80d90b91e8
|
@ -1,5 +0,0 @@
|
||||||
"""passbook audit model admin"""
|
|
||||||
|
|
||||||
from passbook.lib.admin import admin_autoregister
|
|
||||||
|
|
||||||
admin_autoregister("passbook_audit")
|
|
|
@ -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)
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
"""passbook crypto model admin"""
|
|
||||||
|
|
||||||
from passbook.lib.admin import admin_autoregister
|
|
||||||
|
|
||||||
admin_autoregister("passbook_crypto")
|
|
|
@ -1,5 +0,0 @@
|
||||||
"""captcha factor admin"""
|
|
||||||
|
|
||||||
from passbook.lib.admin import admin_autoregister
|
|
||||||
|
|
||||||
admin_autoregister("passbook_factors_captcha")
|
|
|
@ -1,5 +0,0 @@
|
||||||
"""dummy factor admin"""
|
|
||||||
|
|
||||||
from passbook.lib.admin import admin_autoregister
|
|
||||||
|
|
||||||
admin_autoregister("passbook_factors_dummy")
|
|
|
@ -1,5 +0,0 @@
|
||||||
"""email factor admin"""
|
|
||||||
|
|
||||||
from passbook.lib.admin import admin_autoregister
|
|
||||||
|
|
||||||
admin_autoregister("passbook_factors_email")
|
|
|
@ -1,5 +0,0 @@
|
||||||
"""password factor admin"""
|
|
||||||
|
|
||||||
from passbook.lib.admin import admin_autoregister
|
|
||||||
|
|
||||||
admin_autoregister("passbook_factors_password")
|
|
|
@ -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)
|
|
|
@ -1,5 +0,0 @@
|
||||||
"""Passbook passbook expiry policy Admin"""
|
|
||||||
|
|
||||||
from passbook.lib.admin import admin_autoregister
|
|
||||||
|
|
||||||
admin_autoregister("passbook_policies_expiry")
|
|
|
@ -1,5 +0,0 @@
|
||||||
"""Passbook passbook expression policy Admin"""
|
|
||||||
|
|
||||||
from passbook.lib.admin import admin_autoregister
|
|
||||||
|
|
||||||
admin_autoregister("passbook_policies_expression")
|
|
|
@ -1,5 +0,0 @@
|
||||||
"""Passbook HIBP Admin"""
|
|
||||||
|
|
||||||
from passbook.lib.admin import admin_autoregister
|
|
||||||
|
|
||||||
admin_autoregister("passbook_policies_hibp")
|
|
|
@ -1,4 +0,0 @@
|
||||||
"""autodiscover admin"""
|
|
||||||
from passbook.lib.admin import admin_autoregister
|
|
||||||
|
|
||||||
admin_autoregister("passbook_policies_password")
|
|
|
@ -1,5 +0,0 @@
|
||||||
"""Passbook reputation Admin"""
|
|
||||||
|
|
||||||
from passbook.lib.admin import admin_autoregister
|
|
||||||
|
|
||||||
admin_autoregister("passbook_policies_reputation")
|
|
|
@ -1,4 +0,0 @@
|
||||||
"""autodiscover admin"""
|
|
||||||
from passbook.lib.admin import admin_autoregister
|
|
||||||
|
|
||||||
admin_autoregister("passbook_policies_webhook")
|
|
|
@ -1,5 +0,0 @@
|
||||||
"""passbook Application Security Gateway model admin"""
|
|
||||||
|
|
||||||
from passbook.lib.admin import admin_autoregister
|
|
||||||
|
|
||||||
admin_autoregister("passbook_providers_app_gw")
|
|
|
@ -1,4 +0,0 @@
|
||||||
"""oauth provider admin"""
|
|
||||||
# from passbook.lib.admin import admin_autoregister
|
|
||||||
|
|
||||||
# admin_autoregister('passbook_providers_oauth')
|
|
|
@ -1,5 +0,0 @@
|
||||||
"""oidc provider admin"""
|
|
||||||
|
|
||||||
from passbook.lib.admin import admin_autoregister
|
|
||||||
|
|
||||||
admin_autoregister("passbook_providers_oidc")
|
|
|
@ -1,5 +0,0 @@
|
||||||
"""SAML IDP Admin"""
|
|
||||||
|
|
||||||
from passbook.lib.admin import admin_autoregister
|
|
||||||
|
|
||||||
admin_autoregister("passbook_providers_saml")
|
|
|
@ -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")
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
"""Passbook LDAP Admin"""
|
|
||||||
|
|
||||||
from passbook.lib.admin import admin_autoregister
|
|
||||||
|
|
||||||
admin_autoregister("passbook_sources_ldap")
|
|
|
@ -1,5 +0,0 @@
|
||||||
"""passbook oauth_client admin"""
|
|
||||||
|
|
||||||
from passbook.lib.admin import admin_autoregister
|
|
||||||
|
|
||||||
admin_autoregister("passbook_sources_oauth")
|
|
|
@ -1,5 +0,0 @@
|
||||||
"""SAML SP Admin"""
|
|
||||||
|
|
||||||
from passbook.lib.admin import admin_autoregister
|
|
||||||
|
|
||||||
admin_autoregister("passbook_sources_saml")
|
|
Reference in New Issue