feat(staff): staff invitations by email (#133 slice B) #136

Merged
amiryahaya merged 14 commits from feat/133-staff-invitations into main 2026-10-30 15:37:35 +01:00
Owner

What

Slice B of #133: staff invitations by email (ADR 0030). Admin portal and POS (usher/checker) users join only by invitation; web, partner and mobile customers still register themselves.

  • POST /v1/admin/staff-invitations (Idempotency-Key, admin_portal.administration.manage, platform scope), GET list, DELETE /{id}?version= (revoke; rows are never deleted), POST /v1/me/staff-invitations/accept (token in body, 1 KiB, every failure is one 404).
  • Migration 0034 staff_invitations (guard trigger, one new per email, audit excludes email and token hash); setting admin_portal_url; worker email notify.staff_invitation (link <admin_portal_url>/accept-invitation#<token>&e=<email>) and job staff.invitations_expire every 5 min.
  • Inviter must hold every permission of admin_portal roles (Super Admin only by Super Admin); POS roles need only the manage permission. Accept re-checks the inviter (active, permissions), the roles, and that the accepting user is active. A role named by a pending invitation cannot be deleted.
    Not in this PR: the admin pages and the /accept-invitation page (#134).

Reviews

Per-task reviews with fix rounds, then a whole-branch dual pass (Pass 1 ponytail, Pass 2 correctness) and one fix wave with re-checks. No Critical or Important findings remain; Ponytail Must fix list clear.

Checks

make cover 91.6% (staff 96.0, staff/pgstore 90.6, notify 97.9, rbac/pgstore 84.9); go test ./..., make contract, make lint (0 issues); scripts/generate-clients.sh ran with no diff.

Rulings

  • Same-user replay of accept writes nothing (no re-grant of a role an admin removed).
  • POS roles need only the manage permission from the inviter; slice A SetRoles still requires every permission (follow-up to align).
  • Unverified-email accept is the one 404 (not 403 as organization accept).
  • Account creation relies on OIDC prompt=create from the accept page (assumption, see verify).

Known limits (ADR 0030)

Cap of 100 pending can be passed by a few on concurrent invites; an overdue unswept row is in neither the new nor expired list for up to 5 min; inviter state read without a lock at accept; invite and accept lock in opposite order (rare deadlock gives retryable 503); API keys with the manage permission can create invitations; the idempotency record keeps the invited email 7 days; admin_portal_url not scheme-checked; used_by/used_at editable after use (as organization invitations).

  • Not verified: real IdP sign-up via prompt=create, a real SMTP server, two real nodes. Worker and SMTP must run, and admin_portal_url must be set, before invitations work.

🤖 Generated with Claude Code

## What Slice B of #133: staff invitations by email (ADR 0030). Admin portal and POS (usher/checker) users join only by invitation; web, partner and mobile customers still register themselves. - `POST /v1/admin/staff-invitations` (Idempotency-Key, `admin_portal.administration.manage`, platform scope), `GET` list, `DELETE /{id}?version=` (revoke; rows are never deleted), `POST /v1/me/staff-invitations/accept` (token in body, 1 KiB, every failure is one 404). - Migration 0034 `staff_invitations` (guard trigger, one new per email, audit excludes email and token hash); setting `admin_portal_url`; worker email `notify.staff_invitation` (link `<admin_portal_url>/accept-invitation#<token>&e=<email>`) and job `staff.invitations_expire` every 5 min. - Inviter must hold every permission of admin_portal roles (Super Admin only by Super Admin); POS roles need only the manage permission. Accept re-checks the inviter (active, permissions), the roles, and that the accepting user is active. A role named by a pending invitation cannot be deleted. Not in this PR: the admin pages and the `/accept-invitation` page (#134). ## Reviews Per-task reviews with fix rounds, then a whole-branch dual pass (Pass 1 ponytail, Pass 2 correctness) and one fix wave with re-checks. No Critical or Important findings remain; Ponytail Must fix list clear. ## Checks `make cover` **91.6%** (staff 96.0, staff/pgstore 90.6, notify 97.9, rbac/pgstore 84.9); `go test ./...`, `make contract`, `make lint` (0 issues); `scripts/generate-clients.sh` ran with no diff. ## Rulings - Same-user replay of accept writes nothing (no re-grant of a role an admin removed). - POS roles need only the manage permission from the inviter; slice A SetRoles still requires every permission (follow-up to align). - Unverified-email accept is the one 404 (not 403 as organization accept). - Account creation relies on OIDC `prompt=create` from the accept page (assumption, see verify). ## Known limits (ADR 0030) Cap of 100 pending can be passed by a few on concurrent invites; an overdue unswept row is in neither the new nor expired list for up to 5 min; inviter state read without a lock at accept; invite and accept lock in opposite order (rare deadlock gives retryable 503); API keys with the manage permission can create invitations; the idempotency record keeps the invited email 7 days; `admin_portal_url` not scheme-checked; `used_by/used_at` editable after use (as organization invitations). - Not verified: real IdP sign-up via `prompt=create`, a real SMTP server, two real nodes. **Worker and SMTP must run, and `admin_portal_url` must be set, before invitations work.** 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
staff.Inviter and staff.Acceptor with their store interfaces and the
InvitationNotifier the email job will implement; pgstore.Invitations
persists staff_invitations; rbac/pgstore.ActiveHoldsPermissionsTx checks
an active user's platform permissions from the database.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
POS roles (usher_app, checker_app) need only administration.manage of the
inviter, at invite and accept; accept compares emails in ASCII only and
re-checks each role's application; bounded invitation row lock wait
(staff.ErrBusy); wrapped store errors; Normalize keeps the caller's slice.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
docs: staff invitation limits from the final review (#133)
All checks were successful
ci / changes (pull_request) Successful in 11s
ci / clients (pull_request) Successful in 1m53s
ci / web (pull_request) Successful in 6m9s
ci / api (pull_request) Successful in 11m0s
ci / ci-gate (pull_request) Successful in 3s
0db6e8e038
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
primatekuntech/kws!136
No description provided.