fix(intake): security reports outlive their workspace #127

Merged
sharang merged 1 commits from fix/intake-outlives-purge into main 2026-11-12 13:33:11 +00:00
Owner

Benjamin's decision Nr. 17 (docgen#6 comment 17878, V-g): reports must not be deleted automatically when a workspace is deleted.

Before: DELETE /v1/admin/tenants/{id} (staff only, archived workspaces only) deleted the workspace's intake reports with it, because every intake table cascades from tenants.

Now:

  • The purge checks first, before any document file or Keycloak account is removed. It answers 409 intake_retained while the workspace has reports.
  • Migration 0030: intake_reports.tenant_id changes to ON DELETE RESTRICT, so the database refuses too. DeleteTenant maps that to ErrConflict.
  • CountIntakeReports exists on both stores.

How long reports are then kept, and who may delete them later, is a retention question that isn't decided yet. Until it is, they stay.

Effects:

  • Prod: no workspace there has intake reports today (the intake is off), so nothing changes.
  • Stage: a purge of a workspace that has test reports is refused from now on.
  • The breakpilot prod tenant plan isn't affected: it creates a new workspace and doesn't purge one (control-center confirmed).

Tests:

  • TestPurgeKeepsIntakeReports: refused, nothing removed, the store refuses as well.
  • TestIntakeStore now expects the reports to stay.
  • Postgres variants run in CI.

Control-center was told before this PR.

🤖 Generated with Claude Code

https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf

Benjamin's decision Nr. 17 (docgen#6 comment 17878, V-g): reports must not be deleted automatically when a workspace is deleted. **Before:** `DELETE /v1/admin/tenants/{id}` (staff only, archived workspaces only) deleted the workspace's intake reports with it, because every intake table cascades from `tenants`. **Now:** - The purge checks first, before any document file or Keycloak account is removed. It answers **409 `intake_retained`** while the workspace has reports. - **Migration 0030:** `intake_reports.tenant_id` changes to `ON DELETE RESTRICT`, so the database refuses too. `DeleteTenant` maps that to `ErrConflict`. - `CountIntakeReports` exists on both stores. How long reports are then kept, and who may delete them later, is a retention question that isn't decided yet. Until it is, they stay. **Effects:** - **Prod:** no workspace there has intake reports today (the intake is off), so nothing changes. - **Stage:** a purge of a workspace that has test reports is refused from now on. - **The `breakpilot` prod tenant plan** isn't affected: it creates a new workspace and doesn't purge one (control-center confirmed). **Tests:** - `TestPurgeKeepsIntakeReports`: refused, nothing removed, the store refuses as well. - `TestIntakeStore` now expects the reports to stay. - Postgres variants run in CI. Control-center was told before this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
sharang added 1 commit 2026-11-12 13:25:54 +00:00
fix(intake): security reports outlive their workspace
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 6m5s
ci / image (pull_request) Skipped
34921bd44e
Purging an archived workspace deleted its intake reports with it: every
intake table cascaded from tenants. Benjamin's decision Nr. 17 (docgen#6
17878, V-g): no automatic deletion of the reports when a workspace is
deleted.

The purge now refuses first, before any file or account is removed:
409 intake_retained while the workspace has reports. Migration 0030 makes
the database refuse as well (intake_reports → tenants ON DELETE RESTRICT),
and DeleteTenant maps that to ErrConflict. CountIntakeReports on both
stores.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
sharang merged commit b28d564867 into main 2026-11-12 13:33:11 +00:00
Sign in to join this conversation.