Skip to content

Commit 2f6bd6c

Browse files
committed
fix(platform-objects): a business unit with child units refuses its delete (parent_business_unit_id restrict)
Claude-Session: https://claude.ai/code/session_01VBFXArkqADbAp54xq6RAZE Co-authored-by: Claude <noreply@anthropic.com>
1 parent f32d795 commit 2f6bd6c

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎packages/platform-objects/src/identity/sys-business-unit.object.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,19 @@ export const SysBusinessUnit = ObjectSchema.create({
128128
),
129129

130130
// ── Hierarchy ────────────────────────────────────────────────
131+
// `restrict`, not the lookup default `set_null`: deleting a unit that still
132+
// has child units is refused (`409 DELETE_RESTRICTED`, naming this object and
133+
// the child count) until they are re-parented or deleted. Under `set_null`
134+
// the delete answered 200 and silently made each child a root of the
135+
// tenant, so a `unit_and_subordinates` grant anchored above the deleted
136+
// unit stopped reaching the former subtree. A delete that removes the
137+
// children first (leaf to root) still completes.
131138
parent_business_unit_id: Field.lookup('sys_business_unit', {
132139
label: 'Parent Business Unit',
133140
required: false,
134-
description: 'Self-reference for the org tree. Null = root of tenant.',
141+
deleteBehavior: 'restrict',
142+
description:
143+
'Self-reference for the org tree. Null = root of tenant. A unit that still has child units cannot be deleted until they are re-parented or deleted.',
135144
group: 'Hierarchy',
136145
}),
137146

0 commit comments

Comments
 (0)