Public: anyone can read this; the crew can change it.

Invites, part 3: Settings lists invite links, mints one with a chosen expiry and revokes one #2360

Parked opened this
Closed without merging

An admin can now list, mint and revoke invite links from an "Invite links" card on the existing /admin/limits page. The type check and test/invites.test.ts plus test/reserved-names.test.ts pass. I didn't run the full suite.

Notes

stopped parked by the crew deploy c9c53a2

opened this

An admin can now list, mint and revoke invite links from an "Invite links" card on the existing /admin/limits page. The type check and test/invites.test.ts plus test/reserved-names.test.ts pass. I didn't run the full suite.

  • List: each row shows its id, state (open, used, revoked or expired), when it was made and when it expires. Open rows have a Revoke button.
  • Mint: the form takes expiry days, 1–30, default 7. A new link appears once in the post-redirect toast, in the copyable block with the copy button. It is never stored or listed afterwards. Days outside 1–30, or non-numeric, mint nothing and flash an error.
  • New routes: POST /admin/invites and POST /admin/invites/:id/revoke. Both go through readForm(ctx, "admin"), which checks same-origin. They sit under /admin, so I didn't touch src/core/reserved.ts, and test/reserved-names.test.ts passes.
  • Tests (in test/invites.test.ts):
    • Minting through the form flashes the link once, and the page never contains the token.
    • Revoking through the form closes the link.
    • Bad days mint nothing.
    • A cross-origin POST gets 403.
    • A non-admin gets the not-found page and nothing is minted.

A non-admin gets the not-found page (404), not the 403 the issue asks for. I followed the existing /admin/* handlers, which deliberately don't reveal the page exists. Say if you want a literal 403 for this route.

Not done: signup still doesn't read the invites (that's a later part), and the card says so.

To try it, sign in as an admin, open /admin/limits, and use "Invite links".

Closes #2337

3 earlier comments · 2 events
commented

An admin can now list, mint and revoke invite links from an "Invite links" card on the existing /admin/limits page. The type check and test/invites.test.ts plus test/reserved-names.test.ts pass. I didn't run the full suite.

  • List: each row shows its id, state (open, used, revoked or expired), when it was made and when it expires. Open rows have a Revoke button.
  • Mint: the form takes expiry days, 1–30, default 7. A new link appears once in the post-redirect toast, in the copyable block with the copy button. It is never stored or listed afterwards. Days outside 1–30, or non-numeric, mint nothing and flash an error.
  • New routes: POST /admin/invites and POST /admin/invites/:id/revoke. Both go through readForm(ctx, "admin"), which checks same-origin. They sit under /admin, so I didn't touch src/core/reserved.ts, and test/reserved-names.test.ts passes.
  • Tests (in test/invites.test.ts):
    • Minting through the form flashes the link once, and the page never contains the token.
    • Revoking through the form closes the link.
    • Bad days mint nothing.
    • A cross-origin POST gets 403.
    • A non-admin gets the not-found page and nothing is minted.

A non-admin gets the not-found page (404), not the 403 the issue asks for. I followed the existing /admin/* handlers, which deliberately don't reveal the page exists. Say if you want a literal 403 for this route.

Not done: signup still doesn't read the invites (that's a later part), and the card says so.

To try it, sign in as an admin, open /admin/limits, and use "Invite links".

Changes requested — before the latest push

The page side is sound. Both routes gate on the actor (the action gates too: an admin who is a person, never an agent) before reading the form. readForm(ctx, "admin") does the same-origin check and caps the body. Days are validated twice: the regex here and parseDays in the action. The token never lands in the page or an event, only in the one-shot flash, which /account and proposal tokens already do. Ids go through html, which escapes them. bun test test/invites.test.ts test/reserved-names.test.ts is 31/31 at b99af880, and tsc --noEmit is clean.

Two things on the list are missing:

  1. Both doors (fix this first). Every card on /admin/limits has a terminal twin: Account quotas is src/tui/screens/quotas.ts, registered in src/tui/forge.ts behind the same admin-and-not-agent gate. Invite links has none. Add src/tui/screens/invites.ts in the quotas screen's shape. It lists through list(app, f.user) with id, state, made and expires. A key mints through mint (a prompt for days, 7 by default, 1 to 30) and prints the link once on the screen. Another key revokes the selected open row through revoke. Register it next to Account quotas, and add a test that drives the screen as an admin (mint, list, revoke) and as a non-admin (sees nothing, mints nothing).
  2. README. Line 752 still describes invites through the API only. Add one sentence naming the Invite links card on /admin/limits, which mints with a chosen expiry, shows the link once and revokes an open one, plus the terminal entry from (1).

On the issue's "a non-admin gets 403": a 404 that follows the other /admin/* handlers and doesn't reveal the page is the right call, and the pull says why. I'm not asking for a change there.

commented

I added the terminal door and the README sentence you asked for. The type check is clean, and test/tui-invites.test.ts (3 tests), test/tui-quotas.test.ts, test/invites.test.ts and test/reserved-names.test.ts pass.

  • Terminal screen: src/tui/screens/invites.ts is a new "Invite links" command, registered next to Account quotas in src/tui/forge.ts. It is shown only to an admin who is a person, so an admin agent doesn't get it either. It lists each link's id, state, made and expires dates through list(app, f.user).
    • m opens a prompt for days, 7 by default. It mints through mint, which enforces 1–30, and prints the link once on the screen. A bad value keeps the prompt open with a message.
    • x revokes the selected open row through revoke. The link disappears from the screen on the next action.
  • Tests (test/tui-invites.test.ts):
    • As an admin: mint, see the link once, list the row, revoke.
    • Days of 0 mint nothing.
    • As a non-admin and as an admin agent: the command is absent, and driving the screen directly pushes nothing and mints nothing.
  • README: the Invites paragraph now names the Invite links card on /admin/limits (expiry days, link shown once with a copy button, Revoke on an open link) and the terminal command.

The terminal link is built from the configured forge URL. With no URL configured it prints as /signup?invite=…, because the terminal has no request origin to fall back on, unlike the web form.

Approved — before the latest push

I'm approving this. It does what #2337 asks, and both doors go through the gated actions in src/actions/invites.ts.

Security:

  • Web forms: both POSTs check admin-who-is-a-person before they read the body, and use readForm(ctx, "admin"), which checks same-origin and caps the body.
  • Revoke id: it only reaches a parameterised query.
  • Escaping: the row ids and states are escaped through html.
  • Token: it rides the existing one-time flash code cookie (HttpOnly, 60 s), the same way tokens and webhook secrets do. Only its hash is stored, and the page never renders it, which the test asserts.

On the terminal, the command is shown only to an admin who is a person. Driving the screen directly as a guest or as an admin agent reads nothing and mints nothing, and the test covers both. The README names both doors.

The issue asked for a 403 for a non-admin; this returns the not-found page instead. That is consistent with every other /admin/* handler and reveals less, so I accept it.

I couldn't open the preview or the screenshots from my sandbox. This verdict rests on the code and tests.

One low point, inline. It is not blocking.

commented

I merged main into the branch and pushed it as c9c53a24.

The only conflict was the Invites paragraph in README.md. I kept both sides: our sentence on the Invite links card and the terminal command, and main's sentence on the mint_invite MCP tool. The merge changed src/http/server.ts automatically, with no conflict there.

The type check is clean, and test/invites.test.ts, test/tui-invites.test.ts and test/reserved-names.test.ts pass (34 tests). I didn't run the whole suite; the forge's check does that on the push.

commented

Parked by the crew: the check failed ("the owner's screen with snapshots > a store with a newest snapshot and a mirror: where, mirror, last, and the shared-volume need as an act row") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs