Jun 27 MT-5

This commit is contained in:
2026-06-27 12:56:11 -04:00
parent 668cb645e2
commit 7505e82ab4
6 changed files with 344 additions and 10 deletions
+16
View File
@@ -11,6 +11,10 @@ Resolution rules:
* exact match on tenant_domains.domain (host, lowercased, port stripped)
* tenant must be status='active'
* custom domains must be verified; subdomains we issue are trusted
MT-5: plan fields are loaded in the same session and stored on TenantContext
so quota.py / gates.py can read them without a second control-DB query.
Returns a detached TenantContext or None.
"""
@@ -40,6 +44,8 @@ def resolve_tenant(host):
if tenant is None or tenant.status != 'active':
return None
plan = tenant.plan # relationship already loaded via joined session
# Materialise everything needed while the session is still open
# (db_uri decrypts the stored credential).
return TenantContext(
@@ -48,4 +54,14 @@ def resolve_tenant(host):
name=tenant.name,
plan_id=tenant.plan_id,
db_uri=tenant.db_uri,
# MT-5: plan fields
plan_code=plan.code if plan else None,
max_users=plan.max_users if plan else None,
max_facilities=plan.max_facilities if plan else None,
max_inspections_month=plan.max_inspections_month if plan else None,
max_issues_month=plan.max_issues_month if plan else None,
allow_mobile_api=plan.allow_mobile_api if plan else True,
allow_scheduled_reports=plan.allow_scheduled_reports if plan else True,
allow_branding=plan.allow_branding if plan else True,
allow_custom_domain=plan.allow_custom_domain if plan else True,
)