From c6eb2b44e858fecb1496c425266b89c23b533b8a Mon Sep 17 00:00:00 2001 From: Inferencebot Date: Sun, 8 Nov 2026 02:09:28 +0000 Subject: [PATCH] overview: guests are their own list, excluded from member counts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /admin/overview now returns gift (guest) accounts in a separate guests[] list instead of inside members[], and excludes them from totals.members, totals.active and the member spend totals. Guests get their own totals breakout (guests, guests_active, guest_spend, guest_all_time_spend) so their spend stays visible without ever reading as member activity — the same reasoning as the operator (admins) and agent categories. Builds on the gift feature's account_type marker: a guest is any row with account_type='gift'. The panel reads guests[] and ignores gift rows in its member count either way. --- app/main.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index a613a10..2c60c7c 100644 --- a/app/main.py +++ b/app/main.py @@ -4143,7 +4143,10 @@ async def admin_overview(request: Request): Authenticated by the X-Admin-Token header. Returns every member (active + inactive) with their balance, spend, remaining, and team reset date, plus - co-op aggregates (total members, total spend). + co-op aggregates (total members, total spend). Guest (gift) accounts come + back in their own `guests` list — never inside `members` — so no consumer + can count them as members by accident; their spend is broken out in the + totals rather than folded into the member figures. """ _verify_admin_token(request) @@ -4224,11 +4227,14 @@ async def admin_overview(request: Request): logger.warning("admin overview: all-time spend query failed: %s", e) members = [] + guests = [] admins = [] total_spend = 0.0 total_all_time = 0.0 operator_spend = 0.0 operator_all_time = 0.0 + guest_spend = 0.0 + guest_all_time = 0.0 for email, active, balance, user_id, org_slug, matrix_mxid, acct_type, oc_email, gift_exp in rows: team = teams.get(f"member:{email}", {}) spend = float(team.get("spend") or 0.0) @@ -4284,6 +4290,15 @@ async def admin_overview(request: Request): total_all_time += member_all_time operator_spend += spend operator_all_time += member_all_time + elif (acct_type or "member") == "gift": + # Guest (gift) accounts: their own list, never members. Excluded + # from the member count AND from the spend totals a reader reads + # as member activity — a gift is not a membership. Their spend is + # broken out separately in the totals so it stays visible (the + # same reasoning as the agents below). + guests.append(entry) + guest_spend += spend + guest_all_time += member_all_time else: members.append(entry) total_spend += spend @@ -4316,11 +4331,18 @@ async def admin_overview(request: Request): return { "members": members, + "guests": guests, "admins": admins, "agents": agents, "totals": { "members": len(members), "active": sum(1 for m in members if m["active"]), + # Guests are never members: their own count + spend breakout, so a + # consumer never has to guess whether a figure includes them. + "guests": len(guests), + "guests_active": sum(1 for g in guests if g["active"]), + "guest_spend": round(guest_spend, 2), + "guest_all_time_spend": round(guest_all_time, 2), # total_spend spans members AND the co-op's own operator accounts. # operator_spend is the breakout of that portion, so a consumer # never has to guess whether a figure includes the co-op's own use.