Fix user delete flow 4

This commit is contained in:
Urtzi Alfaro
2025-08-02 18:38:14 +02:00
parent eedbc2401e
commit 8d1b7c1efb
4 changed files with 7 additions and 53 deletions

View File

@@ -40,7 +40,7 @@ class AuthTenantServiceClient(BaseServiceClient):
async def get_user_tenants(self, user_id: str) -> Optional[List[Dict[str, Any]]]:
"""Get all tenant memberships for a user"""
try:
result = await self.get(f"tenants/memberships/{user_id}")
result = await self.get(f"tenants/user/{user_id}")
return result.get("memberships", []) if result else []
except Exception as e:
logger.error("Failed to get user tenants", user_id=user_id, error=str(e))

View File

@@ -73,31 +73,6 @@ async def verify_tenant_access(
detail="Access verification failed"
)
@router.get("/tenants/users/{user_id}", response_model=List[TenantResponse])
async def get_user_tenants(
user_id: str,
current_user: Dict[str, Any] = Depends(get_current_user_dep),
db: AsyncSession = Depends(get_db)
):
# Users can only see their own tenants
if current_user["user_id"] != user_id:
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="Access denied"
)
try:
tenants = await TenantService.get_user_tenants(user_id, db)
return tenants
except Exception as e:
logger.error(f"Failed to get user tenants: {e}")
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="Failed to retrieve tenants"
)
@router.get("/tenants/{tenant_id}", response_model=TenantResponse)
async def get_tenant(
tenant_id: UUID = Path(..., description="Tenant ID"),
@@ -313,7 +288,7 @@ async def delete_tenant_complete(
detail=f"Failed to delete tenant: {str(e)}"
)
@router.get("/tenants/memberships/{user_id}")
@router.get("/user/{user_id}")
async def get_user_tenants(
user_id: str,
current_user = Depends(get_current_user_dep),

View File

@@ -129,32 +129,6 @@ class TenantService:
permissions=[]
)
@staticmethod
async def get_user_tenants(user_id: str, db: AsyncSession) -> List[TenantResponse]:
"""Get all tenants accessible by user"""
try:
# Get user's tenant memberships
result = await db.execute(
select(Tenant)
.join(TenantMember, Tenant.id == TenantMember.tenant_id)
.where(
and_(
TenantMember.user_id == user_id,
TenantMember.is_active == True,
Tenant.is_active == True
)
)
.order_by(Tenant.name)
)
tenants = result.scalars().all()
return [TenantResponse.from_orm(tenant) for tenant in tenants]
except Exception as e:
logger.error(f"Error getting user tenants: {e}")
return []
@staticmethod
async def get_tenant_by_id(tenant_id: str, db: AsyncSession) -> Optional[TenantResponse]:
"""Get tenant by ID"""