feat(orgs): organization invitations and members, slice B (#37) #108
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
primatekuntech/kws!108
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/37-org-invitations"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Slice B of #37 (does not close it). A tour agent company's Organization Administrator invites its own staff by email; the invited person accepts after signing in; the administrator lists, re-roles and removes the company's partner-portal users. Builds on slice A (#107). Plan:
docs/superpowers/plans/2026-10-27-org-invitations.md; rulings and limits: ADR 0021 "Slice B" (o)-(t).What is in it
organization_invitations: SHA-256 token hash (secret column, never audited), guardednew -> used|expired|revoked, one open invitation per (organization, email), 7-day default expiry.Business Entry ClerkandBusiness Portal Payment Clerkas system roles, with exactly the legacy permission lists (pinned by a test)./v1/orgs/{id}/invitations):business_portal.users.invite,Idempotency-Keyrequired; only an Organization Administrator may grant that role; at most 50 open; re-invite revokes the old link; email queued in the same transaction (notify.invitation); the link carries the token in a URL fragment; the response never contains the token.POST /v1/me/invitations/accept, token in the body): verified email, exact email match, active organization, and the inviter must still be an Organization Administrator; every refusal is one identical 404. Roles granted are the built-in system roles only.GET /v1/orgs/{id}/members,PUT .../{user_id}/roles,DELETE .../{user_id}): last Organization Administrator can never be removed or demoted (organization rowFOR NO KEY UPDATE, then count).orgs.invitations_expirejob (every 5 min);notify.invitationhandler registered in the worker with SMTP.token(scalar-safe);rbac/pgstoregetsHasRoleTxandGrantSystemRoleTx(system roles only); slice A's approval now grants throughGrantSystemRoleTx(the name-onlyGrantRoleTxis deleted).Verification
go test ./... -race -count=1green,make lint0 issues,make contractok, clients (TS/Dart) generate.make cover: 90.8% (minimum 80%), run after the last code change.Deploy notes
Run migration 0026 (it re-applies system roles on
KWS_MODE=migrate). Needspartner_portal_url(https) set, SMTP on API and worker, and the worker running (invitation emails, expiry). Without SMTP, inviting returns 503.[verify] with the owner
7-day expiry (legacy 2); clerks hold eWallet top-up (legacy lists); only administrators grant Organization Administrator; already-member = 409; removal deletes the membership; the registrant is an ordinary member after approval.
Known limits
No staff-on-behalf invitations, custom organization roles, member email change, switch-organization endpoint or removal notice; no per-organization send cap (#62); the 50-open cap is soft under racing invites; accept timing differs slightly between 404 cases; a repeat accept is 404 once the inviter loses administrator; concurrent removal of one user from two organizations can leave no default membership.
🤖 Generated with Claude Code
Members service (List, SetRoles, Remove) under the organization row's FOR NO KEY UPDATE lock: only an Organization Administrator adds or takes away that role, and no change leaves the organization without one (409 last_administrator). Removal promotes another default membership. Routes GET/PUT/DELETE /v1/orgs/{id}/members... with users.view/update/delete. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>- rbac/pgstore.GrantRoleTx (prefers an organization role of the same name) had no caller left: removed with its test; review.go names GrantSystemRoleTx. - RevokeOpenByEmail and CountOpen map a lock or statement timeout to ErrBusy (503) instead of a 500. - The invitation expiry job logs only when it expired something. - OpenAPI: 413 on POST /v1/orgs/{id}/invitations and PUT /v1/orgs/{id}/members/{user_id}/roles. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>