Improve the frontend 2

This commit is contained in:
Urtzi Alfaro
2025-10-29 06:58:05 +01:00
parent 858d985c92
commit 36217a2729
98 changed files with 6652 additions and 4230 deletions

View File

@@ -224,7 +224,7 @@ class SubscriptionMiddleware(BaseHTTPMiddleware):
allowed_tiers: List[str]
) -> Dict[str, Any]:
"""
Validate subscription tier access using tenant service
Validate subscription tier access using cached subscription lookup
Args:
request: FastAPI request
@@ -250,27 +250,27 @@ class SubscriptionMiddleware(BaseHTTPMiddleware):
headers["x-user-full-name"] = str(user.get('full_name', ''))
headers["x-tenant-id"] = str(user.get('tenant_id', ''))
# Call tenant service to get subscription tier with gateway-appropriate timeout
# Call tenant service fast tier endpoint with caching
timeout_config = httpx.Timeout(
connect=2.0, # Connection timeout - short for gateway
read=10.0, # Read timeout
write=2.0, # Write timeout
pool=2.0 # Pool timeout
connect=1.0, # Connection timeout - very short for cached endpoint
read=5.0, # Read timeout - short for cached lookup
write=1.0, # Write timeout
pool=1.0 # Pool timeout
)
async with httpx.AsyncClient(timeout=timeout_config) as client:
# Get tenant subscription information
tenant_response = await client.get(
f"{settings.TENANT_SERVICE_URL}/api/v1/tenants/{tenant_id}",
# Use fast cached tier endpoint
tier_response = await client.get(
f"{settings.TENANT_SERVICE_URL}/api/v1/subscriptions/{tenant_id}/tier",
headers=headers
)
if tenant_response.status_code != 200:
if tier_response.status_code != 200:
logger.warning(
"Failed to get tenant subscription",
"Failed to get subscription tier from cache",
tenant_id=tenant_id,
status_code=tenant_response.status_code,
response_text=tenant_response.text
status_code=tier_response.status_code,
response_text=tier_response.text
)
# Fail open for availability
return {
@@ -279,14 +279,15 @@ class SubscriptionMiddleware(BaseHTTPMiddleware):
'current_tier': 'unknown'
}
tenant_data = tenant_response.json()
current_tier = tenant_data.get('subscription_tier', 'starter').lower()
tier_data = tier_response.json()
current_tier = tier_data.get('tier', 'starter').lower()
logger.debug("Subscription tier check",
logger.debug("Subscription tier check (cached)",
tenant_id=tenant_id,
current_tier=current_tier,
minimum_tier=minimum_tier,
allowed_tiers=allowed_tiers)
allowed_tiers=allowed_tiers,
cached=tier_data.get('cached', False))
# Check if current tier is in allowed tiers
if current_tier not in [tier.lower() for tier in allowed_tiers]: