Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .changeset/35418-approval-timeline-system-notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'@objectstack/plugin-approvals': patch
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
'@object-ui/console': patch
---

fix(approvals): the approval timeline names an unstaffed position by its label, and the platform's own rows read as the system's

Clause-②: yes (widening) — @objectstack/plugin-approvals adds the optional `ApprovalServiceOptions.positionLabelSource`; @object-ui/i18n adds approvalsInbox.systemActor and approvalsInbox.actSystemNote; nothing removed
Metadata-protocol: none

When a request goes to the organization's administrators because a position on its approver list has no holder, its timeline note named the position by its machine name ("岗位「crm_sales_manager」无人任职"). The note a reader is served now names it by its label: 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.

On the timeline, a row no person took read its actor as "—", and the routing, submitter-exclusion and no-approver notes read as "Commented". A row with no actor now reads its actor as "System", and a `comment` row with no actor reads as "System note". A person's comment keeps "Commented" and its author.

New locale keys: `approvalsInbox.systemActor` and `approvalsInbox.actSystemNote`, in all eleven packs.
6 changes: 5 additions & 1 deletion content/docs/automation/approvals.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,11 @@ organization's capability, such as its owner, is on the slate for that.

The request says why. Its timeline carries a note, for example *Routed to this
organization's administrators because the approver slate named no one: position
'sales_manager' has no holder.*, and its node-config snapshot keeps the abandoned
'sales_manager' has no holder.* That English, with the position's name, is what
the row stores; a reader is served the note in their own language, and it names
the position by its label (the language pack's translation, else the position's
declared label), for example *岗位「销售经理」无人任职*. The timeline shows the
note as a system note, by the system. Its node-config snapshot keeps the abandoned
slate and the same reason under `__resolvedFrom` (`admin_rescue:abandoned`,
`admin_rescue:reason`). The abandoned slate is replaced, not kept beside them: a
holder staffed into the position after the request opened does not receive it,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,4 +475,75 @@ describe('an empty admin_rescue slate opens on the organization\'s administrator
]);
});
});
// [#35418] The note names an unheld position by its label, never by its
// machine name: the reader's pack (`positions.<name>.label`) first, else the
// position's declared `label`, else the name, as before.
describe('[#35418] the note names an unheld position by its label', () => {
let labelled: ApprovalService;
const declared: Record<string, string> = { sales_manager: 'Sales Manager' };
const noteFor = async (requestId: string, locale?: string) =>
(await labelled.listActions(requestId, { ...as('u_sub', 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<string, unknown>);
}
// An app's pack, as `AppPlugin` loads it: zh-CN translates the position.
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('a zh-CN reader reads the translated label, and never the machine name', async () => {
const row = await open('label_zh', UNSTAFFED);
const [comment] = await noteFor(row.id, 'zh-CN');
expect(comment).toBe('审批人名单未指向任何人,因此已转交本组织管理员处理:岗位「销售经理」无人任职。');
expect(comment).not.toContain('sales_manager');
});

it('a reader whose pack holds no translation reads the declared label', async () => {
const row = await open('label_en', UNSTAFFED);
expect(await noteFor(row.id, 'en')).toEqual([
"Routed to this organization's administrators because the approver slate named no one: "
+ "position 'Sales Manager' has no holder.",
]);
expect((await noteFor(row.id, 'ja-JP'))[0]).toContain('役職「Sales Manager」');
});

it('CONTROL: the stored row keeps the name, and a reader with no locale is served it', async () => {
const row = await open('label_stored', UNSTAFFED);
const ENGLISH = "Routed to this organization's administrators because the approver slate named no one: "
+ "position 'sales_manager' has no holder.";
expect((await actionsOf(row.id)).find((a) => a.action === 'comment')?.comment).toBe(ENGLISH);
expect(await noteFor(row.id)).toEqual([ENGLISH]);
});

it('a position no pack and no declaration knows keeps its name, and a failing source does not fail the read', async () => {
const row = await open('label_unknown', UNSTAFFED);
const bare = new ApprovalService({
engine: engine as any,
clock: { now: () => new Date(now += 1000) },
logger: { warn: () => {}, info: () => {}, error: () => {}, debug: () => {} } as any,
i18nServiceSource: () => {
const i18n = createMemoryI18n();
for (const [locale, data] of Object.entries(ApprovalsTranslations)) {
i18n.loadTranslations(locale, data as Record<string, unknown>);
}
return i18n;
},
positionLabelSource: async () => { throw new Error('metadata exploded'); },
});
const served = (await bare.listActions(row.id, { ...as('u_sub', ORG), locale: 'zh-CN' }))
.filter((a) => a.action === 'comment' && !a.actor_id);
expect(served.map((a) => a.comment)).toEqual(['审批人名单未指向任何人,因此已转交本组织管理员处理:岗位「sales_manager」无人任职。']);
});
});
});
20 changes: 19 additions & 1 deletion packages/plugins/plugin-approvals/src/admin-rescue-note.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
*/

import { describe, it, expect } from 'vitest';
import { adminRescueNoteOf, adminRescueNoteText, adminRescueReason, type ApprovalSentenceRender } from './admin-rescue-note.js';
import {
adminRescueNoteOf, adminRescueNoteText, adminRescuePositions, adminRescueReason, type ApprovalSentenceRender,
} from './admin-rescue-note.js';
import { approvalMessages } from './translations/messages.js';

/** A render over one shipped locale of the catalog, `{{hole}}` filled the `t()` way. */
Expand Down Expand Up @@ -48,6 +50,22 @@ describe('[#25576] the admin_rescue note', () => {
expect(adminRescueNoteText(note, renderIn('zh-CN', ['approvalAdminRescueNote']))).toBeUndefined();
});

it('[#35418] names an unheld position by the label the reader is given, and only a position', () => {
const note = { abandoned: ['position:crm_sales_manager', 'position:crm_sales_director', 'team:crm_sales_manager'] };
const label = (name: string) => (name === 'crm_sales_manager' ? '销售经理' : undefined);
expect(adminRescueNoteText(note, renderIn('zh-CN'), label)).toBe(
'审批人名单未指向任何人,因此已转交本组织管理员处理:岗位「销售经理」无人任职;'
+ '岗位「crm_sales_director」无人任职;team「crm_sales_manager」未解析到任何人。',
);
// A clause the pack lacks falls back to its English, labelled the same way.
expect(adminRescueNoteText({ abandoned: ['position:crm_sales_manager'] }, renderIn('zh-CN', ['approvalAdminRescuePositionUnheld']), label))
.toBe("审批人名单未指向任何人,因此已转交本组织管理员处理:position '销售经理' has no holder。");
// The stored English keeps the name.
expect(adminRescueNoteText(note)).toContain("position 'crm_sales_manager' has no holder");
expect(adminRescuePositions({ abandoned: ['position:a', 'team:b', 'position:a', 'position:', 'u_1', 'position:c'] }))
.toEqual(['a', 'c']);
});

it('reads only the shape it writes', () => {
const good = { action_id: 'aact_1', abandoned: ['position:p'], fallback: 'not_declared' };
expect(adminRescueNoteOf({ __adminRescueNote: good })).toEqual(good);
Expand Down
32 changes: 32 additions & 0 deletions packages/plugins/plugin-approvals/src/admin-rescue-note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,32 @@ export function adminRescueReason(
.map(english).join(enMessages.approvalAdminRescueReasonSeparator);
}

/**
* [#35418] A position's display label for the reader, or `undefined` when none
* is known (the position's name then stands).
*/
export type PositionLabelOf = (positionName: string) => string | undefined;

/**
* The note's text. With no `render`, the English the row stores; with one,
* the reader's language, or `undefined` when the note sentence itself is not
* rendered (the stored comment then stands).
*
* [#35418] With `positionLabel` too, an unheld position is named by the label
* it answers (`岗位「销售经理」无人任职`), never by its machine name
* (`crm_sales_manager`), wherever one is known. The stored English keeps the
* name: it is the audit text, and it identifies the position exactly.
*/
export function adminRescueNoteText(note: Omit<AdminRescueNote, 'action_id'>): string;
export function adminRescueNoteText(
note: Omit<AdminRescueNote, 'action_id'>,
render: ApprovalSentenceRender,
positionLabel?: PositionLabelOf,
): string | undefined;
export function adminRescueNoteText(
note: Omit<AdminRescueNote, 'action_id'>,
render?: ApprovalSentenceRender,
positionLabel?: PositionLabelOf,
): string | undefined {
const clauses = reasonClauses(note.abandoned, note.fallback, note.submitter_excluded);
if (!render) {
Expand All @@ -142,11 +155,30 @@ export function adminRescueNoteText(
const separator = render(approvalMessageKey('approvalAdminRescueReasonSeparator'), {})
?? enMessages.approvalAdminRescueReasonSeparator;
const reason = clauses
.map((clause) => labelledPosition(clause, positionLabel))
.map((clause) => render(approvalMessageKey(clause.id), clause.params) ?? english(clause))
.join(separator);
return render(approvalMessageKey('approvalAdminRescueNote'), { reason });
}

/** An unheld position's clause, its `value` the position's label where `positionLabel` knows one. */
function labelledPosition(clause: Clause, positionLabel: PositionLabelOf | undefined): Clause {
if (clause.id !== 'approvalAdminRescuePositionUnheld' || !positionLabel) return clause;
const label = positionLabel(clause.params.value);
return label ? { ...clause, params: { ...clause.params, value: label } } : clause;
}

/** The position names an admin_rescue note's abandoned slate holds, each once. */
export function adminRescuePositions(note: Pick<AdminRescueNote, 'abandoned'>): string[] {
const names = new Set<string>();
for (const slot of note.abandoned) {
if (typeof slot === 'string' && slot.startsWith('position:') && slot.length > 'position:'.length) {
names.add(slot.slice('position:'.length));
}
}
return [...names];
}

/**
* The note a parsed node-config snapshot carries, or `undefined` when it
* carries none or one this module did not write (the stored comment stands).
Expand Down
45 changes: 44 additions & 1 deletion packages/plugins/plugin-approvals/src/approval-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ import {
ADMIN_RESCUE_NOTE_SNAPSHOT_KEY,
adminRescueNoteOf,
adminRescueNoteText,
adminRescuePositions,
adminRescueReason,
type AdminRescueNote,
} from './admin-rescue-note.js';
Expand Down Expand Up @@ -2074,6 +2075,17 @@ export interface ApprovalServiceOptions {
* authored text the request snapshotted when it opened.
*/
i18nServiceSource?: () => ReaderLabelI18n | undefined;
/**
* [#35418] A position's declared `label`, by its name: what a timeline note
* names an unheld position by when the reader's language pack holds no
* `positions.<name>.label`. The plugin answers it from the `metadata`
* service (`get('position', name)`), read per call for the reason
* {@link ApprovalServiceOptions.i18nServiceSource} is.
*
* Absent, or answering `undefined`, the note names the position by its
* name, as before.
*/
positionLabelSource?: (positionName: string) => Promise<string | undefined>;
/**
* [ADR-0142 D6] The `ownership-queue` service, through which a `queue`
* approver expands to the queue's members at node entry. Resolved LAZILY
Expand Down Expand Up @@ -2211,6 +2223,8 @@ export class ApprovalService implements IApprovalService, ObjectSchemaReadDelega
private readonly platformAdminStandings = new WeakMap<object, Map<string, Promise<boolean>>>();
/** [#24863] Lazily-resolved `i18n` service for the reader-locale display labels. */
private i18nServiceSource?: () => ReaderLabelI18n | undefined;
/** [#35418] A position's declared label, for a note that names an unheld position. */
private positionLabelSource?: (positionName: string) => Promise<string | undefined>;
/** [ADR-0142 D6] Lazily-resolved `ownership-queue` service a `queue` approver expands through. */
private ownershipQueues?: () => ApproverQueueSource | undefined;
/** [ADR-0157 D5] Lazily-resolved working-calendar service a `working_time` escalation counts through. */
Expand Down Expand Up @@ -2255,6 +2269,7 @@ export class ApprovalService implements IApprovalService, ObjectSchemaReadDelega
this.fieldVisibility = opts.fieldVisibility;
this.messageTranslator = opts.messageTranslator;
this.i18nServiceSource = opts.i18nServiceSource;
this.positionLabelSource = opts.positionLabelSource;
this.ownershipQueues = opts.ownershipQueues;
this.workCalendar = opts.workCalendar;
this.recordReaderVisibleObjects = new Set(
Expand Down Expand Up @@ -11346,13 +11361,41 @@ export class ApprovalService implements IApprovalService, ObjectSchemaReadDelega
if (row && text) row.comment = text;
};
const rescue = adminRescueNoteOf(snapshot);
if (rescue) overlay(rescue.action_id, () => adminRescueNoteText(rescue, labels.sentence));
if (rescue) {
const positionLabels = await this.notePositionLabels(adminRescuePositions(rescue), labels);
overlay(rescue.action_id, () => adminRescueNoteText(rescue, labels.sentence, (name) => positionLabels.get(name)));
}
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));
}

/**
* [#35418] The label a reader reads each of `positions` by: the reader's
* language pack (`positions.<name>.label`), else the position's declared
* `label` ({@link ApprovalServiceOptions.positionLabelSource}). A position
* neither answers is left out, and the note names it by its name. Display
* only: a failed read leaves the name standing, never fails the read.
*/
private async notePositionLabels(
positions: readonly string[],
labels: ReaderLabels,
): Promise<Map<string, string>> {
const out = new Map<string, string>();
for (const name of positions) {
let label = labels.positionLabel(name);
if (!label && this.positionLabelSource) {
try {
const declared = await this.positionLabelSource(name);
if (typeof declared === 'string' && declared.trim()) label = declared;
} catch { /* display-only — the name stands */ }
}
if (label) out.set(name, label);
}
return out;
}

/**
* `IFileAccessDelegate` — may this caller download a decision attachment?
* (ADR-0104 D3 wave 2; declared by `sys_approval_action.fileAccessDelegate`.)
Expand Down
12 changes: 12 additions & 0 deletions packages/plugins/plugin-approvals/src/approvals-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,18 @@ export class ApprovalsServicePlugin implements Plugin {
// object labels in the reader's locale (`reader-locale-labels.ts`).
// Without one, the door serves the labels as stored.
i18nServiceSource: i18nService,
// [#35418] A position's declared label, for the timeline note that names
// an unheld position when the reader's pack holds no translation of it.
// Resolved LAZILY for the reason the providers above are; absent, the
// note names the position by its name.
positionLabelSource: async (positionName) => {
let metadata: { get?(type: string, name: string): Promise<unknown> } | undefined;
try { metadata = ctx.getService('metadata'); } catch { return undefined; }
if (typeof metadata?.get !== 'function') return undefined;
const item = await metadata.get('position', positionName);
const label = (item as { label?: unknown } | undefined)?.label;
return typeof label === 'string' && label.trim() ? label : undefined;
},
// [ADR-0142 D6] The queue service a `queue` approver expands through.
// Resolved LAZILY for the reason the providers above are: plugin-sharing
// registers it and may start after this one. Absent, a queue approver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
flowLabelKey,
flowNameOfProcess,
localizeRequestLabels,
positionLabelKey,
readerLabelsFor,
type ReaderLabelI18n,
} from './reader-locale-labels.js';
Expand All @@ -54,6 +55,7 @@ const ZH = {
[flowLabelKey('account_approval')]: '客户审批',
[approvalStepLabelKey('account_approval', 'manager_review')]: '经理审核',
[objectLabelKey('account')]: '客户',
[positionLabelKey('crm_sales_manager')]: '销售经理',
};

describe('[#24863] every key the reader asks is one the translation contract declares', () => {
Expand All @@ -62,6 +64,7 @@ describe('[#24863] every key the reader asks is one the translation contract dec
expect(approvalStepLabelKey('account_approval', 'manager_review'))
.toBe('flows.account_approval.approvals.manager_review.label');
expect(objectLabelKey('account')).toBe('objects.account.label');
expect(positionLabelKey('crm_sales_manager')).toBe('positions.crm_sales_manager.label');
});

it('a pack holding exactly those keys parses, and keeps each value at its address', () => {
Expand All @@ -70,6 +73,7 @@ describe('[#24863] every key the reader asks is one the translation contract dec
expect(result.data.flows.account_approval.label).toBe('客户审批');
expect(result.data.flows.account_approval.approvals.manager_review.label).toBe('经理审核');
expect(result.data.objects.account.label).toBe('客户');
expect(result.data.positions.crm_sales_manager.label).toBe('销售经理');
});

it('control: the same round trip refuses a step key the face does not declare', () => {
Expand Down Expand Up @@ -98,6 +102,7 @@ describe('[#24863] the pick', () => {
expect(labels.flowLabel('account_approval')).toBe('客户审批');
expect(labels.stepLabel('account_approval', 'manager_review')).toBe('经理审核');
expect(labels.objectLabel('account')).toBe('客户');
expect(labels.positionLabel('crm_sales_manager')).toBe('销售经理');
}
});

Expand Down
Loading
Loading