feat(orgs): tour agent organization registration, slice A (#37) #107

Merged
amiryahaya merged 9 commits from feat/37-org-registration into main 2026-10-27 12:33:51 +01:00
Owner

Slice A of #37: tour agent company (organization) registration for the partner portal. Does not close #37 (invitations and organization accounts are slice B; the plan outlines it).

What it does

  • A signed-in user with a verified email registers a company: POST /v1/me/organizations (Idempotency-Key required; one open registration per user; the Kenya Wildlife Service type is staff-only). They upload documents as raw PDF/JPEG/PNG bodies (type sniffed and matched to Content-Type, 5 MiB, 20 per company, append-only, bytes in PostgreSQL behind orgs.DocumentStore until #18 adds object storage).
  • KWS staff move it pending -> reviewed -> verified -> active (or rejected, final), and can disable and re-enable: POST /v1/admin/organizations/{id}/status. The status machine is enforced by a DB guard; every change writes an append-only log row; remarks are shown to the applicant.
  • Four new permission keys (admin_portal.organizations.view|review|verify|approve), all platform scope only, assigned to the legacy role groups; an organization's own admins can never approve themselves.
  • Approval grants the registrant (by user id, in the same transaction) "Organization Administrator" in the company. Disable cuts access: a membership of a non-active organization resolves to no grant (legacy's disable did nothing). Wallet untouched.
  • Three emails through the job queue (received, approved, rejected). New partner_portal_url setting (https only).
  • Migration 0025, ADR 0021, OpenAPI (13 operations) plus live contract test, CLAUDE.md "Organizations" section, shared rbac.PlatformOnly/PlatformHas helper (payments now uses it too, behaviour unchanged).

Owner decisions (approved defaults)

Verified-login registration (legacy was anonymous); three review steps by legacy role group; rejected is final; registrant (not the form's contact email) becomes the first administrator; disable cuts access only; no virus scan before public launch; 5 MiB / 20 files / PDF only; no new KRA/registration fields; legacy "Pending hard-copy" and "Approved" statuses dropped.

Known limits (ADR 0021)

No virus scan (ClamAV job is the upgrade); document bytes in PostgreSQL until #18; no invitations or member management (slice B); any verified user can make KWS email an address they type, once per open registration (rate limits #62); no four-eyes rule; after rejected the guard protects only status and registrant; a same-status move answers 200 without the step check; uploads are held in memory (up to 5 MiB per request).

Review (dual pass)

  • Pass 1 (ponytail): no Must fix; five cleanups done (shared platform-scope helper, grant adapter removed, sniff inlined, simpler file-name cleaner, one status list). Re-checked after each fix commit: no Must fix.
  • Pass 2 (correctness): one Important finding, fixed with tests: a download carried the applicant's file name and extension (an RTL-override name saved as .exe, or a PDF/HTML polyglot saved as .html). Downloads now use the stored type's extension and file names drop format characters. Minor items fixed or documented in the ADR.

Verification

go test -race -count=1 ./... green, make lint 0 issues, make contract ok, TypeScript and Dart clients generate, make cover: total coverage 90.8% (minimum 80%).

Note for bisecting: commits 5ff67d4 and b8a11cd fail TestSpec_AndTheRoutesInTheCodeAreTheSameSet (the contract test scans the source for routes, and the spec arrives in the last task). The branch head is green.

Deploy

Run migration 0025 (KWS_MODE=migrate). Set the partner_portal_url setting (https URL) for the approved email link. SMTP must be configured on API and worker for the emails (as for purchases). The worker must be running.

🤖 Generated with Claude Code

Slice A of #37: **tour agent company (organization) registration for the partner portal**. **Does not close #37** (invitations and organization accounts are slice B; the plan outlines it). ## What it does - A signed-in user with a **verified email** registers a company: `POST /v1/me/organizations` (`Idempotency-Key` required; one open registration per user; the Kenya Wildlife Service type is staff-only). They upload documents as raw PDF/JPEG/PNG bodies (type sniffed and matched to `Content-Type`, 5 MiB, 20 per company, append-only, bytes in PostgreSQL behind `orgs.DocumentStore` until #18 adds object storage). - KWS staff move it `pending -> reviewed -> verified -> active` (or `rejected`, final), and can disable and re-enable: `POST /v1/admin/organizations/{id}/status`. The status machine is enforced by a DB guard; every change writes an append-only log row; remarks are shown to the applicant. - Four new permission keys (`admin_portal.organizations.view|review|verify|approve`), all platform scope only, assigned to the legacy role groups; an organization's own admins can never approve themselves. - Approval grants the registrant (by user id, in the same transaction) "Organization Administrator" in the company. **Disable cuts access**: a membership of a non-active organization resolves to no grant (legacy's disable did nothing). Wallet untouched. - Three emails through the job queue (received, approved, rejected). New `partner_portal_url` setting (https only). - Migration 0025, ADR 0021, OpenAPI (13 operations) plus live contract test, CLAUDE.md "Organizations" section, shared `rbac.PlatformOnly/PlatformHas` helper (payments now uses it too, behaviour unchanged). ## Owner decisions (approved defaults) Verified-login registration (legacy was anonymous); three review steps by legacy role group; rejected is final; registrant (not the form's contact email) becomes the first administrator; disable cuts access only; no virus scan before public launch; 5 MiB / 20 files / PDF only; no new KRA/registration fields; legacy "Pending hard-copy" and "Approved" statuses dropped. ## Known limits (ADR 0021) No virus scan (ClamAV job is the upgrade); document bytes in PostgreSQL until #18; no invitations or member management (slice B); any verified user can make KWS email an address they type, once per open registration (rate limits #62); no four-eyes rule; after `rejected` the guard protects only status and registrant; a same-status move answers 200 without the step check; uploads are held in memory (up to 5 MiB per request). ## Review (dual pass) - Pass 1 (ponytail): no Must fix; five cleanups done (shared platform-scope helper, grant adapter removed, sniff inlined, simpler file-name cleaner, one status list). Re-checked after each fix commit: no Must fix. - Pass 2 (correctness): one Important finding, fixed with tests: a download carried the applicant's file name and extension (an RTL-override name saved as `.exe`, or a PDF/HTML polyglot saved as `.html`). Downloads now use the stored type's extension and file names drop format characters. Minor items fixed or documented in the ADR. ## Verification `go test -race -count=1 ./...` green, `make lint` 0 issues, `make contract` ok, TypeScript and Dart clients generate, **`make cover`: total coverage 90.8% (minimum 80%)**. **Note for bisecting:** commits `5ff67d4` and `b8a11cd` fail `TestSpec_AndTheRoutesInTheCodeAreTheSameSet` (the contract test scans the source for routes, and the spec arrives in the last task). The branch head is green. ## Deploy Run migration 0025 (`KWS_MODE=migrate`). Set the `partner_portal_url` setting (https URL) for the approved email link. SMTP must be configured on API and worker for the emails (as for purchases). The worker must be running. 🤖 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>
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(orgs): CLAUDE.md rules for organizations (#37)
All checks were successful
ci / changes (pull_request) Successful in 19s
ci / clients (pull_request) Successful in 2m4s
ci / api (pull_request) Successful in 11m57s
ci / ci-gate (pull_request) Successful in 2s
95452183db
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!107
No description provided.