feat(billing): let a super admin give a workspace a paid plan without payment
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 15/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- next.js, react, supabase, typescript
- Ambito
- backend-api-design
Direzione di ricerca
Start with the dependencies #80 and #81 and the stated decision from Eddie; the billing tables, plan configuration, and design choice are prerequisites. Then read src/lib/auth/super-admin.ts, src/app/super-admin/page.tsx, src/proxy.ts, and docs/architecture/schema.md. Done means the selected design meets the acceptance criteria, including grant and revoke behavior, entitlement resolution, audit logging, and end to end coverage.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Context
Eddie wants to move a free account onto a full paid plan without the user paying: early users, friends of the project, contributors, support recoveries, press. Today there is nothing to promote to, so this issue records the requirement and the design choice now, before checkout and webhooks are built around an assumption that a paid plan always has a paying subscription behind it.
What the code says today:
- No plan, subscription, or entitlement exists anywhere in
src/orsupabase/migrations/. The billing tables are still to come in #80, whose scope already lists "Entitlement overrides". Plans as configuration are #81, checkout is #82, webhooks and the nightly reconcile are #83. - Billing is per workspace, not per user:
docs/architecture/schema.md:412("Plan and entitlement columns attach toworkspacesor a new table keyed byworkspace_id; nothing is keyed on the user"). So "promote an account" here means "give a workspace a paid plan". A user with several workspaces is promoted one workspace at a time. - The only elevated role is the super admin:
src/lib/auth/super-admin.ts, an email list inSTACKDASH_SUPER_ADMIN_EMAILS, withrequireSuperAdminas the one check and/app/admin(rewritten tosrc/app/super-admin/page.tsxbysrc/proxy.ts, #374) as the one surface. There is no database role. - #92 plans a read-only admin view of customers and plans. This issue adds the one write it does not cover.
- #98 plans coupons and trials for paying customers. A 100% coupon is one way to do this (option C below), which is why the choice is recorded here rather than folded into #98.
- The direction review (#141, item 3) proposed freezing billing and plans work until there is a launch signal. This issue sits behind that freeze with the rest of #73.
Decision
Decided 2026-11-17: option B, chosen by Eddie. The reasons are in the decision comment on this issue. The options are kept below as they were presented, for the record.
| Option | Pros | Cons | Effort | Impact |
|---|---|---|---|---|
| A. Status quo: no promotion feature; edit the plan by hand in SQL when needed | No code. Nothing to build until #80 exists | No audit of who promoted whom, against "Admin views and data exports are logged". If #83's reconcile derives the plan from provider subscriptions, it silently reverts a hand edit the next night, the exact trap the house rules call out. Needs service role access to production for every promotion | XS | The promoted user loses paid features the night after the edit, with no record of why or who granted them. No money at risk |
B. App-side complimentary grant: a workspace_plan_grants row (plan, reason, granted by, optional expiry) that the entitlement resolver treats like an active subscription; a super admin grants and revokes it from /app/admin |
Provider agnostic, so it works whatever #76 decides and on a self-hosted install with billing on. Reconcile in #83 only writes subscription rows, so it cannot undo a grant. No fake customer or $0 invoice at the provider, and no user email sent to the provider for someone who never pays. Expiry is a stored deadline the resolver reads, so no job has to end it | A second source of entitlement: every plan check must go through one resolver, never read the subscription directly. Grants do not show in the provider's dashboard or MRR, so the admin view (#92) has to list them. Needs its own audit trail | M on top of #80 and #81 | If the resolver is bypassed somewhere, that surface treats a promoted workspace as free until fixed. If revoke fails, a workspace keeps paid features it should not: cost is hosting, not money taken from anyone |
| C. Provider-side 100% discount: create a real subscription at the billing provider with a 100% coupon, so the promoted workspace looks like any other subscriber | One code path: entitlements come only from subscriptions. Shows in the provider dashboard | Blocked on #76 (provider), #82 (checkout), #83 (webhooks), and #98 (coupons). Creates a provider customer record and sends the user's email to the provider for someone who never pays, against data minimization. $0 invoices, and tax handling depends on the provider choice. Repeated for each provider if #97 adds a second | S on top of #76, #82, #83, #98 (M, M, S, plus the decision) | Promotion is impossible until four other issues ship. A coupon misconfigured as less than 100% charges a user who was promised free access: money at risk |
Files each option touches:
| Option | Files and objects |
|---|---|
| A | None; a SQL statement run by hand against production |
| B | New migration for workspace_plan_grants; the entitlement resolver from #80/#81 (src/lib/billing/ or wherever #81 puts it); a Server Action beside src/app/super-admin/page.tsx; a grant panel in the admin page; docs/architecture/schema.md; e2e spec |
| C | The provider client from #82; the coupon setup from #98; a super admin action that calls the provider; webhook handling in #83 for the comped subscription |
Recommendation: B. The deciding argument: it is the only option that survives the nightly reconcile in #83 without special casing, and it does not wait on the provider decision (#76). Second choice: A, as a stopgap only if a promotion is needed before #80 lands, with the reason written on the workspace's issue. C ranks last because it puts real money paths and a provider customer record behind what is meant to be free.
Plan
Written for option B, as decided.
- Migration:
workspace_plan_grantskeyed byworkspace_id(cascade on workspace delete), withplan(the plan id from #81's config, enforced as a database enum or a check against the same literal union),reason(required text),granted_by(auth.usersid),created_at timestamptz default now(),expires_at timestamptz null,revoked_at timestamptz null,revoked_by. At most one unrevoked grant per workspace (partial unique index). RLS: no policy forauthenticated; only the service role writes, behind the super admin check. - Entitlement resolver (from #81): a workspace's effective plan is the higher of its active subscription plan and its active grant (
revoked_at is null and (expires_at is null or expires_at > now())). Every plan and limit check goes through it. A grant never writes to subscription rows, and #83's reconcile never reads or writes grants. - Super admin Server Actions
grantWorkspacePlanandrevokeWorkspacePlan. Each callsrequireSuperAdminitself (a Server Action is a public endpoint; the proxy rewrite is not authorization), validates input with a strict zod schema, takes the workspace by handle or id, and re-reads the workspace on the server. A missing workspace and a refused caller get the same response. - Audit: every grant and revoke logs
admin.plan_granted/admin.plan_revokedwith the super admin's user id, workspace id, plan, and expiry; never an email. The grant row itself is the durable record. - UI on
/app/admin: find a workspace, show its effective plan and where it comes from (subscription, grant, or free), grant with a plan, a reason, and an optional end date, and revoke. Hidden when billing is disabled, as in a self-hosted install without billing. - Workspace billing settings (#87): a promoted workspace sees its plan as "Complimentary" with the end date if there is one, and no payment prompt.
- Expiry and stacking: when a grant ends, the workspace falls back to its subscription or to free with no job and no data loss beyond plan limits. A promoted workspace that later subscribes keeps the higher plan of the two; revoking the grant leaves the paid subscription untouched.
Acceptance criteria
- A super admin can give a free workspace any paid plan from
/app/adminwith a reason and an optional end date, and the workspace gets that plan's entitlements on its next request without any payment - A super admin can revoke the grant, and the workspace returns to its subscription plan or to free
- A grant with an end date in the past grants nothing, with no scheduled job involved
- Running the #83 reconcile against a promoted workspace leaves the grant and the effective plan unchanged
- A non super admin calling either Server Action directly gets the same refusal as for a missing workspace, and nothing changes
- Every grant and revoke is logged with who did it, to which workspace, and when, with no email or other personal data in the log line
- The workspace's billing settings say the plan is complimentary and show the end date when set
- Deleting a workspace removes its grants; deleting an account (#42) leaves no orphaned grant
- Admin controls pass an axe scan and a keyboard-only pass
- Playwright e2e covers grant, effective plan, and revoke as a super admin, and refusal as a member
Files and areas
In scope: the grant migration, the entitlement resolver, the super admin page and its actions, the billing settings page's plan line, docs/architecture/schema.md, and e2e.
Non-goals:
- Discounts, partial comps, coupons, and trials for paying customers: #98.
- Creating anything at the billing provider.
- Self-service promotion codes a user enters.
- Per-user plans. Billing stays per workspace (
docs/architecture/schema.md:412). - A new admin role. The super admin email list stays the only elevated capability.
Verification
npm run testfor the resolver: subscription only, grant only, both, expired grant, revoked grant.supabase migration upon the local stack, thennpm run test:dbfor theworkspace_plan_grantsRLS: no access asauthenticated, writes as the service role.npm run test:e2efor the spec above, plus the accessibility check on/app/admin.
Depends on
- #80 (billing tables, which already lists entitlement overrides)
- #81 (plans as configuration, which gives the plan ids)
Branch: <issue-number>-complimentary-workspace-plan
Closes with a Closes #<issue-number> footer on the commit or pull request.
Model: anthropic/claude-opus-5-5 | Reasoning effort: not reported by harness
- Lingua principale
- TypeScript
- Stelle
- 13
- Fork
- 2
- Merge medio
- 5h 20m
- PR unite (30g)
- 287
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di eddiejaoude/StackDash
-
area: integrations documentation priority: P2 size: XS
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
eddiejaoude/StackDash#798 ·
I maintainer di solito rispondono entro 1 giorno
-
area: ops documentation priority: P3 size: XS
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
eddiejaoude/StackDash#796 ·
I maintainer di solito rispondono entro 1 giorno
-
area: docs documentation impact: low priority: P3 size: XS
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
eddiejaoude/StackDash#790 ·
I maintainer di solito rispondono entro 1 giorno
-
area: ops bug impact: low priority: P3 size: XS
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
eddiejaoude/StackDash#785 ·
I maintainer di solito rispondono entro 1 giorno
-
area: connections enhancement impact: low priority: P3 size: XS
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
eddiejaoude/StackDash#768 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di eddiejaoude/StackDash
Issue simili
-
bot:ai-assisted component:midnight-js status:untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
midnightntwrk/midnight-js#1790 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
area:vscode bug has repro platform:macos platform:vscode regression
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
anthropics/claude-code#113502 ·
-
Add: Rajdhani TV HDApertacheck:passed streams:add
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 77/100
I maintainer di solito rispondono entro 1 giorno
-
effort/l priority/p1 risk/high triage/core
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
iflytek/skillhub#1188 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno