Fix user delete flow 4
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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"""
|
||||
|
||||
Reference in New Issue
Block a user