Skip to content

Commit 83e545a

Browse files
fix(approvals): the no-approver note names its position by its label (#36306)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"} --> _Requested by **Leehom** · [project thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XP3RHGWUG7UH3fNa4tBa9UC)_ repo:objectstack#4 · os-project-manager · session_01FEkQ5okniknzVVR3KTSVr1 Fixes #36035 Clause-②: no Metadata-protocol: none ## 维护者速读 - 审批动态里「无人可审」那条系统说明不再显示岗位内部名:中文读者看到岗位的中文名(如「销售经理」),没有翻译时用岗位自己的显示名,都没有才退回内部名;英文审计原文不变。 - 接着上一轮「转交给管理员说明用岗位显示名」的修复,补上它留下的「无人可审」说明,属于控制台核心业务操作体验专题。 - 只改读取时的显示,库里存的审计原文和旧请求的说明都原样保留,转交规则不动;出问题可直接撤回。 - 无。 ## What changes 1. **The note stores its literals as a reference.** `no-approver-note.ts`: a new note stores `slots` (the slate's `type:value` literals, `noApproverSlots`) in the `__noApproverNote` snapshot entry instead of the pre-composed `who` string. `noApproverWho(slate, positionLabel?)` composes `type 'value'`, naming a position by the label `positionLabel` answers, else by its name. `noApproverSentence` / `noApproverNoteText` take an optional `positionLabel` and compose from `slots`; a note that stored `who` (written before this change) is rendered from that string exactly as before. `noApproverNoteOf` reads either shape. 2. **The read names the position the way #36030 does.** `ApprovalService.localizeRoutingNotes` builds the label map for the note's positions through the existing `notePositionLabels` (reader's pack `positions.NAME.label`, else the declared `label` from `positionLabelSource`, else nothing) and passes it to `noApproverNoteText`. No second resolver: the position-name extraction is `slatePositions`, factored out of `adminRescuePositions` in `admin-rescue-note.ts`, which now delegates to it. 3. **The stored English is unchanged.** The write site (`approval-service.ts`, one hunk) stores `slots`; the row's `comment` is still `noApproverNoteText(note)` with no render, which composes the same `position 'NAME'` English as before. The refusal remedy and the submitter's notice still compose from the slate with no labels (see Acceptance notes). 4. **Docs.** `content/docs/automation/approvals.mdx`, the no-approver paragraph: the note names the position by its label for a reader and by its name in the stored text. `approval-service.ts` carries three small hunks (import, the write line, the read line); the note module could not carry the write and the read alone. `overlap-check` is clean against #36295, #36247, #36144 and #36135, which share that file. ## Tests <details><summary>Pins: admin-rescue-named-slate.integration.test.ts, new describe "[#36035] the no-approver note names its position by its label"</summary> The suite's real `ApprovalService` on `ObjectQL` over in-memory SQLite, an organization with no administrator (so the request opens on the slate that names no one), the plugin catalog plus an app pack in a real in-memory `i18n` service, and a `positionLabelSource` declaring `sales_manager` as "Sales Manager". - the snapshot stores `{ action_id, slots: ['position:sales_manager'] }`; the row stores the English with `position 'sales_manager'`; a no-locale read is served that English; - zh-CN (pack label 销售经理) reads `...担任 position '销售经理' 的成员...` and no `sales_manager`; - en and ja-JP (no pack key) read `position 'Sales Manager'`; - a position no pack and no declaration knows (`treasury`) keeps its name; - CONTROL: a note rewritten to the old stored shape (`who: "position 'sales_manager'"`) renders exactly as before in zh-CN, en and with no locale. The pin went into the existing harness file as a sibling of the #35418 describe rather than a new file: it reuses that file's engine, organizations and `open` helper (AGENTS.md: a new pin for a component with a shared harness goes into that file). </details> <details><summary>Ablations at 8a83eed (scripts/ablation-replace.mjs, each restored to the HEAD blob with an empty git diff HEAD)</summary> - A1 read site passes no `positionLabel`: 2 failed (zh-CN pack label, declared label) / 3 passed. - A2 write site stores the composed `who` again: 3 failed (snapshot shape, zh-CN, declared) / 2 passed. - A3 an unknown position's name dropped: 3 failed (snapshot English, unlabelled name, legacy row) / 2 passed. - A4 a stored `who` no longer read: 1 failed (legacy CONTROL) / 4 passed. </details> <details><summary>Runs at 8a83eed</summary> - `pnpm --filter @objectstack/plugin-approvals test`: Test Files 126 passed (126), Tests 1813 passed (1813). - `pnpm --filter @objectstack/plugin-approvals typecheck`: exit 0 (test layer held at its ledgered debt). - eslint over the four changed source files: exit 0. </details> ## Acceptance notes - The `__noApproverNote` snapshot entry is internal to `@objectstack/plugin-approvals` (nothing in `packages/spec`, `ui/` or the package index reads it); new notes carry `slots`, older ones keep `who`, and the read accepts both. - Same family, not in this PR, carried by #36308 (class a, user-visible): the decision door's refusal remedy and the submitter's `approval.comment` notice compose the no-approver sentence from the slate with no labels, so they still name the machine name (`...holds position 'legal'...`, pinned in `exclude-submitter.integration.test.ts`). The notice is rendered per recipient at delivery, so labelling it needs the recipient's locale, not the reader's. - Observation, carried by #36308 (class a, user-visible): the `{{who}}` hole carries the approver type's English machine token in every pack, so a zh-CN reader now reads `担任 position '销售经理' 的成员`, where the administrators' note translates the type (`岗位「销售经理」`). Translating the type needs a per-type clause in all eleven catalogs; out of this card's scope. ## Verification Read first: `no-approver-note.ts` (`noApproverWho`, `noApproverSentence`, `noApproverNoteOf` — the old/new shape split), the `localizeRoutingNotes` hunk in `approval-service.ts`, the write hunk at `slateSource = 'no_one'`. Two-minute check: `pnpm --filter @objectstack/plugin-approvals exec vitest run src/admin-rescue-named-slate.integration.test.ts -t 36035` — expect 5 passed. <details><summary>Local gates at 8a83eed</summary> `node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --ran`: 103 derived families accounted for, 103 run, 0 NOT-MEASURED (a derived zero: every family recorded an exit code, all 0). Four first answered exit 3 (prerequisite) and were rerun after it was met: `check-plugin-teardown-shape --self-test` (pinned fixture commit fetched), `check:skill-examples`, `check:i18n` and `check:dual-build-cjs-loads` (after the build closure finished). `overlap-check`: clean against origin/main and 4 open PRs. CI families: not yet reported at open. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01FEkQ5okniknzVVR3KTSVr1)_ <!-- signed: repo:objectstack#4 · os-project-manager · session_01FEkQ5okniknzVVR3KTSVr1 --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 78dcb06 commit 83e545a

6 files changed

Lines changed: 163 additions & 22 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/plugin-approvals': patch
3+
---
4+
5+
fix(approvals): the no-approver note names its position by its label
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
When a request opens with no one able to approve it and its approver list names an unstaffed position, its timeline note told the reader to add "a member who holds position 'regional_manager'", with the position's internal name, in every language. The note now stores the position as a reference, so a reader is served the position's label the way the administrators' routing note names one: the reader's language pack (`positions.<name>.label`) first, else the position's declared `label`, else the name as before. The English the row stores for audit keeps the name, and a note written before this change is shown exactly as it was.

‎content/docs/automation/approvals.mdx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,9 @@ administrator is its submitter on a step that sets `excludeSubmitter`. The
593593
server logs a warning, and the request's timeline and a notice to its submitter
594594
say that no one else can approve it yet and that an organization administrator
595595
must add a member who can (one who holds the unstaffed position, when the slate
596-
names one). Only the admin override decides it, and never its submitter's own.
596+
names one). The timeline's note names that position the way the note above
597+
does: by its label for a reader, by its name in the text the row stores. Only the
598+
admin override decides it, and never its submitter's own.
597599

598600
### The approver finds it in their queue
599601

‎packages/plugins/plugin-approvals/src/admin-rescue-named-slate.integration.test.ts‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,4 +546,77 @@ describe('an empty admin_rescue slate opens on the organization\'s administrator
546546
expect(served.map((a) => a.comment)).toEqual(['审批人名单未指向任何人,因此已转交本组织管理员处理:岗位「sales_manager」无人任职。']);
547547
});
548548
});
549+
// [#36035] The no-approver note (an organization with no administrator opens
550+
// on the slate that names no one) stores its position as a `type:value`
551+
// slot, not a finished string, and names it the way the note above does:
552+
// the reader's pack, else the declared label, else the name.
553+
describe('[#36035] the no-approver note names its position by its label', () => {
554+
let labelled: ApprovalService;
555+
const declared: Record<string, string> = { sales_manager: 'Sales Manager' };
556+
const holding = (who: string) => 'No one else can approve this request yet. An organization administrator '
557+
+ `must add a member who holds ${who}; that member can then decide it.`;
558+
const holdingZh = (who: string) => `目前还没有其他人能审批此请求。组织管理员需要添加一名担任 ${who} 的成员,之后由该成员决定。`;
559+
const ENGLISH = holding("position 'sales_manager'");
560+
const noteFor = async (requestId: string, locale?: string) =>
561+
(await labelled.listActions(requestId, { ...as('u_sub', LEADERLESS_ORG), ...(locale ? { locale } : {}) }))
562+
.filter((a) => a.action === 'comment' && !a.actor_id)
563+
.map((a) => a.comment);
564+
565+
beforeAll(() => {
566+
const i18n = createMemoryI18n();
567+
for (const [locale, data] of Object.entries(ApprovalsTranslations)) {
568+
i18n.loadTranslations(locale, data as Record<string, unknown>);
569+
}
570+
i18n.loadTranslations('zh-CN', { positions: { sales_manager: { label: '销售经理' } } });
571+
labelled = new ApprovalService({
572+
engine: engine as any,
573+
clock: { now: () => new Date(now += 1000) },
574+
logger: { warn: () => {}, info: () => {}, error: () => {}, debug: () => {} } as any,
575+
i18nServiceSource: () => i18n,
576+
positionLabelSource: async (name) => declared[name],
577+
});
578+
});
579+
580+
it('the snapshot stores the slot, not a finished string; the row stores the English with the name', async () => {
581+
const row = await open('none_stored', UNSTAFFED, {}, LEADERLESS_ORG);
582+
const [note] = (await actionsOf(row.id)).filter((a) => a.action === 'comment' && !a.actor_id);
583+
expect(note.comment).toBe(ENGLISH);
584+
expect((await snapshotOf(row.id)).__noApproverNote).toEqual({
585+
action_id: note.id, slots: ['position:sales_manager'],
586+
});
587+
expect(await noteFor(row.id)).toEqual([ENGLISH]);
588+
});
589+
590+
it('a zh-CN reader reads the pack\'s label, and never the machine name', async () => {
591+
const row = await open('none_zh', UNSTAFFED, {}, LEADERLESS_ORG);
592+
const [comment] = await noteFor(row.id, 'zh-CN');
593+
expect(comment).toBe(holdingZh("position '销售经理'"));
594+
expect(comment).not.toContain('sales_manager');
595+
});
596+
597+
it('a reader whose pack holds no translation reads the declared label', async () => {
598+
const row = await open('none_declared', UNSTAFFED, {}, LEADERLESS_ORG);
599+
expect(await noteFor(row.id, 'en')).toEqual([holding("position 'Sales Manager'")]);
600+
const [ja] = await noteFor(row.id, 'ja-JP');
601+
expect(ja).toContain("position 'Sales Manager'");
602+
expect(ja).not.toContain('sales_manager');
603+
});
604+
605+
it('a position with no label anywhere keeps its internal name', async () => {
606+
const row = await open('none_unlabelled', [{ type: 'position', value: 'treasury' }], {}, LEADERLESS_ORG);
607+
expect(await noteFor(row.id, 'zh-CN')).toEqual([holdingZh("position 'treasury'")]);
608+
});
609+
610+
it('CONTROL: a note written before the slot was stored renders exactly as before', async () => {
611+
const row = await open('none_legacy', UNSTAFFED, {}, LEADERLESS_ORG);
612+
// The stored shape of a note written before #36035: `who`, pre-composed.
613+
const snapshot = await snapshotOf(row.id);
614+
snapshot.__noApproverNote = { action_id: snapshot.__noApproverNote.action_id, who: "position 'sales_manager'" };
615+
await engine.update('sys_approval_request', { id: row.id, node_config_json: JSON.stringify(snapshot) },
616+
{ context: SYSTEM } as any);
617+
expect(await noteFor(row.id, 'zh-CN')).toEqual([holdingZh("position 'sales_manager'")]);
618+
expect(await noteFor(row.id, 'en')).toEqual([ENGLISH]);
619+
expect(await noteFor(row.id)).toEqual([ENGLISH]);
620+
});
621+
});
549622
});

‎packages/plugins/plugin-approvals/src/admin-rescue-note.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,13 @@ function labelledPosition(clause: Clause, positionLabel: PositionLabelOf | undef
170170

171171
/** The position names an admin_rescue note's abandoned slate holds, each once. */
172172
export function adminRescuePositions(note: Pick<AdminRescueNote, 'abandoned'>): string[] {
173+
return slatePositions(note.abandoned);
174+
}
175+
176+
/** [#36035] The position names a slate's `type:value` slots hold, each once: the no-approver note's too. */
177+
export function slatePositions(slots: readonly string[]): string[] {
173178
const names = new Set<string>();
174-
for (const slot of note.abandoned) {
179+
for (const slot of slots) {
175180
if (typeof slot === 'string' && slot.startsWith('position:') && slot.length > 'position:'.length) {
176181
names.add(slot.slice('position:'.length));
177182
}

‎packages/plugins/plugin-approvals/src/approval-service.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ import {
142142
namesNoOneBut,
143143
noApproverNoteOf,
144144
noApproverNoteText,
145+
noApproverPositions,
145146
noApproverSentence,
147+
noApproverSlots,
146148
noApproverWho,
147149
type NoApproverNote,
148150
} from './no-approver-note.js';
@@ -5352,8 +5354,8 @@ export class ApprovalService implements IApprovalService, ObjectSchemaReadDelega
53525354
slateSource = 'administrators';
53535355
} else {
53545356
slateSource = 'no_one';
5355-
const who = noApproverWho(approvers);
5356-
noApproverNote = { action_id: uid('aact'), ...(who ? { who } : {}) };
5357+
const slots = noApproverSlots(approvers);
5358+
noApproverNote = { action_id: uid('aact'), ...(slots ? { slots } : {}) };
53575359
// Break-glass stays break-glass (#3424): an organization whose
53585360
// administrators' slate resolves to nobody opens the request on the
53595361
// slate that names no one — the only option that neither waves the
@@ -11385,7 +11387,10 @@ export class ApprovalService implements IApprovalService, ObjectSchemaReadDelega
1138511387
const exclusion = submitterExclusionNoteOf(snapshot);
1138611388
if (exclusion) overlay(exclusion.action_id, () => submitterExclusionNoteText(exclusion, labels.sentence));
1138711389
const noApprover = noApproverNoteOf(snapshot);
11388-
if (noApprover) overlay(noApprover.action_id, () => noApproverNoteText(noApprover, labels.sentence));
11390+
if (noApprover) {
11391+
const positionLabels = await this.notePositionLabels(noApproverPositions(noApprover), labels);
11392+
overlay(noApprover.action_id, () => noApproverNoteText(noApprover, labels.sentence, (name) => positionLabels.get(name)));
11393+
}
1138911394
}
1139011395

1139111396
/**

‎packages/plugins/plugin-approvals/src/no-approver-note.ts‎

Lines changed: 63 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,54 +24,96 @@
2424

2525
import { approvalMessageKey, interpolate } from './approval-notification-text.js';
2626
import { enMessages, type ApprovalMessageId } from './translations/messages.js';
27-
import type { ApprovalSentenceRender } from './admin-rescue-note.js';
27+
import { slatePositions, type ApprovalSentenceRender, type PositionLabelOf } from './admin-rescue-note.js';
2828
import { isPlatformAdminAddress, slateNamesAPerson } from './approver-address.js';
2929

3030
/** The node-config snapshot key the note rides under. */
3131
export const NO_APPROVER_NOTE_SNAPSHOT_KEY = '__noApproverNote';
3232

33-
/** The note as the request's snapshot stores it. */
33+
/**
34+
* The note as the request's snapshot stores it.
35+
*
36+
* [#36035] A note stores the slate's literals as `slots`, the `type:value`
37+
* references themselves, so a read can name a position by its label the way
38+
* the administrators' note does (`adminRescueNoteText`). A note written before
39+
* stored `who` instead: the literals pre-composed as English, which no read
40+
* can take apart again, so it is rendered exactly as it always was.
41+
*/
3442
export interface NoApproverNote {
3543
/** The `sys_approval_action` row (an `action: 'comment'` with no actor) this note is. */
3644
readonly action_id: string;
37-
/** The slate's literals, as `type 'value'`, which a member must hold; absent when it kept none. */
45+
/** The slate's literals, as `type:value`, which a member must hold; absent when it kept none. */
46+
readonly slots?: readonly string[];
47+
/** A note written before `slots`: the literals as `type 'value'`, read as stored. */
3848
readonly who?: string;
3949
}
4050

41-
/** What the literals on `slate` ask a member to hold, or `undefined` when it holds none. */
42-
export function noApproverWho(slate: readonly string[]): string | undefined {
43-
const named = slate
44-
.filter((slot) => !!slot && slot.includes(':') && !isPlatformAdminAddress(slot))
45-
.map((slot) => `${slot.slice(0, slot.indexOf(':'))} '${slot.slice(slot.indexOf(':') + 1)}'`);
51+
/** The literals on `slate` a member must hold, as `type:value`, or `undefined` when it holds none. */
52+
export function noApproverSlots(slate: readonly string[]): string[] | undefined {
53+
const slots = slate.filter((slot) => !!slot && slot.includes(':') && !isPlatformAdminAddress(slot));
54+
return slots.length ? slots : undefined;
55+
}
56+
57+
/**
58+
* What the literals on `slate` ask a member to hold, as `type 'value'`, or
59+
* `undefined` when it holds none. [#36035] With `positionLabel`, a position's
60+
* value is the label it answers; with none, or for a position it does not
61+
* know, the position's name stands, which is the English the row stores.
62+
*/
63+
export function noApproverWho(slate: readonly string[], positionLabel?: PositionLabelOf): string | undefined {
64+
const named = (noApproverSlots(slate) ?? []).map((slot) => {
65+
const type = slot.slice(0, slot.indexOf(':'));
66+
const value = slot.slice(slot.indexOf(':') + 1);
67+
return `${type} '${(type === 'position' && positionLabel?.(value)) || value}'`;
68+
});
4669
return named.length ? named.join(', ') : undefined;
4770
}
4871

72+
/** [#36035] The position names a note's `slots` hold, each once; none for a note that stored `who`. */
73+
export function noApproverPositions(note: Pick<NoApproverNote, 'slots'>): string[] {
74+
return slatePositions(note.slots ?? []);
75+
}
76+
4977
/** Does `slate` name no person other than `submitter`, so no one else can decide it? */
5078
export function namesNoOneBut(slate: readonly string[], submitter: string): boolean {
5179
return !slateNamesAPerson(slate.filter((slot) => slot !== submitter));
5280
}
5381

54-
/** The catalog sentence for the note, and its parameters. */
55-
export function noApproverSentence(note: Pick<NoApproverNote, 'who'>): {
82+
/**
83+
* The catalog sentence for the note, and its parameters. A note's `slots` are
84+
* composed here, each position named by `positionLabel` where it knows one; a
85+
* note that stored `who` keeps it as written.
86+
*/
87+
export function noApproverSentence(note: Pick<NoApproverNote, 'slots' | 'who'>, positionLabel?: PositionLabelOf): {
5688
id: ApprovalMessageId; params: Record<string, string>;
5789
} {
58-
return note.who
59-
? { id: 'approvalNoApproverHolding', params: { who: note.who } }
90+
const who = note.slots ? noApproverWho(note.slots, positionLabel) : note.who;
91+
return who
92+
? { id: 'approvalNoApproverHolding', params: { who } }
6093
: { id: 'approvalNoApprover', params: {} };
6194
}
6295

6396
/**
6497
* The note's text. With no `render`, the English the row stores and the
6598
* refusal says; with one, the reader's language, or `undefined` when the pack
6699
* does not hold the sentence (the stored comment then stands).
100+
*
101+
* [#36035] With `positionLabel` too, a position the note's `slots` name is
102+
* named by the label it answers, as `adminRescueNoteText` names one. The
103+
* stored English keeps the name: it is the audit text.
67104
*/
68-
export function noApproverNoteText(note: Pick<NoApproverNote, 'who'>): string;
69-
export function noApproverNoteText(note: Pick<NoApproverNote, 'who'>, render: ApprovalSentenceRender): string | undefined;
105+
export function noApproverNoteText(note: Pick<NoApproverNote, 'slots' | 'who'>): string;
106+
export function noApproverNoteText(
107+
note: Pick<NoApproverNote, 'slots' | 'who'>,
108+
render: ApprovalSentenceRender,
109+
positionLabel?: PositionLabelOf,
110+
): string | undefined;
70111
export function noApproverNoteText(
71-
note: Pick<NoApproverNote, 'who'>,
112+
note: Pick<NoApproverNote, 'slots' | 'who'>,
72113
render?: ApprovalSentenceRender,
114+
positionLabel?: PositionLabelOf,
73115
): string | undefined {
74-
const { id, params } = noApproverSentence(note);
116+
const { id, params } = noApproverSentence(note, render ? positionLabel : undefined);
75117
return render ? render(approvalMessageKey(id), params) : interpolate(enMessages[id], params);
76118
}
77119

@@ -83,7 +125,11 @@ export function noApproverNoteOf(snapshot: unknown): NoApproverNote | undefined
83125
if (!snapshot || typeof snapshot !== 'object') return undefined;
84126
const note = (snapshot as Record<string, unknown>)[NO_APPROVER_NOTE_SNAPSHOT_KEY];
85127
if (!note || typeof note !== 'object') return undefined;
86-
const { action_id, who } = note as Record<string, unknown>;
128+
const { action_id, slots, who } = note as Record<string, unknown>;
87129
if (typeof action_id !== 'string' || !action_id) return undefined;
130+
if (slots !== undefined) {
131+
if (!Array.isArray(slots) || !slots.every((slot) => typeof slot === 'string')) return undefined;
132+
return slots.length ? { action_id, slots } : { action_id };
133+
}
88134
return typeof who === 'string' && who ? { action_id, who } : { action_id };
89135
}

0 commit comments

Comments
 (0)