Skip to content

Commit 16c43fb

Browse files
committed
refactor(auth): the organization standing-key list stays module-private; the guard reads the map's entry
Claude-Session: https://claude.ai/code/session_01A3vH4wwSVnJvvx5BcfUpPf Co-authored-by: Claude <noreply@anthropic.com>
1 parent 11016ab commit 16c43fb

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

‎packages/plugins/plugin-auth/src/last-admin-guard.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,8 +751,10 @@ export const ACTIVATION_LEDGER_STANDING_KEYS = ['metadata_type', 'name', 'active
751751
* platform standing under `single` (`slug = 'default'`, else the only
752752
* organization). Re-slugging it while several organizations exist moves the
753753
* anchor off its grant; a delete is judged on every row, like the other tables'.
754+
* Module-private: the guard tests payloads against the map's entry
755+
* ({@link STANDING_KEYS_BY_TABLE}), so the list the gate reads is the list used.
754756
*/
755-
export const ORGANIZATION_STANDING_KEYS = ['slug'] as const;
757+
const ORGANIZATION_STANDING_KEYS = ['slug'] as const;
756758

757759
/**
758760
* [commit f8eb73601] The three lists above, keyed by the table each one judges — the shape
@@ -1767,7 +1769,7 @@ export function registerLastAdminGuard(
17671769
const ctx = ctxOf(rawCtx);
17681770
if (ctx.object !== SystemObjectName.ORGANIZATION) return;
17691771
const data = (ctx.input?.data ?? {}) as Record<string, unknown>;
1770-
if (!touchesAny(data, ORGANIZATION_STANDING_KEYS)) return;
1772+
if (!touchesAny(data, STANDING_KEYS_BY_TABLE[SystemObjectName.ORGANIZATION]!)) return;
17711773
await enforceStanding('organization-update', SystemObjectName.ORGANIZATION, ctx.input, data);
17721774
};
17731775

‎packages/plugins/plugin-auth/src/last-admin-standing-keys.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import {
5252
GRANT_STANDING_KEYS,
5353
MEMBER_STANDING_KEYS,
5454
ACTIVATION_LEDGER_STANDING_KEYS,
55-
ORGANIZATION_STANDING_KEYS,
5655
STANDING_KEYS_BY_TABLE,
5756
STANDING_KEY_EXCLUSIONS,
5857
} from './last-admin-guard.js';
@@ -132,6 +131,7 @@ describe('[#8734] standing-key lists correspond to what resolveAuthzContext read
132131
// no longer from the `sys_permission_set` row, which the guard no longer judges.
133132
expect(STANDING_KEYS_BY_TABLE.sys_metadata_activation).toBe(ACTIVATION_LEDGER_STANDING_KEYS);
134133
// [ADR-0131 D5] The organization whose grant anchors standing under `single`.
135-
expect(STANDING_KEYS_BY_TABLE.sys_organization).toBe(ORGANIZATION_STANDING_KEYS);
134+
// The guard reads this entry of the map itself, so only its content is pinned.
135+
expect(STANDING_KEYS_BY_TABLE.sys_organization).toEqual(['slug']);
136136
});
137137
});

0 commit comments

Comments
 (0)