Guest state: the overview payload carries the definitive display state
Single derivation point (tested once, here): 'invited' while the Cloudron invite is unaccepted, else the guests-ledger status (the record of record), membership state only as a no-ledger-row fallback. The panel and dashboard become pure consumers of `state` — their local invited/active derivation goes away in their own repos next. Live-behaviour note: today's four live guests render byte-identically; the change only shows for ended guests (ledger 'expired' instead of the bare inactive flag), which is what the panel already displayed via its own guest_status preference.
This commit is contained in:
1 parent
62a59477c6
commit
58214be0db
2 files changed
+44
-5
No files matched your search
+14
-1
@@ -4787,7 +4787,9 @@ async def admin_overview(request: Request):
|
||||
# until acceptance flips it. Display/state semantics only: access
|
||||
# rules, the $2 cap and the expiry box are unchanged (an unaccepted
|
||||
# guest cannot reach anything anyway — the setup link is the only
|
||||
# door in).
|
||||
# door in). This override is half of the SINGLE guest-state
|
||||
# derivation (see the guest_status block below for the other half);
|
||||
# the panel and dashboard consume `state` and derive nothing.
|
||||
sent = (guest_info.get(email) or {}).get("sent")
|
||||
mstate = "invited"
|
||||
mstate_reason = (f"awaiting setup — invite sent {str(sent)[:10]}, "
|
||||
@@ -4821,6 +4823,17 @@ async def admin_overview(request: Request):
|
||||
gi = guest_info.get(email) or {}
|
||||
entry["guest_inviter"] = gi.get("inviter")
|
||||
entry["guest_status"] = gi.get("status")
|
||||
# The other half of the SINGLE guest-state derivation (portal =
|
||||
# source of truth; tested once in tests/test_guest_invited_state.py,
|
||||
# consumed as-is by the panel and dashboard). Once the invite is
|
||||
# accepted the guests-ledger status IS the display state — the
|
||||
# record of record (active / converted / expired / depleted /
|
||||
# cancelled by recipient) — so an ended guest reads its ledger
|
||||
# status, not the bare active/inactive membership flag. A guest
|
||||
# with no ledger row keeps the membership state as the fallback.
|
||||
if entry["state"] != "invited" and gi.get("status"):
|
||||
entry["state"] = gi["status"]
|
||||
entry["state_reason"] = ""
|
||||
if email.lower() in OPERATOR_EMAILS:
|
||||
# Operator accounts: surfaced under a separate "admin" category in
|
||||
# the panel, excluded from member counts and aggregates (their
|
||||
|
||||
@@ -17,8 +17,11 @@ WHY THIS EXISTS
|
||||
1. guest_invite_pending — the derivation itself: accepted, username-set,
|
||||
unseen-record (fetch failed) and no-user-id cases.
|
||||
2. GET /admin/overview: a fresh guest (inviteAccepted=false, no
|
||||
username) reports state='invited' with an 'awaiting setup' reason;
|
||||
the guests ledger status stays the record of record.
|
||||
username) reports state='invited' with an 'awaiting setup' reason.
|
||||
Once accepted, state FOLLOWS THE LEDGER STATUS (active / expired /
|
||||
...) — the single derivation point for the guest display state,
|
||||
consumed as-is by the panel and dashboard; a guest with no ledger
|
||||
row falls back to the membership state.
|
||||
3. Simulated acceptance (inviteAccepted flips true, or a username is
|
||||
chosen) → the same endpoint reports state='active'.
|
||||
4. A FAILED Cloudron users fetch never claims 'invited' — the row falls
|
||||
@@ -205,8 +208,31 @@ def main():
|
||||
check("overview: activated flag agrees (pending)",
|
||||
g.get("activated") is False, str(g.get("activated")))
|
||||
ended = [x for x in data["guests"] if x["email"] == "ended@x.org"][0]
|
||||
check("overview: an inactive guest still reads inactive (not invited)",
|
||||
ended["state"] == "inactive", str(ended.get("state")))
|
||||
check("overview: ended guest reads its LEDGER status ('expired'), not the bare flag",
|
||||
ended["state"] == "expired" and ended["state_reason"] == "",
|
||||
f"{ended.get('state')} / {ended.get('state_reason')!r}")
|
||||
|
||||
# The ledger is the record of record even when it disagrees with the
|
||||
# members.active flag: an active-flagged guest whose access has ENDED
|
||||
# (expired ledger row, active flag not yet flipped) reads 'expired'.
|
||||
conn = m.get_db()
|
||||
CLOUDRON_USERS["uid-lapsed@x.org"] = {"inviteAccepted": True, "username": "lapsedg"}
|
||||
seed_account(conn, "lapsed@x.org", account_type="guest", active=1,
|
||||
uid="uid-lapsed@x.org")
|
||||
seed_guest_ledger(conn, inviter, "lapsed@x.org", status="expired")
|
||||
# ...and a guest with NO ledger row falls back to the membership state.
|
||||
CLOUDRON_USERS["uid-noledger@x.org"] = {"inviteAccepted": True, "username": "noledger"}
|
||||
seed_account(conn, "noledger@x.org", account_type="guest", active=1,
|
||||
uid="uid-noledger@x.org")
|
||||
conn.commit()
|
||||
conn.close()
|
||||
data = asyncio.run(overview())
|
||||
lapsed = [x for x in data["guests"] if x["email"] == "lapsed@x.org"][0]
|
||||
check("overview: ledger status wins over the active flag (lapsed guest = 'expired')",
|
||||
lapsed["state"] == "expired", str(lapsed.get("state")))
|
||||
noledger = [x for x in data["guests"] if x["email"] == "noledger@x.org"][0]
|
||||
check("overview: no ledger row → membership-state fallback ('active')",
|
||||
noledger["state"] == "active", str(noledger.get("state")))
|
||||
|
||||
# --- 3. simulated acceptance: the flip to active ---------------------------
|
||||
CLOUDRON_USERS["uid-guest@x.org"]["inviteAccepted"] = True
|
||||
|
||||
Reference in new issue
Block a user