delegate enabled check to apps

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens Langhammer 2024-01-16 11:43:09 +01:00
parent 054a2e8aec
commit e8ec8d994f
No known key found for this signature in database
3 changed files with 15 additions and 2 deletions

View file

@ -1,4 +1,6 @@
"""Enterprise app config"""
from functools import lru_cache
from django.conf import settings
from authentik.blueprints.apps import ManagedAppConfig
@ -25,3 +27,12 @@ class AuthentikEnterpriseConfig(EnterpriseConfig):
orig_import = "authentik.events.middleware.AuditMiddleware"
new_import = "authentik.enterprise.middleware.EnterpriseAuditMiddleware"
settings.MIDDLEWARE = [new_import if x == orig_import else x for x in settings.MIDDLEWARE]
def enabled(self):
return self.check_enabled()
@lru_cache()
def check_enabled(self):
from authentik.enterprise.models import LicenseKey
return LicenseKey.get_total().is_valid()

View file

@ -4,6 +4,7 @@ from functools import partial
from typing import Callable
from deepdiff import DeepDiff
from django.apps.registry import apps
from django.core.files import File
from django.db import connection
from django.db.models import Model
@ -12,7 +13,6 @@ from django.db.models.signals import post_init
from django.http import HttpRequest, HttpResponse
from authentik.core.models import User
from authentik.enterprise.models import LicenseKey
from authentik.events.middleware import AuditMiddleware, should_log_model
@ -23,7 +23,7 @@ class EnterpriseAuditMiddleware(AuditMiddleware):
def __init__(self, get_response: Callable[[HttpRequest], HttpResponse]):
super().__init__(get_response)
self._enabled = LicenseKey.get_total().is_valid()
self._enabled = apps.get_app_config("authentik_enterprise").enabled()
def connect(self, request: HttpRequest):
super().connect(request)

View file

@ -1,6 +1,7 @@
"""Enterprise signals"""
from datetime import datetime
from django.apps.registry import apps
from django.db.models.signals import pre_save
from django.dispatch import receiver
from django.utils.timezone import get_current_timezone
@ -16,3 +17,4 @@ def pre_save_license(sender: type[License], instance: License, **_):
instance.internal_users = status.internal_users
instance.external_users = status.external_users
instance.expiry = datetime.fromtimestamp(status.exp, tz=get_current_timezone())
apps.get_app_config("authentik_enterprise").check_enabled.cache_clear()