Jun 28 - Update tenant self-service signup, trial period enforcement
This commit is contained in:
@@ -55,6 +55,8 @@ _UNKNOWN_TENANT_PAGE = (
|
||||
def _is_exempt(path):
|
||||
if path.startswith('/static/'):
|
||||
return True
|
||||
if path.startswith('/signup'):
|
||||
return True # public self-service signup has no tenant context
|
||||
for prefix in current_app.config.get('MULTI_TENANT_EXEMPT_PATHS', []):
|
||||
if prefix and path.startswith(prefix):
|
||||
return True
|
||||
@@ -146,17 +148,31 @@ def init_tenancy(app):
|
||||
or _is_exempt(request.path)):
|
||||
return
|
||||
|
||||
status = tenant.subscription_status
|
||||
status = tenant.subscription_status
|
||||
trial_ends_at = tenant.trial_ends_at
|
||||
|
||||
if status is None or status in ('trial', 'active'):
|
||||
# Fully authorised — no action needed.
|
||||
if status is None or status == 'active':
|
||||
return
|
||||
|
||||
if status == 'trial':
|
||||
if trial_ends_at is not None:
|
||||
from app.utils.time_utils import now_eastern
|
||||
now = now_eastern()
|
||||
if now >= trial_ends_at:
|
||||
# Trial expired — redirect to subscribe; allow /settings/ so
|
||||
# they can still see their plan page and the subscribe button.
|
||||
if not (request.path.startswith('/billing/')
|
||||
or request.path.startswith('/settings/')):
|
||||
return redirect(url_for('billing.subscribe'))
|
||||
else:
|
||||
days_left = (trial_ends_at - now).days
|
||||
if days_left <= 3:
|
||||
g.billing_warning = 'trial_ending'
|
||||
return
|
||||
|
||||
if status == 'past_due':
|
||||
# Allow access but signal the template to show the payment warning banner.
|
||||
g.billing_warning = 'past_due'
|
||||
return
|
||||
|
||||
# status == 'cancelled' (or any unrecognised future value)
|
||||
# Block access and redirect to the subscription management page.
|
||||
# status == 'cancelled' — block and redirect to subscription page.
|
||||
return redirect(url_for('billing.suspended'))
|
||||
|
||||
Reference in New Issue
Block a user