diff --git a/authentik/brands/api.py b/authentik/brands/api.py index d17a5e604..c5960e4db 100644 --- a/authentik/brands/api.py +++ b/authentik/brands/api.py @@ -69,6 +69,7 @@ class Themes(models.TextChoices): def get_default_ui_footer_links(): + """Get default UI footer links based on current tenant settings""" return get_current_tenant().footer_links diff --git a/authentik/lib/logging.py b/authentik/lib/logging.py index fae097ae5..bc6e5b755 100644 --- a/authentik/lib/logging.py +++ b/authentik/lib/logging.py @@ -117,6 +117,7 @@ def add_process_id(logger: Logger, method_name: str, event_dict): def add_tenant_information(logger: Logger, method_name: str, event_dict): + """Add the current tenant""" tenant = getattr(connection, "tenant", None) if tenant is not None: event_dict["schema_name"] = tenant.schema_name diff --git a/authentik/root/db/base.py b/authentik/root/db/base.py index b7750ee73..70e8595f7 100644 --- a/authentik/root/db/base.py +++ b/authentik/root/db/base.py @@ -8,6 +8,7 @@ class DatabaseWrapper(BaseDatabaseWrapper): """database backend which supports rotating credentials""" def get_connection_params(self): + """Refresh DB credentials before getting connection params""" CONFIG.refresh("postgresql.password") conn_params = super().get_connection_params() conn_params["user"] = CONFIG.get("postgresql.user") diff --git a/authentik/tenants/api.py b/authentik/tenants/api.py index b7351a128..d58e11621 100644 --- a/authentik/tenants/api.py +++ b/authentik/tenants/api.py @@ -19,6 +19,8 @@ from authentik.tenants.models import Domain, Tenant class TenantManagementKeyPermission(permissions.BasePermission): + """Authentication based on tenant_management_key""" + def has_permission(self, request: Request, view: View) -> bool: token = validate_auth(get_authorization_header(request)) tenant_management_key = CONFIG.get("tenant_management_key") @@ -110,5 +112,5 @@ class SettingsView(RetrieveUpdateAPIView): def get_object(self): obj = get_tenant(self.request) - self.check_object_permissions(obj) + self.check_object_permissions(self.request, obj) return obj diff --git a/authentik/tenants/models.py b/authentik/tenants/models.py index a045ac7cb..fa6358ce5 100644 --- a/authentik/tenants/models.py +++ b/authentik/tenants/models.py @@ -3,6 +3,7 @@ from uuid import uuid4 from django.apps import apps from django.db import models +from django.db.utils import IntegrityError from django.dispatch import receiver from django.utils.translation import gettext_lazy as _ from django_tenants.models import DomainMixin, TenantMixin, post_schema_sync @@ -60,12 +61,12 @@ class Tenant(TenantMixin, SerializerModel): def save(self, *args, **kwargs): if self.schema_name == "template": - raise Exception("Cannot create schema named template") + raise IntegrityError("Cannot create schema named template") super().save(*args, **kwargs) def delete(self, *args, **kwargs): if self.schema_name in ("public", "template"): - raise Exception("Cannot delete schema public or template") + raise IntegrityError("Cannot delete schema public or template") super().delete(*args, **kwargs) @property @@ -83,6 +84,8 @@ class Tenant(TenantMixin, SerializerModel): class Domain(DomainMixin, SerializerModel): + """Tenant domain""" + def __str__(self) -> str: return f"Domain {self.domain}" @@ -99,6 +102,7 @@ class Domain(DomainMixin, SerializerModel): @receiver(post_schema_sync, sender=TenantMixin) def tenant_needs_sync(sender, tenant, **kwargs): + """Reconcile apps for a specific tenant on creation""" if tenant.ready: return diff --git a/authentik/tenants/scheduler.py b/authentik/tenants/scheduler.py index 02a2aabf6..b6189dfa5 100644 --- a/authentik/tenants/scheduler.py +++ b/authentik/tenants/scheduler.py @@ -1,9 +1,12 @@ +"""Tenant-aware Celery beat scheduler""" from tenant_schemas_celery.scheduler import ( TenantAwarePersistentScheduler as BaseTenantAwarePersistentScheduler, ) class TenantAwarePersistentScheduler(BaseTenantAwarePersistentScheduler): + """Tenant-aware Celery beat scheduler""" + @classmethod def get_queryset(cls): return super().get_queryset().filter(ready=True) diff --git a/authentik/tenants/utils.py b/authentik/tenants/utils.py index 776ef223a..49e453f29 100644 --- a/authentik/tenants/utils.py +++ b/authentik/tenants/utils.py @@ -1,3 +1,4 @@ +"""Tenant utils""" from django.db import connection from authentik.tenants.models import Tenant