Skip to content

Commit 900c90a

Browse files
committed
wip(platform-objects, lint): business unit page and readScope hint name the enterprise requirement
Claude-Session: https://claude.ai/code/session_01Utp6CYwoPbRRkiyph2ufCw Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2ffdb64 commit 900c90a

5 files changed

Lines changed: 121 additions & 8 deletions

File tree

‎packages/lint/src/validate-security-posture.test.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,42 @@ describe('validateSecurityPosture (ADR-0090 D7)', () => {
792792
expect(findings[0]).toMatchObject({ severity: 'info', rule: SECURITY_PRIVATE_NO_READSCOPE });
793793
});
794794

795+
// The hint offers only the scopes this stack can compile: `defineStack`
796+
// refuses `own_and_reports` / `unit` / `unit_and_below` unless `requires`
797+
// names `hierarchy-security`, so without that token the hint names the
798+
// requirement in the same sentence as those scopes instead of offering them
799+
// bare.
800+
const noReadscopeHint = (requires?: string[]): string =>
801+
validateSecurityPosture({
802+
...(requires ? { requires } : {}),
803+
objects: [{ name: 'expense', sharingModel: 'private' }],
804+
permissions: [{ name: 'finance_user', objects: { expense: { allowRead: true } } }],
805+
}).find((f) => f.rule === SECURITY_PRIVATE_NO_READSCOPE)?.hint ?? '';
806+
807+
it('without hierarchy-security, offers org and names the requirement beside the hierarchy scopes', () => {
808+
const hint = noReadscopeHint();
809+
const requirementAt = hint.indexOf("requires: ['hierarchy-security']");
810+
expect(requirementAt).toBeGreaterThan(-1);
811+
expect(hint).toContain('@objectstack/security-enterprise');
812+
const firstHierarchyScope = Math.min(
813+
...["'own_and_reports'", "'unit'", "'unit_and_below'"].map((s) => {
814+
const at = hint.indexOf(s);
815+
expect(at, `${s} is named`).toBeGreaterThan(-1);
816+
return at;
817+
}),
818+
);
819+
// What the hint offers before any hierarchy scope is `org` alone…
820+
expect(hint.slice(0, firstHierarchyScope)).toContain("readScope: 'org'");
821+
// …and no sentence ends between the first hierarchy scope and the requirement.
822+
expect(hint.slice(firstHierarchyScope, requirementAt)).not.toMatch(/\.\s/);
823+
});
824+
825+
it('with hierarchy-security declared, offers every scope and does not name the requirement', () => {
826+
const hint = noReadscopeHint(['hierarchy-security']);
827+
for (const scope of ["'own_and_reports'", "'unit'", "'unit_and_below'", "'org'"]) expect(hint).toContain(scope);
828+
expect(hint).not.toContain('security-enterprise');
829+
});
830+
795831
it('stays silent when depth or VAMA is declared, or the object is public', () => {
796832
expect(
797833
rulesOf({

‎packages/lint/src/validate-security-posture.ts‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,15 @@ export function validateSecurityPosture(stack: AnyRec, opts?: { nowMs?: number }
13721372
})
13731373
.map((o) => String(o.name ?? '')),
13741374
);
1375+
// The hint offers only the scopes this stack can compile. `defineStack`
1376+
// refuses a hierarchy scope (`own_and_reports` / `unit` / `unit_and_below`,
1377+
// `findHierarchyScopeGrants`) unless `requires` names `hierarchy-security`
1378+
// (ADR-0057), the enterprise capability — so read the same declaration here
1379+
// and, without it, name the requirement beside those scopes instead of
1380+
// offering them bare. A stack with no `requires` (the runtime metadata
1381+
// door hands none) gets the requirement named too.
1382+
const hierarchyScopesCompile =
1383+
Array.isArray(stack.requires) && (stack.requires as unknown[]).includes('hierarchy-security');
13751384
if (privateObjects.size > 0) {
13761385
for (let i = 0; i < permissionSets.length; i++) {
13771386
const ps = permissionSets[i];
@@ -1390,9 +1399,12 @@ export function validateSecurityPosture(stack: AnyRec, opts?: { nowMs?: number }
13901399
message:
13911400
`"${objName}" is private (OWD) and this set grants allowRead without a readScope — ` +
13921401
`holders see ONLY records they own (plus explicit shares).`,
1393-
hint:
1394-
`If that is intended (personal data), ignore this. Otherwise add readScope: ` +
1395-
`'own_and_reports' | 'unit' | 'unit_and_below' | 'org', or widen the object's sharingModel.`,
1402+
hint: hierarchyScopesCompile
1403+
? `If that is intended (personal data), ignore this. Otherwise add readScope: ` +
1404+
`'own_and_reports' | 'unit' | 'unit_and_below' | 'org', or widen the object's sharingModel.`
1405+
: `If that is intended (personal data), ignore this. Otherwise add readScope: 'org', ` +
1406+
`or widen the object's sharingModel. Scopes 'own_and_reports', 'unit' and 'unit_and_below' ` +
1407+
`need requires: ['hierarchy-security'], which @objectstack/security-enterprise provides.`,
13961408
});
13971409
}
13981410
}

‎packages/platform-objects/src/apps/translations/zh-CN.objects.generated.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ export const zhCNObjects: NonNullable<TranslationData['objects']> = {
984984
sys_business_unit: {
985985
label: "业务单元",
986986
pluralLabel: "业务单元",
987-
description: "公司的组织结构——事业部、部门、区域和办公地点——用于划定数据和报表的范围。",
987+
description: "公司的组织结构——事业部、部门、区域和办公地点。共享规则可以把记录共享给某个业务单元,或某个业务单元及其下级单元:成员获得这些访问权限,离开后即失去。让权限集按业务单元读取全部记录(读取范围「unit」)需要企业版。",
988988
fields: {
989989
name: {
990990
label: "名称"
@@ -1010,7 +1010,7 @@ export const zhCNObjects: NonNullable<TranslationData['objects']> = {
10101010
},
10111011
timezone: {
10121012
label: "时区",
1013-
help: "该业务单元计算日期边界所用的 IANA 时区(如 Asia/Shanghai)。留空则依次继承上级业务单元的时区、组织的时区,最后为 UTC。"
1013+
help: "为该业务单元保存的 IANA 时区(如 Asia/Shanghai);留空则取上级业务单元的,再取组织的。它目前不会改变任何日期计算:公式、报表和显示的日期使用 设置 → 本地化 → 默认时区。"
10141014
},
10151015
organization_id: {
10161016
label: "组织",
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// The Business Unit page says what a unit does in the open edition, and what
4+
// needs the enterprise edition (#30210 row 1). It used to say units are "used
5+
// to scope data and reports", while scoping a permission set's read access by
6+
// unit (`readScope: 'unit'` and the other hierarchy scopes) is refused at
7+
// compile without `requires: ['hierarchy-security']`, which only
8+
// `@objectstack/security-enterprise` provides. What does work in the open
9+
// edition is a sharing rule naming a unit (or a unit and the units under it),
10+
// whose access follows membership in and out.
11+
//
12+
// The unit's `timezone` help used to say date boundaries are computed in it.
13+
// Nothing reads the column (the same reading as `sys_organization.timezone`,
14+
// pinned in `sys-organization-name-timezone-help.test.ts`), so the help says
15+
// which setting is in effect instead.
16+
import { describe, expect, it } from 'vitest';
17+
import { SysBusinessUnit } from './sys-business-unit.object.js';
18+
import { zhCNObjects } from '../apps/translations/zh-CN.objects.generated.js';
19+
20+
const zhUnit = () =>
21+
(zhCNObjects as unknown as Record<string, { description?: string; fields?: Record<string, { help?: string }> }>)
22+
.sys_business_unit;
23+
24+
describe('sys_business_unit: the page says what the open edition gives and what needs enterprise (#30210)', () => {
25+
it('names sharing rules as what a unit drives, and the enterprise requirement for unit-scoped read access', () => {
26+
const d = SysBusinessUnit.description ?? '';
27+
expect(d).toMatch(/[Ss]haring rules/);
28+
expect(d).toMatch(/enterprise edition/);
29+
expect(d).not.toMatch(/used to scope data and reports/);
30+
});
31+
32+
it('the zh-CN page text says the same, not the old scoping claim', () => {
33+
const d = zhUnit()?.description ?? '';
34+
expect(d).toMatch(/共享规则/);
35+
expect(d).toMatch(/企业版/);
36+
expect(d).not.toMatch(/划定数据和报表的范围/);
37+
});
38+
39+
it('the zh-CN timezone help no longer says date boundaries are computed in it', () => {
40+
const help = zhUnit()?.fields?.timezone?.help ?? '';
41+
expect(help).toMatch(/不会改变任何日期计算/);
42+
expect(help).not.toMatch(/计算日期边界所用/);
43+
});
44+
45+
it("the timezone help says it changes no date calculation and that Localization's Default timezone wins", () => {
46+
const help = (SysBusinessUnit.fields as Record<string, { description?: string }>).timezone.description ?? '';
47+
expect(help).toMatch(/does not change any date calculation/);
48+
expect(help).toMatch(/Settings → Localization → Default timezone/);
49+
expect(help).not.toMatch(/are computed in/);
50+
});
51+
});

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,17 @@ export const SysBusinessUnit = ObjectSchema.create({
3030
managedBy: 'platform',
3131
// Admin-facing copy: what the records are and what an admin does here. The
3232
// design reference (canonical org/data-partition tree, ADR-0057 D2) lives in
33-
// the docblock above, never in this string.
34-
description: 'Your company structure — divisions, departments, regions and offices — used to scope data and reports.',
33+
// the docblock above, never in this string. It says what a unit does in
34+
// the open edition (sharing rules naming a unit, whose access follows
35+
// membership in and out) and that scoping a permission set's read access by
36+
// unit (`readScope: 'unit'` and the other ADR-0057 hierarchy scopes) needs
37+
// the enterprise edition: `defineStack` refuses those scopes without
38+
// `requires: ['hierarchy-security']`, which only
39+
// @objectstack/security-enterprise provides.
40+
description:
41+
'Your company structure — divisions, departments, regions and offices. Sharing rules can share records with a unit, ' +
42+
'or a unit and the units under it: members get that access, and lose it when they leave. ' +
43+
"Letting a permission set read every record of a unit (read scope 'unit') needs the enterprise edition.",
3544
displayNameField: 'name',
3645
nameField: 'name', // [ADR-0079] canonical primary-title pointer (mirrors deprecated displayNameField)
3746
highlightFields: ['name', 'kind', 'parent_business_unit_id', 'manager_user_id'],
@@ -189,13 +198,18 @@ export const SysBusinessUnit = ObjectSchema.create({
189198
// bound unconverged). No `defaultValue`, deliberately: an explicit
190199
// default here would mean "stop inheriting", which is the opposite of what
191200
// an unset unit means.
201+
//
202+
// [#30210] Because nothing reads the column, the help says so in the
203+
// reader's terms and names the setting in effect — the same correction
204+
// `sys_organization.timezone` took (#25347). The old help said date
205+
// boundaries ARE computed in this zone, a claim no reader backed.
192206
timezone: Field.text({
193207
label: 'Timezone',
194208
required: false,
195209
maxLength: 64,
196210
valueDomain: 'iana_time_zone',
197211
description:
198-
'IANA time zone (e.g. Asia/Shanghai) date boundaries are computed in for this unit. Leave unset to inherit the parent unit\'s zone, then the organization\'s, then UTC.',
212+
'IANA time zone (e.g. Asia/Shanghai) kept for this unit; leave it empty to take the parent unit\'s, then the organization\'s. It does not change any date calculation today: formulas, reports and displayed dates use Settings → Localization → Default timezone.',
199213
group: 'Hierarchy',
200214
}),
201215

0 commit comments

Comments
 (0)