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
@@ -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