You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 3a08833
Browse filesBrowse the repository at this point in the historyBrowse files
fix(plugin-approvals): word the record-lock refusal in the writer's locale (#34449)
Fixes#34060
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:审批锁定记录时的拒绝提示(409
RECORD_LOCKED)改为按请求语言输出,中文用户看到「项目「华东仓储客服平台实施」正在审批中,已被锁定,审批完成前无法编辑」。
- 为什么改:其它记录拒绝提示早已按请求语言返回,唯独这句永远是英文,用户在被拦住的那一刻读不懂原因。
- 风险与回滚:只换句子,错误码、409、`RECORD_LOCKED: ` 前缀和英文原句逐字不变;回滚即还原本 PR。
-
先看:`packages/plugins/plugin-approvals/src/lifecycle-hooks.ts`(`recordLockRefusal`
与
`refusalLocalization`)、`packages/spec/src/system/operation-message.ts`(四个新键的四种语言文案)、`packages/plugins/plugin-approvals/src/approvals-plugin.ts`(把
i18n 服务传给锁钩子)。
- 两分钟验证:`pnpm --filter @objectstack/plugin-approvals exec vitest run
src/record-lock-user-facing-message.test.ts`,预期全部通过,其中 zh-CN 用例断言中文句子。
- 需要你做的:无,席位落地。
## What changes
The approval record lock's per-row refusal is rendered through the
shared Operation Message Catalog (`renderOperationMessage`,
`@objectstack/spec/system`), the catalog the record door's other
refusals already use (`record_write_denied`, `record_access_denied`, and
this plugin's own `approval_recall_not_submitter`). No new mechanism.
- `packages/spec/src/system/operation-message.ts`: four keys, one wire
code, picked by what the hook has in hand: `record_locked` (`{{object}}`
and `{{title}}`), `record_locked_untitled` (`{{object}}`),
`record_locked_unlabeled` (`{{title}}`) and `record_locked_opaque`
(nothing). They ship in every locale the catalog carries (`en`, `zh-CN`,
`ja-JP`, `es-ES`), the same set as the sibling record-door refusals.
English is byte-identical to the old template literal.
- `lifecycle-hooks.ts`: `recordLockRefusal` picks the key and passes the
label and title as parameters. The locale is
`HookContext.session.locale`, which the engine copies from the request
envelope. The object label is `objects.OBJECT.label` in that locale,
read through the plugin's existing `readerLabelsFor` (negotiated, so a
bare `zh` reaches `zh-CN`). It falls back to the declared label and
never to the API name. A deployment `errors.record_locked*` override
wins, as for every catalog key.
- `approvals-plugin.ts`: `bindApprovalLockHook` takes the lazily read
`i18n` service as a new optional fourth parameter. Absent, the built-in
catalog still answers in the writer's locale.
- Unchanged: `code: RECORD_LOCKED`, `statusCode: 409`, the
`RECORD_LOCKED: ` prefix, the error's own property set, and the three
operator-facing lock refusals.
- Changeset: patch for `@objectstack/plugin-approvals` and
`@objectstack/spec`.
## Tests
- `record-lock-user-facing-message.test.ts`: a new top-level describe on
the real rig (ObjectQL, sqlite, real hook). It covers zh-CN titled and
untitled, a bare `zh`, en-US, an unknown `xx-YY` falling back to
English, no locale, no i18n service, a deployment override, and a
throwing i18n service. Each case asserts `code`, `statusCode` 409, the
prefix, and that nothing reached the store.
- `record-lock-batch-row-status.integration.test.ts`: the bulk-row path
through the real `updateManyData` and `batchData` upsert loops. The
zh-CN row carries the Chinese sentence and the en-US row carries the
existing English sentence. Both rows keep `code` and `httpStatus` 409.
- `operation-message.test.ts`: a new top-level describe. Every locale
defines the four keys with exactly their placeholders, the English is
byte-identical, and an unknown locale falls back to `en`.
## Acceptance notes
- The re-measure used a throwaway REST-level boot (`bootStack`, real
approvals and trigger plugins, a locking approval flow, a zh-CN pack
labelling the object 项目). It was run on main and on this branch and is
not committed.
- `check:platform-checklist` (red on main before #34435) is not among
this diff's derived gates. #34435 is in this branch's base, a121e29.
## Verification
<details><summary>Re-measure on main a121e29 (REST,
Accept-Language)</summary>
```text
PATCH zh-CN -> 409 {"error":"Project '华东仓储客服平台实施' is locked while an approval is in progress, and cannot be edited until that approval is complete","code":"RECORD_LOCKED",...}
updateMany zh-CN -> 207 ... "message":"RECORD_LOCKED: Project '华东仓储客服平台实施' is locked while an approval is in progress, ...","httpStatus":409
PATCH en-US -> 409 (same English sentence)
PATCH xx-YY -> 409 (same English sentence)
```
</details>
<details><summary>Same boot on this branch</summary>
```text
PATCH zh-CN -> 409 {"error":"项目「华东仓储客服平台实施」正在审批中,已被锁定,审批完成前无法编辑","code":"RECORD_LOCKED","object":"m34060_project"}
updateMany zh-CN -> 207 ... {"code":"RECORD_LOCKED","message":"RECORD_LOCKED: 项目「华东仓储客服平台实施」正在审批中,已被锁定,审批完成前无法编辑","httpStatus":409}
PATCH en-US -> 409 {"error":"Project '华东仓储客服平台实施' is locked while an approval is in progress, and cannot be edited until that approval is complete","code":"RECORD_LOCKED",...}
PATCH xx-YY -> 409 (English, as en-US)
updateMany en-US / xx-YY -> 207, row 409, English sentence
```
</details>
<details><summary>Ablation (one-off, not committed)</summary>
`node scripts/ablation-replace.mjs` replaced the hook's `locale`
argument to `recordLockRefusal` with `undefined` (anchor 1 -> 0, blob
4278df5 -> 297b98bb7ab7). It then ran both plugin test files: **7
failed | 14 passed**. All seven were the zh/zh-CN cases plus the
batch-row locale case. The English cases stayed green, as expected. The
subject is imported from `src` by relative path, so no rebuild was
needed. Restore: blob == HEAD (4278df5) and `git diff HEAD` empty.
</details>
<details><summary>Local test and gate readings at head
b5c0292</summary>
- `pnpm --filter @objectstack/plugin-approvals exec vitest run
--maxWorkers=2`: Test Files 121 passed (121), Tests 1714 passed (1714).
- `pnpm --filter @objectstack/spec exec vitest run --maxWorkers=2
src/system/operation-message.test.ts`: Tests 50 passed (50).
- `pnpm --filter @objectstack/plugin-approvals typecheck` (includes
`check:test-typecheck`): exit 0. `pnpm --filter @objectstack/spec
typecheck`: exit 0.
- `node scripts/pm/dispatch-gates.mjs --commands`: 93 commands, run in
this worktree at b5c0292. 91 exited 0 on the first pass. Two first
answered PREREQUISITE NOT MET (exit 3): `check:dual-build-cjs-loads` (no
`dist/` yet) and `check:type-check-debt` (verify-lock queue timeout).
Both were re-run: `check:type-check-debt` under the lock gave exit 0
(128/131 type-checked, 0 in DEBT), and `check:dual-build-cjs-loads`
after the full build gave exit 0 (124 entry points across 72 packages
load).
- `node scripts/pm/dispatch-gates.mjs --ran`: 93 derived, 93 run, 0
NOT-MEASURED, 0 UNRUN.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01FEkQ5kgF3mo9f7LXuv5hac)_
<!-- signed: repo:objectstack#1 · os-project-manager ·
session_01FEkQ5kgF3mo9f7LXuv5hac -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(plugin-approvals): the record-lock refusal is worded in the writer's locale
7
+
8
+
Clause-②: no
9
+
Metadata-protocol: none
10
+
11
+
A user who saved a record held by an approval in progress was refused `409 RECORD_LOCKED` with an English sentence in every locale, while the other refusals on the same request answered in the request locale. A zh-CN writer read `Project '华东仓储客服平台实施' is locked while an approval is in progress, and cannot be edited until that approval is complete`.
12
+
13
+
The sentence is now rendered through the shared Operation Message Catalog (`@objectstack/spec/system`, `renderOperationMessage`), the catalog the record door's other refusals use. Four new keys cover what the lock hook has in hand: `record_locked` (object label and record title), `record_locked_untitled` (label only), `record_locked_unlabeled` (title only) and `record_locked_opaque` (neither). They ship in `en`, `zh-CN`, `ja-JP` and `es-ES`. The object is named by its label in the writer's locale (`objects.<object>.label` from the deployment's language pack, else the declared label), never by its API name. The same zh-CN writer now reads `项目「华东仓储客服平台实施」正在审批中,已被锁定,审批完成前无法编辑`. Batch rows (`updateMany`, `batch` upsert) carry the same sentence.
14
+
15
+
Unchanged: the English sentence is byte-identical, a locale the catalog does not carry reads English, and the wire code `RECORD_LOCKED`, the 409 status and the `RECORD_LOCKED: ` message prefix do not move. A deployment can override each sentence under `errors.record_locked`, `errors.record_locked_untitled`, `errors.record_locked_unlabeled` and `errors.record_locked_opaque`.
0 commit comments