mirror of
https://github.com/block/buzz.git
synced 2026-11-24 18:21:59 +00:00
Stack: this PR → #9690 ## What this does Adds listing and revocation for v2 invite links, and makes every reader of an invite's expiry accept a missing value. - **`GET /api/invites?limit=&before=`** lists the community's v2 invites, newest first: id, creator, created/expiry/revoked times, uses and a computed `status` (`active`, `revoked`, `expired`, `exhausted`). Owner/admin only. The NIP-98 signature covers the full URL including the query. `limit` defaults to 50 (max 200). `next_before` is an opaque cursor holding the last row's `created_at` (microseconds) and id, so paging doesn't depend on that row still existing. - **`POST /api/invites/revoke`** takes exactly one of `{"id": "<uuid>"}` or `{"code": "v2...."}`. The code is hashed and looked up only inside the request's community. v1 and malformed codes get `400 invite_not_revocable`; an invite not in the community gets 404. Revoking twice returns the first `revoked_at`. Members who already joined stay. - **Authorization.** Mint, list and revoke share one HTTP admission helper (tenant bind → NIP-98 via NIP-FI → replay → membership/ban → NIP-OA owner link → role gate). Revoke's final decision is made in the write transaction, in the same order as mint: admission lock → actor's role row `FOR SHARE` → restriction check → invite row `FOR UPDATE`. Owners and admins can revoke any invite; any other member only one they created. A removed or restricted actor is refused. Mint now uses the same role-lock helper. - **Mint response** now includes `invite_id`. - **Nullable expiry readers.** Claim, list, the mint response and operator mint treat a missing `expires_at` as "never expires". The column is still `NOT NULL` here. - **Secrets.** No list/revoke response or access-log line contains a code or its hash; request errors are fixed strings that never echo input. Revoke logs only `invite_id`. A revoke the database refuses is logged as denied with its reason. ## Deploy order A follow-up PR adds links that never expire (`expires_at` nullable). **It depends on this PR being deployed everywhere first**, so every serving relay can read a missing expiry before one is written. ## Tests - DB (`relay_invite/manage_postgres_tests.rs`): revoke by code targets exactly one of two near-identical invites, idempotent revoke, community scoping, creator demoted to member can revoke theirs, a member who didn't create it is refused, a removed creator is refused, a restricted admin is refused, a demotion holding the role row or a restriction holding the admission lock makes revoke wait and then refuse with the row unchanged, a paused claim and a revoke serialize with the member kept, revoke is refused while the community is quiescing, paging survives deleting the cursor row, and a row with no expiry is listed, claimed, kept by the reaper and revocable (on a scratch database with `NOT NULL` dropped). - Relay (`invites/postgres_tests/manage_tests.rs`): list/revoke by id and code end to end, no code or hash in responses, member/non-member refusals, bad selectors, other-community lookups, query-string signature binding, malformed requests not echoing a code in responses or access logs, refused revokes logged as denied, and replayed list/revoke requests refused. --------- Signed-off-by: Will Pfleger <wpfleger@block.xyz> Co-authored-by: Duncan <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@buzz.block.builderlab.xyz>