vergabe-teilnahme/vergabe_teilnahme/apps/accounts/middleware.py
tegwick 9345a1bb1a
All checks were successful
Application acceptance / application-tests (push) Successful in 1m12s
CI Smoke / host-smoke (push) Successful in 0s
CI Smoke / container-smoke (push) Successful in 1s
Build and Publish Container Image / build-and-push (push) Successful in 25s
feat: serve isolated companies below a fixed product path
Assistant: codex
Assistant-Model: gpt-6-astra
Assistant-Session: 01a07ff8-19d0-7820-b4d0-1353833cb7fc
2026-09-11 21:29:26 +02:00

22 lines
1 KiB
Python

from django.contrib.auth.middleware import LoginRequiredMiddleware
from django.contrib.auth.views import redirect_to_login
from django.http import HttpResponse
from django.urls import reverse
from django.utils.cache import add_never_cache_headers
class PilotLoginRequiredMiddleware(LoginRequiredMiddleware):
"""Use Django's default-deny gate, including full-page HTMX reauthentication."""
def handle_no_permission(self, request, view_func):
if request.headers.get('HX-Request') == 'true':
# The original URL may render only a fragment or accept only POST.
login = redirect_to_login(reverse('home'), self.get_login_url(view_func))
return HttpResponse(status=401, headers={'HX-Redirect': login.url})
return super().handle_no_permission(request, view_func)
def process_response(self, request, response):
# Company records and account pages must not survive in shared caches.
if request.path_info != '/health/':
add_never_cache_headers(response)
return response