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",