tenants: migrate context_processor to tenants

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-05-29 18:01:48 +02:00
parent ff611f21cd
commit 14f85ec980
7 changed files with 13 additions and 16 deletions

View File

@ -3,7 +3,7 @@
{% load static %}
{% block title %}
API Browser - {{ config.authentik.branding.title }}
API Browser - {{ tenant.branding_title }}
{% endblock %}
{% block head %}

View File

@ -26,10 +26,7 @@
<div class="ak-login-container">
<header class="pf-c-login__header">
<div class="pf-c-brand ak-brand">
<img src="{{ config.authentik.branding.logo }}" alt="authentik icon" />
{% if config.authentik.branding.title_show %}
<p>{{ config.authentik.branding.title }}</p>
{% endif %}
<img src="{{ tenant.branding_logo }}" alt="authentik icon" />
</div>
</header>
{% block main_container %}

View File

@ -10,9 +10,6 @@ from urllib.parse import urlparse
import yaml
from django.conf import ImproperlyConfigured
from django.http import HttpRequest
from authentik import __version__
SEARCH_PATHS = ["authentik/lib/default.yml", "/etc/authentik/config.yml", ""] + glob(
"/etc/authentik/config.d/*.yml", recursive=True
@ -21,11 +18,6 @@ ENV_PREFIX = "AUTHENTIK"
ENVIRONMENT = os.getenv(f"{ENV_PREFIX}_ENV", "local")
def context_processor(request: HttpRequest) -> dict[str, Any]:
"""Context Processor that injects config object into every template"""
return {"config": CONFIG.raw, "ak_version": __version__}
class ConfigLoader:
"""Search through SEARCH_PATHS and load configuration. Environment variables starting with
`ENV_PREFIX` are also applied.

View File

@ -4,7 +4,7 @@
{% load i18n %}
{% block title %}
{% trans 'Permission denied' %} - {{ config.authentik.branding.title }}
{% trans 'Permission denied' %} - {{ tenant.branding_title }}
{% endblock %}
{% block card_title %}

View File

@ -14,7 +14,7 @@
{% endblock %}
{% block title %}
{% trans 'End session' %} - {{ config.authentik.branding.title }}
{% trans 'End session' %} - {{ tenant.branding_title }}
{% endblock %}
{% block card_title %}

View File

@ -233,7 +233,7 @@ TEMPLATES = [
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"authentik.lib.config.context_processor",
"authentik.tenants.utils.context_processor",
],
},
},

View File

@ -1,7 +1,10 @@
"""Tenant utilities"""
from typing import Any
from django.db.models import Q
from django.http.request import HttpRequest
from authentik import __version__
from authentik.tenants.models import Tenant
_q_default = Q(default=True)
@ -15,3 +18,8 @@ def get_tenant_for_request(request: HttpRequest) -> Tenant:
if not db_tenants.exists():
return Tenant()
return db_tenants.first()
def context_processor(request: HttpRequest) -> dict[str, Any]:
"""Context Processor that injects tenant object into every template"""
return {"tenant": request.tenant, "ak_version": __version__}