From 6a0e02ff959306bb6d467a9fe179a268287336e8 Mon Sep 17 00:00:00 2001 From: Urtzi Alfaro Date: Wed, 17 Dec 2025 15:58:28 +0100 Subject: [PATCH] Fix Demo enterprise: map 'demo-user' to actual owner ID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the frontend requests tenants with user_id='demo-user' in demo mode, the backend now correctly maps this to the actual demo owner ID from the current_user context (set by the gateway middleware). This fixes the issue where the tenant list API was returning empty results even though it returned 200 OK, because it was looking for a user with id='demo-user' which doesn't exist in the database. The actual user IDs are: - Professional: c1a2b3c4-d5e6-47a8-b9c0-d1e2f3a4b5c6 (María García López) - Enterprise: d2e3f4a5-b6c7-48d9-e0f1-a2b3c4d5e6f7 (Director) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- services/tenant/app/api/tenants.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/services/tenant/app/api/tenants.py b/services/tenant/app/api/tenants.py index cfa1b0e7..0598be5b 100644 --- a/services/tenant/app/api/tenants.py +++ b/services/tenant/app/api/tenants.py @@ -152,17 +152,32 @@ async def get_user_tenants( logger.info( "Get user tenants request received", user_id=user_id, - requesting_user=current_user.get("user_id") + requesting_user=current_user.get("user_id"), + is_demo=current_user.get("is_demo", False) ) - if current_user.get("user_id") != user_id and current_user.get("type") != "service": + # Allow demo users to access tenant information for demo-user + is_demo_user = current_user.get("is_demo", False) + is_service_account = current_user.get("type") == "service" + + # For demo sessions, when frontend requests with "demo-user", use the actual demo owner ID + actual_user_id = user_id + if is_demo_user and user_id == "demo-user": + actual_user_id = current_user.get("user_id") + logger.info( + "Demo session: mapping demo-user to actual owner", + requested_user_id=user_id, + actual_user_id=actual_user_id + ) + + if current_user.get("user_id") != actual_user_id and not is_service_account and not (is_demo_user and user_id == "demo-user"): raise HTTPException( status_code=status.HTTP_403_FORBIDDEN, detail="Can only access own tenants" ) try: - tenants = await tenant_service.get_user_tenants(user_id) + tenants = await tenant_service.get_user_tenants(actual_user_id) logger.debug( "Get user tenants successful",