Rename gift to guest throughout: routes, ledger table, account_type values, env names, emails, tests

Pure rename, no behaviour change, matching the renamed panel and dashboard
builds. Includes one-time idempotent migrations for existing databases
(gifts->guests table, gift_expires_at->guest_expires_at column,
account_type 'gift'->'guest' values, gift_lapse_notices->guest_lapse_notices)
and four transitional alias routes (admin/provision-gift, admin/gift-convert,
broker/gift-status, broker/cancel-gift) so pre-rename dashboard/panel builds
keep working until they are redeployed.
This commit is contained in:
inference-bot committed 2026-11-08 02:41:05 +00:00
1 parent 8af8e39c0b
commit 27f9cc06b2
5 files changed
+493 -447

No files matched your search

+30 -30
View File
@@ -50,64 +50,64 @@ LibreChat ──→ Member Portal ──→ LiteLLM ──→ backend
| `ALLOWANCE_POLICY` | `report` (default) \| `on`. `report` computes every allowance decision and changes nothing; `on` performs renewals and sends the one reminder. Deactivation is gated separately by `ALLOWANCE_DEACTIVATE`. |
| `ALLOWANCE_DEACTIVATE` | `off` (default) \| `on`. When `on`, a member who was reminded and is still unpaid after the grace window is moved to the inactive group. **Defaults off so renewals/reminders can run before anyone loses access.** |
| `PAYMENT_GRACE_DAYS` | Days after the single reminder before an unpaid member is deactivated (default `7`). |
| `GIFT_BUDGET` | Gift-account credit in USD (default `5.0`). |
| `GIFT_DAYS` | Gift-account time box in days from provisioning (default `60`). The sweep deactivates an expired gift even with credits left. |
| `GIFT_PER_INVITER_DAYS` | Rolling window for the one-gift-per-inviter limit (default `30`). |
| `GUESTS_GROUP_ID` | Cloudron group ID for gift accounts. The chat and dashboard apps' access restrictions list BOTH the members and guests groups, so a guest reaches exactly those two apps. |
| `GUEST_BUDGET` | Guest-account credit in USD (default `5.0`). |
| `GUEST_DAYS` | Guest-account time box in days from provisioning (default `60`). The sweep deactivates an expired guest even with credits left. |
| `GUEST_PER_INVITER_DAYS` | Rolling window for the one-guest-per-inviter limit (default `30`). |
| `GUESTS_GROUP_ID` | Cloudron group ID for guest accounts. The chat and dashboard apps' access restrictions list BOTH the members and guests groups, so a guest reaches exactly those two apps. |
| `GUESTS_ENDED_GROUP_ID` | Cloudron group a SELF-CANCELLED guest's user lands in: out of guests (chat access ends) but still admitted by the dashboard app, so the ended state and Become-a-member stay visible. Unset → the shared inactive group (dashboard access ends too). |
## Gift accounts
## Guest accounts
A member can give a friend access to the co-op with $5 of credits — no Open
Collective membership required. `POST /admin/provision-gift` (X-Admin-Token)
with `{"email", "name", "inviter": "<the gifting member's email>"}` runs the
gift pipeline: Cloudron user in the **guests** group, a LiteLLM team capped at
`GIFT_BUDGET` with **no monthly reset** (the cap is the gift's whole life), the
portal row marked `account_type='gift'` with the $5 held as non-expiring
credit, `gift_expires_at` set to now + `GIFT_DAYS`, the gift welcome email
Collective membership required. `POST /admin/provision-guest` (X-Admin-Token)
with `{"email", "name", "inviter": "<the guest access member's email>"}` runs the
guest pipeline: Cloudron user in the **guests** group, a LiteLLM team capped at
`GUEST_BUDGET` with **no monthly reset** (the cap is the guest's whole life), the
portal row marked `account_type='guest'` with the $5 held as non-expiring
credit, `guest_expires_at` set to now + `GUEST_DAYS`, the guest welcome email
(setup link, what they can use, Become-a-member, newsletter note), and a
**gifts ledger** row (`gifts` table: inviter → recipient, expiry, status) for
the abuse audit. Guards: one gift per inviter per `GIFT_PER_INVITER_DAYS`; one
gift per recipient ever; the inviter must be an active member; an existing
**guests ledger** row (`guests` table: inviter → recipient, expiry, status) for
the abuse audit. Guards: one guest per inviter per `GUEST_PER_INVITER_DAYS`; one
guest per recipient ever; the inviter must be an active member; an existing
portal row under the recipient address is refused. Guests are subscribed to
the newsletter and invited to NOTHING else (no Loomio, no Matrix).
**Sweep safety.** `reconcile_memberships()` never deactivates a gift for
lacking an OC contribution. A gift lapses only by its own rules, handled by
`reconcile_gift_lifecycles()` inside the sweep: credits spent out (LiteLLM's
cap enforces the limit; the sweep retires the row) or the `GIFT_DAYS` time box.
**Sweep safety.** `reconcile_memberships()` never deactivates a guest for
lacking an OC contribution. A guest lapses only by its own rules, handled by
`reconcile_guest_lifecycles()` inside the sweep: credits spent out (LiteLLM's
cap enforces the limit; the sweep retires the row) or the `GUEST_DAYS` time box.
Deactivation is the same semantics as a member's — guests group → inactive,
budget zeroed, row `active=0`, newsletter unsubscribed — and the account is
KEPT so a returning payer resumes cleanly.
**Self-service cancellation (recipient-initiated).** `POST /broker/cancel-gift`
(dashboard broker identity) ends a gift at the recipient's own request:
deactivation with the same kept-account semantics, the newsletter
**Self-service cancellation (recipient-initiated).** `POST /broker/cancel-guest`
(dashboard broker identity) ends a guest account at the recipient's own
request: deactivation with the same kept-account semantics, the newsletter
unsubscribed, and — the part a lapse does not do — any UNSPENT credit
returned to the co-op as a negative `credit_ledger` row whose reason names
the cancellation and the original gift reference (`gift-return:<email>` is
the cancellation and the original guest reference (`guest-return:<email>` is
the dedupe reference, so a repeat cancel can never double-return). The
gifts-ledger row records the full trail: inviter → recipient → 'cancelled
guests-ledger row records the full trail: inviter → recipient → 'cancelled
by recipient'. The Cloudron user leaves the guests group for
`GUESTS_ENDED_GROUP_ID` — chat and API access end, while the dashboard app
(which lists that group in its access restriction) still admits them, so
`GET /broker/gift-status` can show the ended state: access ended, data
`GET /broker/guest-status` can show the ended state: access ended, data
kept, Become-a-member still one contribution away. A paying member calling
either route gets a 403 — cancelling a membership means ending the Open
Collective contribution, and this endpoint is deliberately gift-only.
Collective contribution, and this endpoint is deliberately guest-only.
**Guest → member conversion (automatic).** When a gift's OC identity appears as
**Guest → member conversion (automatic).** When a guest's OC identity appears as
a live BACKER/ADMIN with the account's own email — via the webhook or the
nightly sweep — `provision_member()` routes the call to
`convert_gift_to_member()`: the Cloudron user moves guests → members, the
LiteLLM cap lifts to the member allowance + credits (unspent gift credit is
`convert_guest_to_member()`: the Cloudron user moves guests → members, the
LiteLLM cap lifts to the member allowance + credits (unspent guest credit is
carried — it already lives in `credit_balance`), the row becomes a normal
member with the standard `MEMBER_BUDGET`, the anchor day (the gift's start
member with the standard `MEMBER_BUDGET`, the anchor day (the guest's start
date) is kept and the reset pinned to it, the congratulations email goes out,
and the normal member onboarding runs (newsletter, Loomio + Matrix syncs,
docs-RAG group, held-credit grants). When the contribution arrives under a
DIFFERENT OC email it cannot auto-match: the operator links it with
`POST /admin/gift-convert` `{"email": "<gift account>", "oc_email": "<the OC
`POST /admin/guest-convert` `{"email": "<guest account>", "oc_email": "<the OC
email the contribution is under>"}` — the row records `members.oc_email`, and
the sweep and webhook treat that address as an additional matcher from then on.