gift accounts: $5 guest passes with time box, inviter ledger, auto member conversion

Operator feature: a member gives a friend access with $5 of credits, no OC
membership. Cloudron user lands in the guests group (chat + dashboard only),
LiteLLM team capped at GIFT_BUDGET with NO monthly reset, portal row marked
account_type='gift' with gift_expires_at set, gift welcome email, newsletter
subscription, and a gifts ledger recording inviter -> recipient (one gift per
inviter per 30 days, one per recipient ever).

Sweep safety: reconcile_memberships never deactivates a gift for lacking an
OC contribution; reconcile_gift_lifecycles lapses gifts by their own rules
(credits spent out, or the GIFT_DAYS time box) with member-deactivation
semantics. Guests are excluded from Loomio/Matrix invite lists, the reinvite
path, budget notices, the allowance reconciliation and the metrics member
counts.

Conversion: a gift whose OC identity appears under its own email converts
automatically (webhook + sweep + /admin/provision all funnel through
provision_member): group guests->members, cap lifted to allowance + carried
credits, anchor day kept, congrats email, full member onboarding.
/admin/gift-convert links a membership paid under a different OC email
(members.oc_email, matched by the sweep and webhook).

Fixture test: tests/test_gift_lifecycle.py (37 checks, network replaced by
a raising guard).
This commit is contained in:
inference-bot committed 2026-11-08 02:05:37 +00:00
1 parent 73d8c61aa7
commit 6d9074eefe
4 files changed
+1159 -32

No files matched your search

+10 -2
View File
@@ -207,13 +207,21 @@ def from_sqlite() -> dict:
"""Members, plus the provisioning dates that give the growth curve.
Operator/utility accounts are excluded, matching the panel's member count.
GIFT accounts are excluded too: they are $5 guest passes, not members —
counting them would move the growth curve the co-op publishes.
"""
conn = connect()
try:
rows = conn.execute("SELECT email, active, welcome_sent_at FROM members").fetchall()
cols = {r[1] for r in conn.execute("PRAGMA table_info(members)").fetchall()}
sel = "SELECT email, active, welcome_sent_at" + (
", account_type" if "account_type" in cols else "") + " FROM members"
has_acct = "account_type" in cols
rows = conn.execute(sel).fetchall()
finally:
conn.close()
real = [r for r in rows if (r[0] or "").strip().lower() not in OPERATOR_EMAILS]
real = [r for r in rows
if (r[0] or "").strip().lower() not in OPERATOR_EMAILS
and not (has_acct and len(r) > 3 and (r[3] or "") == "gift")]
return {
"active": sum(1 for r in real if r[1]),
"total": len(real),