* core: include all sentry headers Signed-off-by: Jens Langhammer <jens@goauthentik.io> * remove spotlight patch we dont need anymore Signed-off-by: Jens Langhammer <jens@goauthentik.io> * always trace in debug Signed-off-by: Jens Langhammer <jens@goauthentik.io> * init sentry earlier Signed-off-by: Jens Langhammer <jens@goauthentik.io> * re-add light interface https://github.com/goauthentik/authentik/pull/14331 removes 2 unneeded API calls Signed-off-by: Jens Langhammer <jens@goauthentik.io> * sentry integrated router Signed-off-by: Jens Langhammer <jens@goauthentik.io> * use new Sentry middleware to propagate headers Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix missing baggage Signed-off-by: Jens Langhammer <jens@goauthentik.io> * cleanup logs Signed-off-by: Jens Langhammer <jens@goauthentik.io> * use sanitized URLs for logging/tracing Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io>
41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
"""Brand utilities"""
|
|
|
|
from typing import Any
|
|
|
|
from django.db.models import F, Q
|
|
from django.db.models import Value as V
|
|
from django.http.request import HttpRequest
|
|
|
|
from authentik import get_full_version
|
|
from authentik.brands.models import Brand
|
|
from authentik.lib.sentry import get_http_meta
|
|
from authentik.tenants.models import Tenant
|
|
|
|
_q_default = Q(default=True)
|
|
DEFAULT_BRAND = Brand(domain="fallback")
|
|
|
|
|
|
def get_brand_for_request(request: HttpRequest) -> Brand:
|
|
"""Get brand object for current request"""
|
|
db_brands = (
|
|
Brand.objects.annotate(host_domain=V(request.get_host()))
|
|
.filter(Q(host_domain__iendswith=F("domain")) | _q_default)
|
|
.order_by("default")
|
|
)
|
|
brands = list(db_brands.all())
|
|
if len(brands) < 1:
|
|
return DEFAULT_BRAND
|
|
return brands[0]
|
|
|
|
|
|
def context_processor(request: HttpRequest) -> dict[str, Any]:
|
|
"""Context Processor that injects brand object into every template"""
|
|
brand = getattr(request, "brand", DEFAULT_BRAND)
|
|
tenant = getattr(request, "tenant", Tenant())
|
|
return {
|
|
"brand": brand,
|
|
"footer_links": tenant.footer_links,
|
|
"html_meta": {**get_http_meta()},
|
|
"version": get_full_version(),
|
|
}
|