snapshot: preserve trial lifecycle and product-grade expiry UX
This commit is contained in:
34
backend/workflows/middleware.py
Normal file
34
backend/workflows/middleware.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
from .branding import is_trial_expired, is_trial_mode_enabled
|
||||
from .roles import ROLE_PLATFORM_OWNER, get_user_role_key
|
||||
|
||||
|
||||
class TrialModeMiddleware:
|
||||
EXEMPT_PREFIXES = (
|
||||
'/healthz/',
|
||||
'/i18n/',
|
||||
'/accounts/login/',
|
||||
'/accounts/logout/',
|
||||
'/accounts/password_reset/',
|
||||
'/accounts/reset/',
|
||||
'/static/',
|
||||
'/media/',
|
||||
)
|
||||
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
def __call__(self, request):
|
||||
if not is_trial_mode_enabled() or not is_trial_expired():
|
||||
return self.get_response(request)
|
||||
|
||||
path = request.path or '/'
|
||||
if any(path.startswith(prefix) for prefix in self.EXEMPT_PREFIXES):
|
||||
return self.get_response(request)
|
||||
|
||||
user = getattr(request, 'user', None)
|
||||
if getattr(user, 'is_authenticated', False) and get_user_role_key(user) == ROLE_PLATFORM_OWNER:
|
||||
return self.get_response(request)
|
||||
|
||||
return render(request, 'workflows/trial_expired.html', status=403)
|
||||
Reference in New Issue
Block a user