feat(orgs): approval/rejection rework — workspace granted, founder notified (task 1.3, ORG-02/03) #55

Merged
amiryahaya merged 1 commit from feat/1.3-approval-rework into main 2026-11-05 08:18:55 +01:00
Owner

Completes the founder story: 1.1 Pending state ✓ → 1.2 submit/poll ✓ → 1.3 approval closes the loop.

Admin queue mapped into /api/admin (SuperAdmin-gated) — was entirely unmapped

  • GET /api/admin/tenant-requests[?status=] — the queue
  • POST /api/admin/tenant-requests/{id}/approve — atomic Pending→Approved via ExecuteUpdate guard (old code: non-atomic check-then-set)
  • POST /api/admin/tenant-requests/{id}/reject — reason recorded

Approve (ORG-02, fixes the silent-approval dead-end from the baseline review)

Creates the tenant (slug dedupe kept), flips the founder Pending → Active with TenantId granted + Owner membership (ExecuteUpdate per #44; tenant saved before the user FK update — ordering bug found during green), audits, in-app notification, best-effort approval email (new SendApprovalAsync).

Reject (ORG-03)

Founder returns Pending → Active/no-workspace (can re-submit), in-app notification + SaveChanges (CreateAsync only tracks — silent-miss found during green), best-effort rejection email (existing).

Tests (TDD §2.1)

OrgApprovalTests (6) written first — red (routes unmapped → 404). Also surfaced + fixed the same ordering bug in the old March TenantRequestTests flow.

Closes #18 (task 1.3)

Completes the founder story: 1.1 Pending state ✓ → 1.2 submit/poll ✓ → **1.3 approval closes the loop**. ## Admin queue mapped into /api/admin (SuperAdmin-gated) — was entirely unmapped - `GET /api/admin/tenant-requests[?status=]` — the queue - `POST /api/admin/tenant-requests/{id}/approve` — atomic Pending→Approved via ExecuteUpdate guard (old code: non-atomic check-then-set) - `POST /api/admin/tenant-requests/{id}/reject` — reason recorded ## Approve (ORG-02, fixes the silent-approval dead-end from the baseline review) Creates the tenant (slug dedupe kept), **flips the founder Pending → Active with TenantId granted + Owner membership** (ExecuteUpdate per #44; tenant saved before the user FK update — ordering bug found during green), audits, in-app notification, best-effort approval email (new SendApprovalAsync). ## Reject (ORG-03) Founder returns Pending → Active/no-workspace (can re-submit), in-app notification + SaveChanges (CreateAsync only tracks — silent-miss found during green), best-effort rejection email (existing). ## Tests (TDD §2.1) `OrgApprovalTests` (6) written first — red (routes unmapped → 404). Also surfaced + fixed the same ordering bug in the old March `TenantRequestTests` flow. Closes #18 (task 1.3)
feat(orgs): approval/rejection rework — workspace granted, founder notified (task 1.3, ORG-02/03)
All checks were successful
API CI / build-and-test (pull_request) Successful in 35m43s
2006ef19c4
Maps the admin tenant-request queue into /api/admin (SuperAdmin-gated):
- GET  /api/admin/tenant-requests[?status=]   — the queue (was unmapped)
- POST /api/admin/tenant-requests/{id}/approve
- POST /api/admin/tenant-requests/{id}/reject

Approve rework (ORG-02, fixes the silent-approval dead-end from the
baseline review):
- Atomic Pending → Approved transition via ExecuteUpdate guard (the old
  check-then-set allowed a concurrent double-approve)
- Founder flips Pending → Active with TenantId = new tenant + Owner
  membership (ExecuteUpdate — accessor.User is AsNoTracking, #44 class;
  tenant saved before the user FK update)
- In-app notification + best-effort approval email (new SendApprovalAsync)

Reject rework (ORG-03):
- Founder returns Pending → Active/no-workspace (can re-submit)
- In-app notification (CreateAsync now followed by SaveChanges) +
  best-effort rejection email (existing)

Slug dedupe logic unchanged. Approvals are audited (both outcomes).

TDD (§2.1): OrgApprovalTests (6) written first — red (routes unmapped),
green after implementation, incl. regression for the old March
TenantRequestTests flow.

Verified: green ×2 (767/767) + one flake-free final run.

🤖 Generated with [ZCode](https://zcode.ai)

Co-Authored-By: ZCode <noreply@anthropic.com>
Author
Owner

ponytail-review (§2.4 AI first-pass) — Verdict: Ship.

What this change does: routes the previously-dead admin approve/reject/list endpoints under the SuperAdmin-gated /api/admin group, makes the Pending→Approved transition atomic (ExecuteUpdate guard — the old check-then-set allowed concurrent double-approve), grants the founder the workspace atomically (TenantId + Status via ExecuteUpdate — AsNoTracking #44 class, with tenant-insert-before-user-FK ordering), notifies on BOTH outcomes (in-app durable via NotificationService + SaveChanges, email best-effort via new SendApprovalAsync), and sends rejected founders back to NoWorkspace/Active for re-submit.

Checked: atomicity guard semantics (affected==0 → 409, matches invite-claim pattern); FK ordering (tenant saved before user update — bug found via green-phase 500, fixed); notification persistence (CreateAsync tracks, explicit SaveChanges added); SuperAdmin filter inherited by the new routes (NonAdmin → 403 test); email failures non-blocking; tests use seeded admin client with Bearer header attached.

Notes (not blocking): approval email is plain-HTML best-effort (mirrors rejection); the admin UI queue page itself is Phase 4 (ADM-01) — the API + tests are the prerequisite; slug collision retried up to 100 then 409 (unchanged).

**ponytail-review (§2.4 AI first-pass) — Verdict: Ship.** What this change does: routes the previously-dead admin approve/reject/list endpoints under the SuperAdmin-gated /api/admin group, makes the Pending→Approved transition atomic (ExecuteUpdate guard — the old check-then-set allowed concurrent double-approve), grants the founder the workspace atomically (TenantId + Status via ExecuteUpdate — AsNoTracking #44 class, with tenant-insert-before-user-FK ordering), notifies on BOTH outcomes (in-app durable via NotificationService + SaveChanges, email best-effort via new SendApprovalAsync), and sends rejected founders back to NoWorkspace/Active for re-submit. Checked: atomicity guard semantics (affected==0 → 409, matches invite-claim pattern); FK ordering (tenant saved before user update — bug found via green-phase 500, fixed); notification persistence (CreateAsync tracks, explicit SaveChanges added); SuperAdmin filter inherited by the new routes (NonAdmin → 403 test); email failures non-blocking; tests use seeded admin client with Bearer header attached. Notes (not blocking): approval email is plain-HTML best-effort (mirrors rejection); the admin UI queue page itself is Phase 4 (ADM-01) — the API + tests are the prerequisite; slug collision retried up to 100 then 409 (unchanged).
amiryahaya deleted branch feat/1.3-approval-rework 2026-11-05 08:18:55 +01:00
Sign in to join this conversation.
No description provided.