overview: guests are their own list, excluded from member counts
/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.
This commit is contained in:
1 parent
103766eb74
commit
c6eb2b44e8
1 file changed
+23
-1
+23
-1
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user