add org subs info to /api/users/emails endpoint (#2495)

Include additional info in this superadmin-only endpoint.
This commit is contained in:
Ilya Kreymer 2025-03-20 08:31:23 -07:00 committed by GitHub
parent b63caf74ad
commit cb14ac3a00
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 4 deletions

View File

@ -1833,6 +1833,16 @@ class SubscriptionCanceledResponse(BaseModel):
canceled: bool
# ============================================================================
class UserOrgInfoOutWithSubs(UserOrgInfoOut):
"""org per user with sub info"""
readOnly: bool
readOnlyReason: Optional[str] = None
subscription: Optional[Subscription] = None
# ============================================================================
# ORGS
# ============================================================================

View File

@ -6,7 +6,7 @@ import os
from uuid import UUID, uuid4
import asyncio
from typing import Optional, List, TYPE_CHECKING, cast, Callable, Tuple
from typing import Optional, List, TYPE_CHECKING, cast, Callable, Tuple, Type
from fastapi import (
Request,
@ -26,6 +26,7 @@ from .models import (
UserUpdatePassword,
User,
UserOrgInfoOut,
UserOrgInfoOutWithSubs,
UserOut,
UserRole,
InvitePending,
@ -164,7 +165,9 @@ class UserManager:
return user
async def get_user_info_with_orgs(self, user: User) -> UserOut:
async def get_user_info_with_orgs(
self, user: User, info_out_cls: Type[UserOrgInfoOut] = UserOrgInfoOut
) -> UserOut:
"""return User info"""
user_orgs, _ = await self.org_ops.get_orgs_for_user(
user,
@ -174,7 +177,7 @@ class UserManager:
if user_orgs:
orgs = [
UserOrgInfoOut(
info_out_cls(
id=org.id,
name=org.name,
slug=org.slug,
@ -184,6 +187,9 @@ class UserManager:
if user.is_superuser
else org.users.get(str(user.id))
),
readOnly=org.readOnly,
readOnlyReason=org.readOnlyReason,
subscription=org.subscription,
)
for org in user_orgs
]
@ -565,7 +571,7 @@ class UserManager:
{"is_superuser": False}, skip=skip, limit=page_size
):
user = User(**res)
user_out = await self.get_user_info_with_orgs(user)
user_out = await self.get_user_info_with_orgs(user, UserOrgInfoOutWithSubs)
emails.append(
UserEmailWithOrgInfo(email=user_out.email, orgs=user_out.orgs)
)