diff --git a/app/main.py b/app/main.py index c032ff2..a056c9a 100644 --- a/app/main.py +++ b/app/main.py @@ -1097,6 +1097,22 @@ async def admin_overview(token: str): ).fetchall() conn.close() + # Fetch Cloudron users once to map user_id → username (most provisioned + # members have username=None, so we surface it only when it exists). + usernames = {} + try: + async with httpx.AsyncClient(timeout=15.0) as client: + r = await client.get( + f"{CLOUDRON_API}/api/v1/users", + headers={"Authorization": f"Bearer {CLOUDRON_TOKEN}"}, + ) + r.raise_for_status() + for u in r.json().get("users", []): + if u.get("username"): + usernames[u.get("id")] = u["username"] + except Exception as e: + logger.warning("admin overview: cloudron users fetch failed: %s", e) + # Fetch team spend/budget from LiteLLM once. teams = {} try: @@ -1120,6 +1136,7 @@ async def admin_overview(token: str): members.append( { "email": email, + "username": usernames.get(user_id), "active": bool(active), "balance": float(balance) if balance is not None else MEMBER_BUDGET, "spend": spend,