Guest cap $5 -> $2: GUEST_BUDGET default, emails, docs, tests
This commit is contained in:
1 parent
0f12c63f5e
commit
6be8e2d632
6 files changed
+45
-45
No files matched your search
+22
-22
@@ -336,18 +336,18 @@ OC_PERSONAL_TOKEN = os.environ.get("OC_PERSONAL_TOKEN", "")
|
||||
MEMBER_BUDGET = float(os.environ.get("MEMBER_BUDGET", "15.0"))
|
||||
|
||||
# --- Guest accounts (operator decisions, 2026-11-08) -------------------------- #
|
||||
# A member can give a friend access to the co-op with $5 of credits, no Open
|
||||
# A member can give a friend access to the co-op with $2 of credits, no Open
|
||||
# Collective membership required. The guest is a ONE-TIME non-expiring credit
|
||||
# balance held in the credits model (credit_balance), hard-capped by the
|
||||
# LiteLLM team budget. Two lapse triggers, both handled by the sweep:
|
||||
# * the $5 is spent (the cap enforces the limit; the sweep deactivates the
|
||||
# * the $2 is spent (the cap enforces the limit; the sweep deactivates the
|
||||
# row once spend reaches the credit balance), and
|
||||
# * GUEST_DAYS elapse from provisioning — a time box, even with credits left.
|
||||
# Deactivation is the same semantics as a member's: guests group → inactive,
|
||||
# team budget zeroed, row active=0, newsletter unsubscribed. The account is
|
||||
# KEPT so a returning payer resumes cleanly (and the guest→member conversion
|
||||
# still fires if their OC membership appears later).
|
||||
GUEST_BUDGET = float(os.environ.get("GUEST_BUDGET", "5.0"))
|
||||
GUEST_BUDGET = float(os.environ.get("GUEST_BUDGET", "2.0"))
|
||||
GUEST_DAYS = float(os.environ.get("GUEST_DAYS", "60"))
|
||||
# One guest per inviting member per rolling 30 days (abuse protection).
|
||||
GUEST_PER_INVITER_DAYS = float(os.environ.get("GUEST_PER_INVITER_DAYS", "30"))
|
||||
@@ -923,7 +923,7 @@ def get_db() -> sqlite3.Connection:
|
||||
if "loomio_invited_at" not in cols:
|
||||
conn.execute("ALTER TABLE members ADD COLUMN loomio_invited_at TEXT")
|
||||
# Migration: account_type — 'member' (default) or 'guest'. Guest accounts are
|
||||
# provisioned by /admin/provision-guest with $5 of non-expiring credit, live
|
||||
# provisioned by /admin/provision-guest with $2 of non-expiring credit, live
|
||||
# in the Cloudron "guests" group, and sit outside every membership
|
||||
# obligation: the sweep never deactivates one for lacking an OC
|
||||
# contribution, they are invited to no Loomio/Matrix rooms, and they lapse
|
||||
@@ -1579,7 +1579,7 @@ async def get_active_member_emails() -> list[str]:
|
||||
The local `members` table is the authoritative source of member emails
|
||||
(populated during provisioning). Used for the Loomio sync and the Matrix
|
||||
invite pass. GUEST accounts are excluded: they are not members — they hold
|
||||
$5 credits, live in the Cloudron guests group, and must never be invited
|
||||
$2 credits, live in the Cloudron guests group, and must never be invited
|
||||
to Loomio, Matrix or (via these lists) any member service.
|
||||
"""
|
||||
conn = get_db()
|
||||
@@ -2529,7 +2529,7 @@ async def provision_member(email: str, name: str, slug: str = "") -> str:
|
||||
|
||||
|
||||
# --- Guest accounts (operator feature, 2026-11-08) --------------------------- #
|
||||
# A member gives a friend access with $5 of credits: Cloudron user in the
|
||||
# A member gives a friend access with $2 of credits: Cloudron user in the
|
||||
# guests group (chat + dashboard only), a one-time LiteLLM budget with NO
|
||||
# monthly reset, the portal row marked account_type='guest', the guest welcome
|
||||
# email, and the newsletter subscription. NO Loomio/Matrix invites. See the
|
||||
@@ -2539,7 +2539,7 @@ def guest_invitation_email(name: str, setup_url: str, inviter_name: str = "") ->
|
||||
"""Build the guest INVITATION email — the one email a guest sends.
|
||||
|
||||
This is the guest-time email AND the guest welcome in one: the recipient is
|
||||
invited in (the inviter named), told what the guest gives ($5 of credits,
|
||||
invited in (the inviter named), told what the guest gives ($2 of credits,
|
||||
how long access runs), and given the account-setup link. The guest welcome
|
||||
content lives here rather than in a second email — one coherent invitation,
|
||||
not two mails at once. Same branded shell as welcome_email(): cream
|
||||
@@ -2565,7 +2565,7 @@ def guest_invitation_email(name: str, setup_url: str, inviter_name: str = "") ->
|
||||
f"{greet}\n\n"
|
||||
f"{invited_line}.\n\n"
|
||||
"It's a member-governed AI cooperative that runs open models.\n\n"
|
||||
"Your invitation comes with $5 of credits for the co-op's chat and\n"
|
||||
"Your invitation comes with $2 of credits for the co-op's chat and\n"
|
||||
f"API. Access runs for {int(GUEST_DAYS)} days from today; the credits\n"
|
||||
"themselves don't expire early.\n\n"
|
||||
"To accept, create your account — it takes about a minute:\n\n"
|
||||
@@ -2596,7 +2596,7 @@ def guest_invitation_email(name: str, setup_url: str, inviter_name: str = "") ->
|
||||
<td align="center" style="background:#ffffff;border:1px solid #e8e2d8;border-radius:16px;padding:40px 32px;">
|
||||
<h1 style="margin:0 0 12px;font-size:24px;font-weight:700;color:#2d3327;">{h1}</h1>
|
||||
<p style="margin:0 0 8px;font-size:16px;color:#6b7a62;line-height:1.5;">{html_invited} — a member-governed AI cooperative running open models.</p>
|
||||
<p style="margin:0 0 24px;font-size:15px;color:#6b7a62;line-height:1.5;">Your invitation comes with <strong style="color:#2d3327;">$5 of credits</strong> for the co-op's chat and API. Access runs for {int(GUEST_DAYS)} days from today; the credits themselves don't expire early.</p>
|
||||
<p style="margin:0 0 24px;font-size:15px;color:#6b7a62;line-height:1.5;">Your invitation comes with <strong style="color:#2d3327;">$2 of credits</strong> for the co-op's chat and API. Access runs for {int(GUEST_DAYS)} days from today; the credits themselves don't expire early.</p>
|
||||
<a href="{setup_url}" style="display:inline-block;background:#5b8c5a;color:#ffffff;text-decoration:none;padding:14px 36px;border-radius:10px;font-size:16px;font-weight:600;">Create your account</a>
|
||||
<p style="margin:14px 0 28px;font-size:13px;color:#94a08c;line-height:1.5;">This takes about a minute.</p>
|
||||
<p style="margin:0 0 10px;font-size:15px;color:#2d3327;line-height:1.5;"><strong>If you like it, become a member.</strong></p>
|
||||
@@ -2675,7 +2675,7 @@ def guest_member_congrats_email(name: str, setup_url: str | None) -> tuple[str,
|
||||
def guest_limits_email(name: str, reason: str) -> tuple[str, str, str]:
|
||||
"""Build the reaching-limits email for a guest account hitting its limit.
|
||||
|
||||
Sent ONCE per guest when the sweep deactivates the guest — either the $5
|
||||
Sent ONCE per guest when the sweep deactivates the guest — either the $2
|
||||
of credits are spent or the GUEST_DAYS time box has run out. Says plainly:
|
||||
the guest access has ended, the account and data are kept, and becoming a
|
||||
member ($15/month via Open Collective) restores access with a full
|
||||
@@ -2734,14 +2734,14 @@ async def provision_guest_member(
|
||||
) -> str:
|
||||
"""Provision a GUEST account end-to-end (operator guest access feature).
|
||||
|
||||
A guest gives a friend $5 of credits with no Open Collective membership:
|
||||
A guest gives a friend $2 of credits with no Open Collective membership:
|
||||
* Cloudron user in the GUESTS group (chat + dashboard only — the two
|
||||
apps' access restrictions list both groups);
|
||||
* a LiteLLM team hard-capped at GUEST_BUDGET with NO monthly reset
|
||||
(budget_duration None — the cap is the guest's whole life);
|
||||
* the portal row marked account_type='guest' with the $5 held as
|
||||
* the portal row marked account_type='guest' with the $2 held as
|
||||
non-expiring credit (the credits model) and guest_expires_at set;
|
||||
* the guest INVITATION email (inviter named, the $5 credits, the
|
||||
* the guest INVITATION email (inviter named, the $2 credits, the
|
||||
setup link — the invitation and the guest welcome in one) and the
|
||||
newsletter subscription;
|
||||
* a guests-ledger row recording inviter → recipient;
|
||||
@@ -2768,7 +2768,7 @@ async def provision_guest_member(
|
||||
await cloudron_set_group(user_id, GUESTS_GROUP_ID)
|
||||
await cloudron_set_active(user_id, True)
|
||||
|
||||
# One-time $5 team: budget_duration None means LiteLLM never resets it.
|
||||
# One-time $2 team: budget_duration None means LiteLLM never resets it.
|
||||
team_id = await litellm_get_or_create_team(email, GUEST_BUDGET, budget_duration=None)
|
||||
key_token = get_stored_key(email)
|
||||
if not key_token:
|
||||
@@ -2781,9 +2781,9 @@ async def provision_guest_member(
|
||||
guest_ref = f"guest:{email}"
|
||||
if not credit_reference_exists(guest_ref):
|
||||
add_credits(email, GUEST_BUDGET,
|
||||
reason="guest account — $5 credit from a member",
|
||||
reason="guest account — $2 credit from a member",
|
||||
reference=guest_ref)
|
||||
# Guest rows hold NO allowance (balance 0 — the $5 is all credit) and
|
||||
# Guest rows hold NO allowance (balance 0 — the $2 is all credit) and
|
||||
# anchor their join day at the guest date (kept if they later convert).
|
||||
conn = get_db()
|
||||
conn.execute(
|
||||
@@ -2849,7 +2849,7 @@ async def convert_guest_to_member(email: str, name: str, slug: str = "") -> str:
|
||||
What converts:
|
||||
* the Cloudron user moves guests → members (regaining Loomio/Matrix
|
||||
eligibility through the normal syncs);
|
||||
* the LiteLLM cap lifts from the $5 guest to the member allowance +
|
||||
* the LiteLLM cap lifts from the $2 guest to the member allowance +
|
||||
credits — any UNSPENT guest credit stays (it already lives in the
|
||||
non-expiring credit_balance bucket);
|
||||
* the portal row becomes account_type='member' with the standard
|
||||
@@ -3279,7 +3279,7 @@ async def litellm_get_or_create_team(email: str, budget: float,
|
||||
spend draws from the one pool.
|
||||
|
||||
`budget_duration` is the reset cadence: members renew every 30 days; GUEST
|
||||
accounts pass None — a one-time budget that NEVER resets, so the $5 cap is
|
||||
accounts pass None — a one-time budget that NEVER resets, so the $2 cap is
|
||||
the guest's whole life (spend it and it is gone).
|
||||
|
||||
Idempotent: looks up the existing team by alias before creating. Note that
|
||||
@@ -4221,7 +4221,7 @@ async def admin_provision_guest(request: Request):
|
||||
(ADMIN_INVITER_EMAIL, default info@inference.coop) — the panel has no
|
||||
inviter input, and the ledger records the admin account.
|
||||
|
||||
Runs the guest pipeline: Cloudron user in the guests group, a $5 LiteLLM
|
||||
Runs the guest pipeline: Cloudron user in the guests group, a $2 LiteLLM
|
||||
team with NO monthly reset, the portal row marked as a guest with a
|
||||
GUEST_DAYS expiry, the guest welcome email, the newsletter subscription,
|
||||
and a guests-ledger row recording inviter → recipient. Admin invites
|
||||
@@ -4375,7 +4375,7 @@ async def admin_guest_request_approve(request_id: int, request: Request):
|
||||
"""Approve a pending guest request — the trial gate's approval action.
|
||||
|
||||
Approval fires the FULL guest pipeline (provision_guest_member: Cloudron
|
||||
user, $5 credit, GUEST_DAYS box, invitation email naming the inviter,
|
||||
user, $2 credit, GUEST_DAYS box, invitation email naming the inviter,
|
||||
newsletter subscribe, ledger row) — the same path the operator's
|
||||
/admin/provision-guest runs, so every guard re-runs. If state moved since
|
||||
the request (the recipient signed up; another invitation landed), the
|
||||
@@ -6250,7 +6250,7 @@ async def broker_guest_invite(request: Request):
|
||||
pending request, or a MANUAL_MEMBERS address. The guest itself is
|
||||
provisioned ONLY through provision_guest_member — the same pipeline the
|
||||
operator's /admin/provision-guest runs (Cloudron user in the guests
|
||||
group, $5 non-expiring credit, GUEST_DAYS time box, invitation email
|
||||
group, $2 non-expiring credit, GUEST_DAYS time box, invitation email
|
||||
naming the inviter, newsletter subscribe, ledger row).
|
||||
|
||||
Trial gate: with GUEST_AUTO_APPROVE off (the default) the request waits
|
||||
@@ -7047,7 +7047,7 @@ async def reconcile_allowances(send: bool = False) -> dict:
|
||||
welcome_sent = row[6] if len(row) > 6 else None
|
||||
|
||||
if acct_type == "guest":
|
||||
# Guest accounts have no OC membership by design — the $5 credit
|
||||
# Guest accounts have no OC membership by design — the $2 credit
|
||||
# balance and the GUEST_DAYS time box govern them instead. No
|
||||
# renewal decision, no reminder, ever.
|
||||
counts["skipped"] += 1
|
||||
|
||||
Reference in new issue
Block a user