Skip to content

Commit 98cbc47

Browse files
committed
fix(platform-objects): state the tenancy posture the isolation sentence holds under; pin an administrator editing and clearing another's setting
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CXM7nqtiQ3M9JqGAqL
1 parent 03e453e commit 98cbc47

3 files changed

Lines changed: 38 additions & 5 deletions

File tree

‎.changeset/35498-standard-unit-setting.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Metadata-protocol: none
1313
An organization administrator can now give any standard unit of measure (UN/ECE Recommendation 20 codes such as `KGM` or `H87`) its own display decimal places, for example 3 for grams at a jeweller or 0 for kilograms at a gravel yard. The value lives in the new organization-owned object `sys_standard_unit_setting` (Setup → Configuration → Standard Unit Settings): one row per standard code, `decimal_places` a whole number from 0 to 12. Deleting the row clears the setting. The organization's own units keep their decimal places on their own `sys_unit` row.
1414

1515
- Every member reads the settings (`member_default`, read only); organization administrators and owners create, edit and delete them (`organization_admin`). External members get no read, as with `sys_unit`.
16-
- `organization_id` is injected, so the tenant wall scopes every read and write; another organization's setting is never read.
16+
- `organization_id` is injected and stamped on every row. Under the `isolated` tenancy posture the tenant wall (ADR-0095 D1) confines every read and write to the caller's organization, so another organization's setting is never read. As with every organization-owned object (ADR-0105 D1), the `single` posture raises no wall, and the `group` posture walls by membership, so a member of several organizations can read each one's settings.
1717
- Every set, change and clear is written to `sys_audit_log`, with field history on both columns.
18-
- The value is a display default only (ADR-0158 L4): a field's own `scale` stays the storage ceiling, and nothing is rounded at write by it. No reader ships in this change; the quantity display reads it.
18+
- The value is a display default only (ADR-0158 L4): a field's own `scale` stays the storage ceiling, and nothing is rounded at write by it. No reader ships in this change; the quantity display card (#35490) will read it.
1919
- Like an exchange rate, a setting is a record the organization owns, so an organization delete is refused (`DELETE_RESTRICTED`) until its settings are deleted.

‎packages/platform-objects/src/system/sys-standard-unit-setting.object.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ export const STANDARD_UNIT_SETTING_CODE_PATTERN = `^(?:${STANDARD_UNIT_SETTING_C
4646
* unlike `sys_unit` the delete is served; it is also what lets an
4747
* organization delete itself, which refuses while any of its records
4848
* remain, as an exchange rate does.
49-
* - **Tenancy** — no tenancy opt-out, so `organization_id` is injected and the
50-
* Layer 0 tenant wall (ADR-0095 D1) scopes every read and write: another
51-
* organization's value is never read.
49+
* - **Tenancy** — no tenancy opt-out, so `organization_id` is injected and
50+
* stamped on every row. Under the `isolated` posture the Layer 0 tenant
51+
* wall (ADR-0095 D1) confines every read and write to the caller's
52+
* organization, so another organization's value is never read; as for
53+
* every organization-owned object (ADR-0105 D1), `single` raises no wall
54+
* and `group` walls by membership.
5255
* - **Who reads, who writes** — every member READS it (`member_default` names
5356
* this object, read only), as `sys_unit` is read, so a quantity displays
5457
* with the same default for everyone who reads it. Organization

‎packages/plugins/plugin-security/src/default-permission-sets.standard-unit-setting.integration.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,36 @@ describe('sys_standard_unit_setting on a real stack: administrator sets and clea
202202
});
203203
}
204204

205+
// The `organization_admin` line's claim: an administrator edits and clears
206+
// EVERY setting of the organization, not only the ones they created, with
207+
// no superuser bit (settings carry no owner scope for an administrator).
208+
describe('an administrator edits and clears every setting of the organization, not only their own', () => {
209+
for (const [creator, editor] of [['owen', 'carol'], ['carol', 'owen']] as const) {
210+
it(`the ${editor === 'carol' ? 'administrator' : 'owner'} changes and then deletes a setting the ${creator === 'owen' ? 'owner' : 'administrator'} created`, async () => {
211+
const code = creator === 'owen' ? 'MTR' : 'CMT';
212+
const id = String((await insert(as[creator], { code, decimal_places: 2 })).id);
213+
expect(await storedById(id)).toMatchObject({ code, decimal_places: 2, organization_id: ORG });
214+
215+
await update(as[editor], id, { decimal_places: 1 });
216+
expect(await storedById(id)).toMatchObject({ code, decimal_places: 1 });
217+
218+
await remove(as[editor], id);
219+
expect(await stored({ code })).toEqual([]);
220+
});
221+
}
222+
223+
it("the effective permissions of both keep read, create, edit and delete, without the superuser bits", async () => {
224+
const security = kernel.getService<{
225+
getEffectiveObjectPermissions(ctx: Ctx): Promise<Record<string, Record<string, unknown>>>;
226+
}>('security');
227+
for (const key of ['carol', 'owen'] as const) {
228+
const map = await security.getEffectiveObjectPermissions(as[key]);
229+
expect(map[OBJ], key).toMatchObject({ allowRead: true, allowCreate: true, allowEdit: true, allowDelete: true });
230+
expect(map[OBJ]?.modifyAllRecords, key).not.toBe(true);
231+
}
232+
});
233+
});
234+
205235
describe('a member', () => {
206236
it("reads the organization's settings, so a quantity displays with the same default for them", async () => {
207237
expect((await list(as.alice)).map((r) => [r.code, r.decimal_places])).toEqual([['GRM', 3]]);

0 commit comments

Comments
 (0)