Fix Demo enterprise

This commit is contained in:
Urtzi Alfaro
2025-12-17 13:03:52 +01:00
parent 0bbfa010bf
commit 8bfe4f2dd7
111 changed files with 26200 additions and 2245 deletions

View File

@@ -533,7 +533,7 @@ async def clone_demo_data(
}
@router.post("/create-child")
@router.post("/internal/demo/create-child")
async def create_child_outlet(
request: dict,
db: AsyncSession = Depends(get_db),
@@ -596,6 +596,23 @@ async def create_child_outlet(
}
}
# Get parent tenant to retrieve the correct owner_id
parent_result = await db.execute(select(Tenant).where(Tenant.id == parent_uuid))
parent_tenant = parent_result.scalars().first()
if not parent_tenant:
logger.error("Parent tenant not found", parent_tenant_id=parent_tenant_id)
return {
"service": "tenant",
"status": "failed",
"records_created": 0,
"duration_ms": int((datetime.now(timezone.utc) - start_time).total_seconds() * 1000),
"error": f"Parent tenant {parent_tenant_id} not found"
}
# Use the parent's owner_id for the child tenant (enterprise demo owner)
parent_owner_id = parent_tenant.owner_id
# Create child tenant with parent relationship
child_tenant = Tenant(
id=virtual_uuid,
@@ -615,9 +632,9 @@ async def create_child_outlet(
tenant_type="child",
hierarchy_path=f"{str(parent_uuid)}.{str(virtual_uuid)}",
# Owner ID - using demo owner ID from parent
# In real implementation, this would be the same owner as the parent tenant
owner_id=uuid.UUID("c1a2b3c4-d5e6-47a8-b9c0-d1e2f3a4b5c6") # Demo owner ID
# Owner ID - MUST match the parent tenant owner (enterprise demo owner)
# This ensures the parent owner can see and access child tenants
owner_id=parent_owner_id
)
db.add(child_tenant)
@@ -685,17 +702,17 @@ async def create_child_outlet(
# Create basic tenant members like parent
import json
# Demo owner is the same as central_baker/enterprise_chain owner (not individual_bakery)
demo_owner_uuid = uuid.UUID("d2e3f4a5-b6c7-48d9-e0f1-a2b3c4d5e6f7")
# Use the parent's owner_id (already retrieved above)
# This ensures consistency between tenant.owner_id and TenantMember records
# Create tenant member for owner
child_owner_member = TenantMember(
tenant_id=virtual_uuid,
user_id=demo_owner_uuid,
user_id=parent_owner_id,
role="owner",
permissions=json.dumps(["read", "write", "admin", "delete"]),
is_active=True,
invited_by=demo_owner_uuid,
invited_by=parent_owner_id,
invited_at=datetime.now(timezone.utc),
joined_at=datetime.now(timezone.utc),
created_at=datetime.now(timezone.utc)
@@ -744,6 +761,7 @@ async def create_child_outlet(
virtual_tenant_id=str(virtual_tenant_id),
parent_tenant_id=str(parent_tenant_id),
child_name=child_name,
owner_id=str(parent_owner_id),
duration_ms=duration_ms
)