Skip to content

Commit 2888073

Browse files
committed
docs(objectql,plugin-auth): state the real reasons the organization refusal, team-member order and per-id reap keep (#26871)
Prose only. The predicate delete now runs the referential walk, so the three comments and the organization refusal's developerMessage that gave 'a predicate delete runs no cascade' as their reason now state the reason that still holds. Claude-Session: https://claude.ai/code/session_01FEkQ5ptsvnYe5ZErgvP66h Co-authored-by: Claude <noreply@anthropic.com>
1 parent 27b890d commit 2888073

3 files changed

Lines changed: 23 additions & 17 deletions

File tree

‎packages/objectql/src/engine.ts‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -789,19 +789,23 @@ export function writeFailureLogMeta(
789789

790790
/**
791791
* [#24948] The refusal of a predicate (`multi`) delete of `sys_organization`:
792-
* the standard `DELETE_RESTRICTED`, saying to delete by id. Only the by-id
793-
* delete runs the referential pass that refuses an organization still owning
794-
* rows and keeps every row's reference to it.
792+
* the standard `DELETE_RESTRICTED`, saying to delete by id. An organization is
793+
* deleted one at a time, through plugin-auth's organization delete: its
794+
* refusal of an organization that still owns records and its
795+
* `beforeDeleteOrganization` clean-up of the organization's teams, team members
796+
* and admin grants run there, once per organization. A delete matching
797+
* organizations by a filter runs neither, and no caller needs one.
795798
*/
796799
function organizationPredicateDeleteRefusal(): Error {
797800
const err: any = new Error(
798801
'Organizations are deleted one at a time, by id: a delete matching organizations by a filter is refused. ' +
799802
'Delete each organization by its id.',
800803
);
801804
err.developerMessage =
802-
`A predicate delete of ${ORGANIZATION_OBJECT} is refused: it runs no referential pass, so it could neither ` +
803-
'refuse an organization that still owns rows nor keep the rows naming it. Delete each organization by id ' +
804-
`(engine.delete('${ORGANIZATION_OBJECT}', { where: { id } })).`;
805+
`A predicate delete of ${ORGANIZATION_OBJECT} is refused: organizations are deleted one at a time, because ` +
806+
"plugin-auth's organization delete refuses an organization that still owns records and removes its teams, " +
807+
'team members and admin grants per organization, and a predicate delete runs neither. Delete each organization ' +
808+
`by id (engine.delete('${ORGANIZATION_OBJECT}', { where: { id } })).`;
805809
err.code = 'DELETE_RESTRICTED';
806810
err.status = 409;
807811
err.httpStatus = 409;
@@ -19646,11 +19650,11 @@ export class ObjectQL implements IObjectQLEngine {
1964619650
// update twin says why; for every pre-#11009 input the two spellings
1964719651
// agree.
1964819652
const isPredicatePath = !isByIdDelete && dispatch.kind === 'multi' && typeof driver.deleteMany === 'function';
19649-
// [#24948] An organization is deleted by id or not at all. The predicate
19650-
// arm runs no referential cascade, so it could neither refuse an
19651-
// organization that still owns rows nor keep a single row from naming a
19652-
// deleted one; any delete not by id is refused here, whatever the driver
19653-
// offers, before any hook or write.
19653+
// [#24948] An organization is deleted by id or not at all: plugin-auth's
19654+
// organization delete refuses one that still owns records and removes its
19655+
// auth structure per organization, which a predicate delete would skip
19656+
// (see `organizationPredicateDeleteRefusal`). Any delete not by id is
19657+
// refused here, whatever the driver offers, before any hook or write.
1965419658
if (!isByIdDelete && object === ORGANIZATION_OBJECT) {
1965519659
throw organizationPredicateDeleteRefusal();
1965619660
}

‎packages/objectql/src/lifecycle/lifecycle-service.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,9 +1789,10 @@ export class LifecycleService {
17891789
});
17901790
if (confirmed.length === 0) break;
17911791
}
1792-
// Per-id deletes (NOT a `{$in}` filter): the engine's delete path reads
1793-
// `where.id` as a scalar target, and by-id deletes get referential
1794-
// cascade handling a filter-delete would bypass.
1792+
// Per-id deletes (NOT a `{$in}` filter): the engine reads a scalar
1793+
// `where.id` as a by-id target even beside `multi: true`, so each
1794+
// confirmed row is deleted on its own, with its own pre-image read,
1795+
// hooks and referential walk.
17951796
for (const row of confirmed) {
17961797
await engine.delete(object, {
17971798
where: { id: row.id },

‎packages/plugins/plugin-auth/src/organization-delete.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,10 @@ export async function isDefaultOrganizationTarget(
262262
* request's transaction, so a later failure rolls it back.
263263
*
264264
* Team members first, by their team: `sys_team_member` reaches the
265-
* organization only through `team_id`, and a multi-row delete runs no cascade.
266-
* Then each team by id, so the engine's cascade clears what still points at it
267-
* (a session's active team). The grants go explicitly, here, rather than
265+
* organization only through `team_id`, a required lookup, so a team still
266+
* holding members would refuse its own delete (a required reference is
267+
* restricted, never cleared). Then each team by id, so the engine's cascade
268+
* clears what still points at it (a session's active team). The grants go explicitly, here, rather than
268269
* waiting on plugin-security's member-delete reconcile: measured on a booted
269270
* showcase, they were still present when the organization row was deleted.
270271
*/

0 commit comments

Comments
 (0)