Commit 9f1a8cc
refactor(frameworks): split custom frameworks into dedicated per-org tables
Previously the branch added a nullable organizationId column to the platform
FrameworkEditorFramework / FrameworkEditorRequirement tables so a single row
was either platform (null) or org-custom (set). That hybrid shape mismatched
the template/instance pattern used everywhere else in the codebase and caused
two cross-tenant reads (frameworks.service.findOne, findRequirement) to leak
one org's custom requirements to another org on the same framework.
Move the org-custom data into dedicated CustomFramework / CustomRequirement
tables. FrameworkInstance.frameworkId and RequirementMap.requirementId become
nullable and gain customFrameworkId / customRequirementId siblings with DB
CHECK constraints enforcing exactly one of the two is set. The editor tables
are pure platform definitions again, so the leaks vanish structurally (no
shared table to filter) rather than relying on filter discipline in each read.
- Schema: revert organizationId from FrameworkEditor tables; add
CustomFramework + CustomRequirement; relax/branch FrameworkInstance and
RequirementMap FKs with CHECK constraints
- Migration: move existing per-org rows into the new tables, repoint FKs,
drop the old columns
- API: rewrite FrameworksService findOne / findRequirement / createCustom /
createRequirement / linkRequirements / linkControlsToRequirement /
findAvailable to branch on platform vs custom. Update ControlsService
create + linkRequirements + DTOs to accept customRequirementId (with
exactly-one validation) and persist documentTypes in the same transaction
- Frontend: plumb isCustom through the requirement/control sheets, widen
FrameworkInstanceWithControls / FrameworkInstanceForTasks to surface
customFramework, and fix all fw.framework.* null-unsafe reads
- Tests: frameworks.service.spec regression coverage that a custom FI never
reads from frameworkEditorRequirement and a platform FI never reads from
customRequirement
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent f40226a commit 9f1a8cc
40 files changed
Lines changed: 1412 additions & 274 deletions
File tree
- apps
- api/src
- admin-organizations
- controls
- dto
- frameworks
- policies
- tasks
- app/src
- app
- (app)/[orgId]
- controls/hooks
- frameworks
- [frameworkInstanceId]
- components
- controls/[controlId]
- components
- requirements/[requirementKey]
- components
- components
- data
- overview/components
- tasks
- components
- api/user-frameworks
- lib/types
- trigger/tasks/onboarding
- packages
- db/prisma
- migrations/20260417210000_split_custom_frameworks
- schema
- docs
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
137 | | - | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
138 | 142 | | |
139 | 143 | | |
140 | 144 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| |||
136 | 138 | | |
137 | 139 | | |
138 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
139 | 171 | | |
140 | 172 | | |
141 | 173 | | |
| |||
0 commit comments