feat(orgs): approval/rejection rework — workspace granted, founder notified (task 1.3, ORG-02/03) #55
No reviewers
Labels
No labels
epic
phase-0
phase-1
phase-2
phase-3
phase-4
phase-5
phase-6
phase-7
phase-8
phase-9
priority/P0
priority/P1
priority/P2
type/backend
type/client
type/docs
type/ops
type/security
type/spike
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
primatekuntech/failsulit!55
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/1.3-approval-rework"
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?
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 queuePOST /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 recordedApprove (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 MarchTenantRequestTestsflow.Closes #18 (task 1.3)
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>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).