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 +
|
Authenticated by the X-Admin-Token header. Returns every member (active +
|
||||||
inactive) with their balance, spend, remaining, and team reset date, plus
|
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)
|
_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)
|
logger.warning("admin overview: all-time spend query failed: %s", e)
|
||||||
|
|
||||||
members = []
|
members = []
|
||||||
|
guests = []
|
||||||
admins = []
|
admins = []
|
||||||
total_spend = 0.0
|
total_spend = 0.0
|
||||||
total_all_time = 0.0
|
total_all_time = 0.0
|
||||||
operator_spend = 0.0
|
operator_spend = 0.0
|
||||||
operator_all_time = 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:
|
for email, active, balance, user_id, org_slug, matrix_mxid, acct_type, oc_email, gift_exp in rows:
|
||||||
team = teams.get(f"member:{email}", {})
|
team = teams.get(f"member:{email}", {})
|
||||||
spend = float(team.get("spend") or 0.0)
|
spend = float(team.get("spend") or 0.0)
|
||||||
@@ -4284,6 +4290,15 @@ async def admin_overview(request: Request):
|
|||||||
total_all_time += member_all_time
|
total_all_time += member_all_time
|
||||||
operator_spend += spend
|
operator_spend += spend
|
||||||
operator_all_time += member_all_time
|
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:
|
else:
|
||||||
members.append(entry)
|
members.append(entry)
|
||||||
total_spend += spend
|
total_spend += spend
|
||||||
@@ -4316,11 +4331,18 @@ async def admin_overview(request: Request):
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
"members": members,
|
"members": members,
|
||||||
|
"guests": guests,
|
||||||
"admins": admins,
|
"admins": admins,
|
||||||
"agents": agents,
|
"agents": agents,
|
||||||
"totals": {
|
"totals": {
|
||||||
"members": len(members),
|
"members": len(members),
|
||||||
"active": sum(1 for m in members if m["active"]),
|
"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.
|
# total_spend spans members AND the co-op's own operator accounts.
|
||||||
# operator_spend is the breakout of that portion, so a consumer
|
# 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.
|
# never has to guess whether a figure includes the co-op's own use.
|
||||||
|
|||||||
Reference in new issue
Block a user