Improve demo tennat and user get

This commit is contained in:
Urtzi Alfaro
2026-01-17 09:19:42 +01:00
parent 4b65817b3e
commit fbc670ddb3
9 changed files with 225 additions and 88 deletions

View File

@@ -212,17 +212,18 @@ async def create_demo_session(
# Add error handling for the task to prevent silent failures
task.add_done_callback(lambda t: _handle_task_result(t, session.session_id))
# Get complete demo account data from config (includes user, tenant, subscription info)
subscription_tier = demo_config.get("subscription_tier", "professional")
user_data = demo_config.get("user", {})
tenant_data = demo_config.get("tenant", {})
# Generate session token with subscription data
# Map demo_account_type to subscription tier
subscription_tier = "enterprise" if session.demo_account_type == "enterprise" else "professional"
session_token = jwt.encode(
{
"session_id": session.session_id,
"virtual_tenant_id": str(session.virtual_tenant_id),
"demo_account_type": request.demo_account_type,
"exp": session.expires_at.timestamp(),
# NEW: Subscription context (same structure as user JWT)
"tenant_id": str(session.virtual_tenant_id),
"subscription": {
"tier": subscription_tier,
@@ -235,14 +236,7 @@ async def create_demo_session(
algorithm=settings.JWT_ALGORITHM
)
# Map demo_account_type to subscription tier
subscription_tier = "enterprise" if session.demo_account_type == "enterprise" else "professional"
tenant_name = (
"Panadería Artesana España - Central"
if session.demo_account_type == "enterprise"
else "Panadería Artesana Madrid - Demo"
)
# Build complete response like a real login would return
return {
"session_id": session.session_id,
"virtual_tenant_id": str(session.virtual_tenant_id),
@@ -254,7 +248,29 @@ async def create_demo_session(
"session_token": session_token,
"subscription_tier": subscription_tier,
"is_enterprise": session.demo_account_type == "enterprise",
"tenant_name": tenant_name
# Complete user data (like a real login response)
"user": {
"id": user_data.get("id"),
"email": user_data.get("email"),
"full_name": user_data.get("full_name"),
"role": user_data.get("role", "owner"),
"is_active": user_data.get("is_active", True),
"is_verified": user_data.get("is_verified", True),
"tenant_id": str(session.virtual_tenant_id),
"created_at": session.created_at.isoformat()
},
# Complete tenant data
"tenant": {
"id": str(session.virtual_tenant_id),
"name": demo_config.get("name"),
"subdomain": demo_config.get("subdomain"),
"subscription_tier": subscription_tier,
"tenant_type": demo_config.get("tenant_type", "standalone"),
"business_type": tenant_data.get("business_type"),
"business_model": tenant_data.get("business_model"),
"description": tenant_data.get("description"),
"is_active": True
}
}
except Exception as e:

View File

@@ -16,8 +16,33 @@ class DemoSessionCreate(BaseModel):
user_agent: Optional[str] = None
class DemoUser(BaseModel):
"""Demo user data returned in session response"""
id: str
email: str
full_name: str
role: str
is_active: bool
is_verified: bool
tenant_id: str
created_at: str
class DemoTenant(BaseModel):
"""Demo tenant data returned in session response"""
id: str
name: str
subdomain: str
subscription_tier: str
tenant_type: str
business_type: Optional[str] = None
business_model: Optional[str] = None
description: Optional[str] = None
is_active: bool
class DemoSessionResponse(BaseModel):
"""Demo session response"""
"""Demo session response - mirrors a real login response with user and tenant data"""
session_id: str
virtual_tenant_id: str
demo_account_type: str
@@ -26,6 +51,11 @@ class DemoSessionResponse(BaseModel):
expires_at: datetime
demo_config: Dict[str, Any]
session_token: str
subscription_tier: str
is_enterprise: bool
# Complete user and tenant data (like a real login response)
user: DemoUser
tenant: DemoTenant
class Config:
from_attributes = True