Unignore site/ (was blocked by mkdocs /site rule), add compose/Docker/uv tooling, and split deploys so push to main goes to beta while prod stays manual.
47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
from django.conf import settings
|
|
from django.shortcuts import redirect
|
|
|
|
|
|
class UnderConstructionMiddleware:
|
|
"""
|
|
When SITE_UNDER_CONSTRUCTION is true, redirect public traffic to the holding page.
|
|
|
|
Exempt: health, static/media, admin, auth login/logout, SMS webhook, and the
|
|
under-construction page itself (so notify-me POSTs work).
|
|
"""
|
|
|
|
EXEMPT_PREFIXES = (
|
|
"/healthz",
|
|
"/static/",
|
|
"/media/",
|
|
"/admin/",
|
|
"/accounts/login",
|
|
"/accounts/logout",
|
|
"/under-construction",
|
|
"/portal/messaging/webhooks/",
|
|
"/unsubscribe/",
|
|
"/api/address-suggest",
|
|
)
|
|
|
|
def __init__(self, get_response):
|
|
self.get_response = get_response
|
|
|
|
def __call__(self, request):
|
|
if settings.SITE_UNDER_CONSTRUCTION and not self._is_exempt(request):
|
|
return redirect("public:under_construction")
|
|
return self.get_response(request)
|
|
|
|
def _is_exempt(self, request) -> bool:
|
|
path = request.path
|
|
if any(path.startswith(prefix) for prefix in self.EXEMPT_PREFIXES):
|
|
return True
|
|
user = getattr(request, "user", None)
|
|
if (
|
|
user is not None
|
|
and getattr(user, "is_authenticated", False)
|
|
and getattr(user, "is_staff", False)
|
|
and path.startswith("/portal/")
|
|
):
|
|
return True
|
|
return False
|