From 1606d966af041e5f73231132384a8bc70345505c Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 04:01:37 +0000 Subject: [PATCH 1/2] fix(approvals): the no-approver note names its position by its label Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5okniknzVVR3KTSVr1 --- content/docs/automation/approvals.mdx | 4 +- ...min-rescue-named-slate.integration.test.ts | 73 +++++++++++++++++ .../plugin-approvals/src/admin-rescue-note.ts | 7 +- .../plugin-approvals/src/approval-service.ts | 11 ++- .../plugin-approvals/src/no-approver-note.ts | 80 +++++++++++++++---- 5 files changed, 153 insertions(+), 22 deletions(-) diff --git a/content/docs/automation/approvals.mdx b/content/docs/automation/approvals.mdx index 51f95502a7e..eb42af2575f 100644 --- a/content/docs/automation/approvals.mdx +++ b/content/docs/automation/approvals.mdx @@ -593,7 +593,9 @@ administrator is its submitter on a step that sets `excludeSubmitter`. The server logs a warning, and the request's timeline and a notice to its submitter say that no one else can approve it yet and that an organization administrator must add a member who can (one who holds the unstaffed position, when the slate -names one). Only the admin override decides it, and never its submitter's own. +names one). The timeline's note names that position the way the note above +does: by its label for a reader, by its name in the text the row stores. Only the +admin override decides it, and never its submitter's own. ### The approver finds it in their queue diff --git a/packages/plugins/plugin-approvals/src/admin-rescue-named-slate.integration.test.ts b/packages/plugins/plugin-approvals/src/admin-rescue-named-slate.integration.test.ts index 1c8d1c4ac0f..f5da916f5a2 100644 --- a/packages/plugins/plugin-approvals/src/admin-rescue-named-slate.integration.test.ts +++ b/packages/plugins/plugin-approvals/src/admin-rescue-named-slate.integration.test.ts @@ -546,4 +546,77 @@ describe('an empty admin_rescue slate opens on the organization\'s administrator expect(served.map((a) => a.comment)).toEqual(['审批人名单未指向任何人,因此已转交本组织管理员处理:岗位「sales_manager」无人任职。']); }); }); + // [#36035] The no-approver note (an organization with no administrator opens + // on the slate that names no one) stores its position as a `type:value` + // slot, not a finished string, and names it the way the note above does: + // the reader's pack, else the declared label, else the name. + describe('[#36035] the no-approver note names its position by its label', () => { + let labelled: ApprovalService; + const declared: Record = { sales_manager: 'Sales Manager' }; + const holding = (who: string) => 'No one else can approve this request yet. An organization administrator ' + + `must add a member who holds ${who}; that member can then decide it.`; + const holdingZh = (who: string) => `目前还没有其他人能审批此请求。组织管理员需要添加一名担任 ${who} 的成员,之后由该成员决定。`; + const ENGLISH = holding("position 'sales_manager'"); + const noteFor = async (requestId: string, locale?: string) => + (await labelled.listActions(requestId, { ...as('u_sub', LEADERLESS_ORG), ...(locale ? { locale } : {}) })) + .filter((a) => a.action === 'comment' && !a.actor_id) + .map((a) => a.comment); + + beforeAll(() => { + const i18n = createMemoryI18n(); + for (const [locale, data] of Object.entries(ApprovalsTranslations)) { + i18n.loadTranslations(locale, data as Record); + } + i18n.loadTranslations('zh-CN', { positions: { sales_manager: { label: '销售经理' } } }); + labelled = new ApprovalService({ + engine: engine as any, + clock: { now: () => new Date(now += 1000) }, + logger: { warn: () => {}, info: () => {}, error: () => {}, debug: () => {} } as any, + i18nServiceSource: () => i18n, + positionLabelSource: async (name) => declared[name], + }); + }); + + it('the snapshot stores the slot, not a finished string; the row stores the English with the name', async () => { + const row = await open('none_stored', UNSTAFFED, {}, LEADERLESS_ORG); + const [note] = (await actionsOf(row.id)).filter((a) => a.action === 'comment' && !a.actor_id); + expect(note.comment).toBe(ENGLISH); + expect((await snapshotOf(row.id)).__noApproverNote).toEqual({ + action_id: note.id, slots: ['position:sales_manager'], + }); + expect(await noteFor(row.id)).toEqual([ENGLISH]); + }); + + it('a zh-CN reader reads the pack\'s label, and never the machine name', async () => { + const row = await open('none_zh', UNSTAFFED, {}, LEADERLESS_ORG); + const [comment] = await noteFor(row.id, 'zh-CN'); + expect(comment).toBe(holdingZh("position '销售经理'")); + expect(comment).not.toContain('sales_manager'); + }); + + it('a reader whose pack holds no translation reads the declared label', async () => { + const row = await open('none_declared', UNSTAFFED, {}, LEADERLESS_ORG); + expect(await noteFor(row.id, 'en')).toEqual([holding("position 'Sales Manager'")]); + const [ja] = await noteFor(row.id, 'ja-JP'); + expect(ja).toContain("position 'Sales Manager'"); + expect(ja).not.toContain('sales_manager'); + }); + + it('a position with no label anywhere keeps its internal name', async () => { + const row = await open('none_unlabelled', [{ type: 'position', value: 'treasury' }], {}, LEADERLESS_ORG); + expect(await noteFor(row.id, 'zh-CN')).toEqual([holdingZh("position 'treasury'")]); + }); + + it('CONTROL: a note written before the slot was stored renders exactly as before', async () => { + const row = await open('none_legacy', UNSTAFFED, {}, LEADERLESS_ORG); + // The stored shape of a note written before #36035: `who`, pre-composed. + const snapshot = await snapshotOf(row.id); + snapshot.__noApproverNote = { action_id: snapshot.__noApproverNote.action_id, who: "position 'sales_manager'" }; + await engine.update('sys_approval_request', { id: row.id, node_config_json: JSON.stringify(snapshot) }, + { context: SYSTEM } as any); + expect(await noteFor(row.id, 'zh-CN')).toEqual([holdingZh("position 'sales_manager'")]); + expect(await noteFor(row.id, 'en')).toEqual([ENGLISH]); + expect(await noteFor(row.id)).toEqual([ENGLISH]); + }); + }); }); diff --git a/packages/plugins/plugin-approvals/src/admin-rescue-note.ts b/packages/plugins/plugin-approvals/src/admin-rescue-note.ts index e11c9296988..9433be77489 100644 --- a/packages/plugins/plugin-approvals/src/admin-rescue-note.ts +++ b/packages/plugins/plugin-approvals/src/admin-rescue-note.ts @@ -170,8 +170,13 @@ function labelledPosition(clause: Clause, positionLabel: PositionLabelOf | undef /** The position names an admin_rescue note's abandoned slate holds, each once. */ export function adminRescuePositions(note: Pick): string[] { + return slatePositions(note.abandoned); +} + +/** [#36035] The position names a slate's `type:value` slots hold, each once: the no-approver note's too. */ +export function slatePositions(slots: readonly string[]): string[] { const names = new Set(); - for (const slot of note.abandoned) { + for (const slot of slots) { if (typeof slot === 'string' && slot.startsWith('position:') && slot.length > 'position:'.length) { names.add(slot.slice('position:'.length)); } diff --git a/packages/plugins/plugin-approvals/src/approval-service.ts b/packages/plugins/plugin-approvals/src/approval-service.ts index 3368dc9f224..f7f93d95d21 100644 --- a/packages/plugins/plugin-approvals/src/approval-service.ts +++ b/packages/plugins/plugin-approvals/src/approval-service.ts @@ -142,7 +142,9 @@ import { namesNoOneBut, noApproverNoteOf, noApproverNoteText, + noApproverPositions, noApproverSentence, + noApproverSlots, noApproverWho, type NoApproverNote, } from './no-approver-note.js'; @@ -5352,8 +5354,8 @@ export class ApprovalService implements IApprovalService, ObjectSchemaReadDelega slateSource = 'administrators'; } else { slateSource = 'no_one'; - const who = noApproverWho(approvers); - noApproverNote = { action_id: uid('aact'), ...(who ? { who } : {}) }; + const slots = noApproverSlots(approvers); + noApproverNote = { action_id: uid('aact'), ...(slots ? { slots } : {}) }; // Break-glass stays break-glass (#3424): an organization whose // administrators' slate resolves to nobody opens the request on the // slate that names no one — the only option that neither waves the @@ -11385,7 +11387,10 @@ export class ApprovalService implements IApprovalService, ObjectSchemaReadDelega const exclusion = submitterExclusionNoteOf(snapshot); if (exclusion) overlay(exclusion.action_id, () => submitterExclusionNoteText(exclusion, labels.sentence)); const noApprover = noApproverNoteOf(snapshot); - if (noApprover) overlay(noApprover.action_id, () => noApproverNoteText(noApprover, labels.sentence)); + if (noApprover) { + const positionLabels = await this.notePositionLabels(noApproverPositions(noApprover), labels); + overlay(noApprover.action_id, () => noApproverNoteText(noApprover, labels.sentence, (name) => positionLabels.get(name))); + } } /** diff --git a/packages/plugins/plugin-approvals/src/no-approver-note.ts b/packages/plugins/plugin-approvals/src/no-approver-note.ts index 2d82c1bcdfd..1788d100d2e 100644 --- a/packages/plugins/plugin-approvals/src/no-approver-note.ts +++ b/packages/plugins/plugin-approvals/src/no-approver-note.ts @@ -24,39 +24,72 @@ import { approvalMessageKey, interpolate } from './approval-notification-text.js'; import { enMessages, type ApprovalMessageId } from './translations/messages.js'; -import type { ApprovalSentenceRender } from './admin-rescue-note.js'; +import { slatePositions, type ApprovalSentenceRender, type PositionLabelOf } from './admin-rescue-note.js'; import { isPlatformAdminAddress, slateNamesAPerson } from './approver-address.js'; /** The node-config snapshot key the note rides under. */ export const NO_APPROVER_NOTE_SNAPSHOT_KEY = '__noApproverNote'; -/** The note as the request's snapshot stores it. */ +/** + * The note as the request's snapshot stores it. + * + * [#36035] A note stores the slate's literals as `slots`, the `type:value` + * references themselves, so a read can name a position by its label the way + * the administrators' note does (`adminRescueNoteText`). A note written before + * stored `who` instead: the literals pre-composed as English, which no read + * can take apart again, so it is rendered exactly as it always was. + */ export interface NoApproverNote { /** The `sys_approval_action` row (an `action: 'comment'` with no actor) this note is. */ readonly action_id: string; - /** The slate's literals, as `type 'value'`, which a member must hold; absent when it kept none. */ + /** The slate's literals, as `type:value`, which a member must hold; absent when it kept none. */ + readonly slots?: readonly string[]; + /** A note written before `slots`: the literals as `type 'value'`, read as stored. */ readonly who?: string; } -/** What the literals on `slate` ask a member to hold, or `undefined` when it holds none. */ -export function noApproverWho(slate: readonly string[]): string | undefined { - const named = slate - .filter((slot) => !!slot && slot.includes(':') && !isPlatformAdminAddress(slot)) - .map((slot) => `${slot.slice(0, slot.indexOf(':'))} '${slot.slice(slot.indexOf(':') + 1)}'`); +/** The literals on `slate` a member must hold, as `type:value`, or `undefined` when it holds none. */ +export function noApproverSlots(slate: readonly string[]): string[] | undefined { + const slots = slate.filter((slot) => !!slot && slot.includes(':') && !isPlatformAdminAddress(slot)); + return slots.length ? slots : undefined; +} + +/** + * What the literals on `slate` ask a member to hold, as `type 'value'`, or + * `undefined` when it holds none. [#36035] With `positionLabel`, a position's + * value is the label it answers; with none, or for a position it does not + * know, the position's name stands, which is the English the row stores. + */ +export function noApproverWho(slate: readonly string[], positionLabel?: PositionLabelOf): string | undefined { + const named = (noApproverSlots(slate) ?? []).map((slot) => { + const type = slot.slice(0, slot.indexOf(':')); + const value = slot.slice(slot.indexOf(':') + 1); + return `${type} '${(type === 'position' && positionLabel?.(value)) || value}'`; + }); return named.length ? named.join(', ') : undefined; } +/** [#36035] The position names a note's `slots` hold, each once; none for a note that stored `who`. */ +export function noApproverPositions(note: Pick): string[] { + return slatePositions(note.slots ?? []); +} + /** Does `slate` name no person other than `submitter`, so no one else can decide it? */ export function namesNoOneBut(slate: readonly string[], submitter: string): boolean { return !slateNamesAPerson(slate.filter((slot) => slot !== submitter)); } -/** The catalog sentence for the note, and its parameters. */ -export function noApproverSentence(note: Pick): { +/** + * The catalog sentence for the note, and its parameters. A note's `slots` are + * composed here, each position named by `positionLabel` where it knows one; a + * note that stored `who` keeps it as written. + */ +export function noApproverSentence(note: Pick, positionLabel?: PositionLabelOf): { id: ApprovalMessageId; params: Record; } { - return note.who - ? { id: 'approvalNoApproverHolding', params: { who: note.who } } + const who = note.slots ? noApproverWho(note.slots, positionLabel) : note.who; + return who + ? { id: 'approvalNoApproverHolding', params: { who } } : { id: 'approvalNoApprover', params: {} }; } @@ -64,14 +97,23 @@ export function noApproverSentence(note: Pick): { * The note's text. With no `render`, the English the row stores and the * refusal says; with one, the reader's language, or `undefined` when the pack * does not hold the sentence (the stored comment then stands). + * + * [#36035] With `positionLabel` too, a position the note's `slots` name is + * named by the label it answers, as `adminRescueNoteText` names one. The + * stored English keeps the name: it is the audit text. */ -export function noApproverNoteText(note: Pick): string; -export function noApproverNoteText(note: Pick, render: ApprovalSentenceRender): string | undefined; +export function noApproverNoteText(note: Pick): string; +export function noApproverNoteText( + note: Pick, + render: ApprovalSentenceRender, + positionLabel?: PositionLabelOf, +): string | undefined; export function noApproverNoteText( - note: Pick, + note: Pick, render?: ApprovalSentenceRender, + positionLabel?: PositionLabelOf, ): string | undefined { - const { id, params } = noApproverSentence(note); + const { id, params } = noApproverSentence(note, render ? positionLabel : undefined); return render ? render(approvalMessageKey(id), params) : interpolate(enMessages[id], params); } @@ -83,7 +125,11 @@ export function noApproverNoteOf(snapshot: unknown): NoApproverNote | undefined if (!snapshot || typeof snapshot !== 'object') return undefined; const note = (snapshot as Record)[NO_APPROVER_NOTE_SNAPSHOT_KEY]; if (!note || typeof note !== 'object') return undefined; - const { action_id, who } = note as Record; + const { action_id, slots, who } = note as Record; if (typeof action_id !== 'string' || !action_id) return undefined; + if (slots !== undefined) { + if (!Array.isArray(slots) || !slots.every((slot) => typeof slot === 'string')) return undefined; + return slots.length ? { action_id, slots } : { action_id }; + } return typeof who === 'string' && who ? { action_id, who } : { action_id }; } From 8a83eed2d557a0bde918b4d55746ba08f10a7bc6 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 04:23:15 +0000 Subject: [PATCH 2/2] chore(changeset): plugin-approvals patch for the no-approver note's label Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5okniknzVVR3KTSVr1 --- .changeset/36035-no-approver-position-label.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .changeset/36035-no-approver-position-label.md diff --git a/.changeset/36035-no-approver-position-label.md b/.changeset/36035-no-approver-position-label.md new file mode 100644 index 00000000000..ee9a102e370 --- /dev/null +++ b/.changeset/36035-no-approver-position-label.md @@ -0,0 +1,10 @@ +--- +'@objectstack/plugin-approvals': patch +--- + +fix(approvals): the no-approver note names its position by its label + +Clause-②: no +Metadata-protocol: none + +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..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.