Files
westfarnandCursor 787f0e48fb Populate the client website template with catalog feature flags.
Extract always-on public/portal/UTM plus optional email_sms, directmail, blog, payments, social, and social_ai so new client sites can be bootstrapped from this seed.

Refs #1
Refs #2

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-26 07:55:26 -05:00

49 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",
"/robots.txt",
"/sitemap.xml",
)
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