fix tests

Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
This commit is contained in:
Marc 'risson' Schmitt 2023-11-21 17:44:23 +01:00
parent b6efa3bde3
commit d492c48657
No known key found for this signature in database
GPG Key ID: 9C3FA22FABF1AA8D
3 changed files with 24 additions and 3 deletions

View File

@ -67,7 +67,6 @@ SHARED_APPS = [
TENANT_APPS = [
"django.contrib.auth",
"django.contrib.sessions",
"authentik.tenants",
"authentik.admin",
"authentik.api",
"authentik.crypto",

View File

@ -1,10 +1,28 @@
"""authentik tenants app"""
from django.apps import AppConfig
from django.db import DEFAULT_DB_ALIAS
from django.db.models.signals import post_migrate
from authentik.blueprints.apps import ManagedAppConfig
class AuthentikTenantsConfig(AppConfig):
def reconcile_default_tenant(using=DEFAULT_DB_ALIAS, *args, **kwargs):
"""Make sure default tenant exists"""
from authentik.tenants.models import Tenant
Tenant.objects.using(using).update_or_create(
defaults={"name": "Default", "ready": True},
schema_name="public",
)
class AuthentikTenantsConfig(ManagedAppConfig):
"""authentik tenants app"""
name = "authentik.tenants"
label = "authentik_tenants"
verbose_name = "authentik Tenants"
default = True
def reconcile_default_tenant(self):
reconcile_default_tenant()
post_migrate.connect(reconcile_default_tenant)

View File

@ -86,6 +86,10 @@ class Tenant(TenantMixin, SerializerModel):
class Domain(DomainMixin, SerializerModel):
"""Tenant domain"""
tenant = models.ForeignKey(
Tenant, db_index=True, related_name="domains", on_delete=models.CASCADE
)
def __str__(self) -> str:
return f"Domain {self.domain}"