Improve demo tennat and user get
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -35,6 +35,7 @@ class Settings(BaseServiceSettings):
|
||||
DEMO_SESSION_CLEANUP_INTERVAL_MINUTES: int = 60
|
||||
|
||||
# Demo account credentials (public)
|
||||
# Contains complete user, tenant, and subscription data matching fixture files
|
||||
DEMO_ACCOUNTS: dict = {
|
||||
"professional": {
|
||||
"email": "demo.professional@panaderiaartesana.com",
|
||||
@@ -42,7 +43,22 @@ class Settings(BaseServiceSettings):
|
||||
"subdomain": "demo-artesana",
|
||||
"base_tenant_id": "a1b2c3d4-e5f6-47a8-b9c0-d1e2f3a4b5c6",
|
||||
"subscription_tier": "professional",
|
||||
"tenant_type": "standalone"
|
||||
"tenant_type": "standalone",
|
||||
# User data from fixtures/professional/01-tenant.json
|
||||
"user": {
|
||||
"id": "c1a2b3c4-d5e6-47a8-b9c0-d1e2f3a4b5c6",
|
||||
"email": "maria.garcia@panaderiaartesana.com",
|
||||
"full_name": "María García López",
|
||||
"role": "owner",
|
||||
"is_active": True,
|
||||
"is_verified": True
|
||||
},
|
||||
# Tenant data
|
||||
"tenant": {
|
||||
"business_type": "bakery",
|
||||
"business_model": "production_retail",
|
||||
"description": "Professional tier demo tenant for bakery operations"
|
||||
}
|
||||
},
|
||||
"enterprise": {
|
||||
"email": "central@panaderiaartesana.es",
|
||||
@@ -51,6 +67,21 @@ class Settings(BaseServiceSettings):
|
||||
"base_tenant_id": "80000000-0000-4000-a000-000000000001",
|
||||
"subscription_tier": "enterprise",
|
||||
"tenant_type": "parent",
|
||||
# User data from fixtures/enterprise/parent/01-tenant.json
|
||||
"user": {
|
||||
"id": "d2e3f4a5-b6c7-48d9-e0f1-a2b3c4d5e6f7",
|
||||
"email": "director@panaderiaartesana.es",
|
||||
"full_name": "Director",
|
||||
"role": "owner",
|
||||
"is_active": True,
|
||||
"is_verified": True
|
||||
},
|
||||
# Tenant data
|
||||
"tenant": {
|
||||
"business_type": "bakery_chain",
|
||||
"business_model": "multi_location",
|
||||
"description": "Central production facility and parent tenant for multi-location bakery chain"
|
||||
},
|
||||
"children": [
|
||||
{
|
||||
"name": "Madrid - Salamanca",
|
||||
|
||||
Reference in New Issue
Block a user