Repository navigation
Commit 99bd6d1
fix(plugin-approvals): a locked record's lines read as locked, and deleting the locked record still lands (#36135)
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
审批中的单据:它的明细行在「是否锁定」查询里也答「已锁定」,和服务端拒绝修改明细的结果一致;审批中删除整张单据又能成功,明细一起删掉、审批请求自动取消。
- 属于审批锁定的加固,替使用审批的业务用户解决「单据锁了但明细状态不一致」和「带明细的单据审批中删不掉」两个问题。
- 出错的话:要么明细被误报为锁定,要么带明细的单据删不掉;可直接撤回本次合并,只回到合并前的状态。
- 无
## What changes
The rule: **a locked record's lines are locked with it, and deleting the
locked record itself still lands.** No node switch is added and no
default moves: lines lock whenever the record's approval node locks the
record, as `main` already enforces.
- **The lock read answers for a line.** `ApprovalService.getRecordLock`
(the record-lock read behind `GET
/api/v1/approvals/records/:object/:recordId/lock` and
`client.approvals.getRecordLock`) now answers `{ locked: true }` for a
`master_detail` child row while its master is held by a locking pending
approval. It used the record-lock judgement only, so it answered `{
locked: false }` for exactly the rows the detail-row lock refuses with
`409 RECORD_LOCKED`. The new `detailRowHeldByLockingApproval` (in
`lifecycle-hooks.ts`) asks the hook's own question: the row's master
edges, read off its FK columns as SYSTEM, each judged by the one shared
lookup (`lockingRequestsForRecords`). The caller-scoped readability
anchor is unchanged, so a row the caller cannot read still answers
`null`, like a missing id.
- **Deleting the locked record lands again, with its lines.** The
delete-cancel linkage cancels a record's pending request when the record
is deleted (its ruling vetoed "forbid delete while pending"). The
detail-row lock refused the `master_detail` cascade legs of that delete,
so a locked record with lines could not be deleted (`409
RECORD_LOCKED`). The detail-row lock's `beforeDelete` now lets a cascade
leg through on one edge only. That leg carries the engine's declared
marker `ctx.referentialCascadeDelete`, and the detail object's single
cascade-capable relation must be the `master_detail` edge to the held
master, which makes the record being deleted that master. The leg must
also run inside an open unit of work: a `ctx.transaction` handle the
engine does not report closed. A delete with no open transaction is
refused whole with `409 RECORD_LOCKED`, and the record, its lines and
its pending request stay. That covers a datasource that declares
`supports.transactionsUnsupported`, a cascade across datasources, a
record and its lines together on a non-default datasource, and a handle
whose unit has already finished. Every other shape is refused too: a
junction under two cascading masters, or a line that also has a `lookup`
declaring `deleteBehavior: 'cascade'`. So deleting a different record
never removes a held record's line, with one exception. When the held
record is itself the child of a record whose delete cascades to it (a
`master_detail` child, or a `lookup` child with `deleteBehavior:
'cascade'`), deleting that parent removes the held record with its lines
and cancels its request.
- **Docs.** `content/docs/automation/approvals.mdx` now states that
lines are locked with the record (insert / update / delete / reparent,
the carried exemptions, `lookup` children untouched). It also states
what deleting the record while pending does and when that delete is
refused, that server code owning the transaction must not catch the
refusal and commit over it, and that the lock read answers for a line.
## Why
A page reads the lock to decide whether to offer an edit, so the read
must answer the same way the server refuses. And a pending record must
stay deletable, because the delete-cancel linkage is the only route left
once the record is locked.
## Tests
Each new pin was run against the base first (red), then with the fix
(green), and each guard was ablated (red) and restored (`git diff HEAD`
empty, blob equal to HEAD).
- `record-lock-read.integration.test.ts`: new top-level `describe` ("a
locked record's lines are locked with it — the record-lock read answers
for a detail row too"), 4 cases on the real
`ApprovalsServicePlugin.start()` rig, with two line objects added to it.
Base: 2 failed / 6 passed (`expected { locked: false } to deeply equal {
locked: true }`). Fix: 8 / 8. Ablating the new `||
detailRowHeldByLockingApproval(...)`: 2 failed, restored.
- `detail-row-lock.integration.test.ts`, four new top-level `describe`s:
- "… deleting the record itself still lands", 5 cases: the held record
deletes with its lines; the caller's own line delete is refused; a
different record's cascade is refused; two fail-closed shapes, a
junction under two masters and `master_detail` plus a cascading lookup,
are refused with nothing removed. Base: the delete case failed (refused
`RECORD_LOCKED`). Ablating the cascade yield: 1 failed. Ablating the
sole-edge narrowing: 1 failed.
- "… without a transaction the held record's delete is refused", 3 cases
on a sqlite driver that declares `supports.transactionsUnsupported`: a
held record with a later `restrict` row, a held record with lines only,
and a control in which an unheld record deletes. Base: 2 failed
(`DELETE_RESTRICTED`; the delete landed).
- "… a closed unit's handle is no transaction", 1 case: a cascade split
across two datasources, with a delete carrying the handle of a finished
transaction. Base: `DELETE_RESTRICTED`.
- "… a held record that is itself a detail row goes with its master", 1
case.
- Ablating the transaction check turned the two no-transaction pins red
(2 failed). Ablating the open-unit test (a closed unit's handle counted
as open) turned the closed-handle pin red (1 failed,
`DELETE_RESTRICTED`). Every ablation was restored.
- The existing insert / update / delete pins of that file were ablated
one hook registration at a time: `beforeInsert` 3 failed, `beforeUpdate`
4 failed, `beforeDelete` 2 failed, each restored.
- Whole package at `d2056107`: `pnpm --filter
@objectstack/plugin-approvals test`: 126 files / 1822 tests passed.
`typecheck` (incl. `check:test-typecheck`) OK.
## Acceptance notes
- **Withheld yield.** A locked record whose line object has a second
relation that also cascades on delete stays undeletable while pending.
So does one whose delete runs outside an open transaction. The engine
does not tell a hook which record started a cascade, and outside a
transaction a later refusal could not put the lines back. In both cases
this refuses rather than risk a held line. The docs page says so.
- **Owner of the transaction.** Inside a transaction, the refusal is
what keeps the lines. Server code that owns the transaction must not
catch the refused delete and commit anyway; the hook cannot prevent
that, and the docs state the rule.
- **Unchanged.** No node-level switch for the line lock and no change to
its default: lines lock whenever the node locks the record. Decided
documents are not locked; edits after the decision are not in this PR.
- **Pending approvers and the lines (read, measured).** The
pending-approver read grant names the master record only. On the real
service it answers `["held_sheet_a"]` for the master object and `[]` for
its line object. An approver reads lines through the line object's own
access: a `controlled_by_parent` detail follows the master's readability
(source reading, not run on a kernel), and a `private` detail owned by
the submitter is not readable to them.
- No console code changes, so no browser check is owed.
## Verification
Two-minute check: `pnpm --filter @objectstack/plugin-approvals exec
vitest run --maxWorkers=2 src/record-lock-read.integration.test.ts
src/detail-row-lock.integration.test.ts` should report 2 files and 29
tests passed.
Files to read first, by risk:
`packages/plugins/plugin-approvals/src/lifecycle-hooks.ts` (the
`cascadeSource` hunk in `bindDetailRowLockHook` and
`soleCascadeEdgeOf`), then `inOpenUnit` and
`detailRowHeldByLockingApproval` beside it, then `approval-service.ts`
`getRecordLock`.
<details><summary>Local gates at d205610 — 103 derived, 102 exit 0, 1
NOT MEASURED</summary>
Derived with `node scripts/pm/dispatch-gates.mjs --commands` at
`d2056107` and reconciled with `--ran` (exit codes recorded): "103
derived, 102 run, 1 NOT-MEASURED, 0 UNRUN". The one NOT MEASURED is
`check-plugin-teardown-shape --self-test`, refused on a local
prerequisite (exit 3, shallow clone) and left to CI. Every other derived
family exited 0, among them `check:query-options-erasure`,
`check:nul-bytes`, `check:doc-authoring`,
`check:engine-double-contract`, `check:test-source-alias`,
`check:system-context-census`, `check:i18n` and `check-empty-changeset`.
CI's own check-runs are the verdict for everything else.
</details>
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(not touched)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes. (CI owns the repo-wide
run)
- [x] 4. One task, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: not touched.
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
---
_Generated by [Claude
Code](https://claude.ai/code/session_017xRBcRtGQS7L4qLKpL8stv)_
<!-- signed: security#2 · sunhaolin · session_017xRBcRtGQS7L4qLKpL8stv
-->
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>1 parent c448c61 commit 99bd6d1
6 files changed
Lines changed: 668 additions & 10 deletions
File tree
- .changeset
- content/docs/automation
- packages/plugins/plugin-approvals/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
408 | 408 | | |
409 | 409 | | |
410 | 410 | | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
411 | 446 | | |
412 | 447 | | |
413 | 448 | | |
| |||
423 | 458 | | |
424 | 459 | | |
425 | 460 | | |
426 | | - | |
| 461 | + | |
| 462 | + | |
427 | 463 | | |
428 | 464 | | |
429 | 465 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
166 | | - | |
| 166 | + | |
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| |||
11124 | 11124 | | |
11125 | 11125 | | |
11126 | 11126 | | |
11127 | | - | |
| 11127 | + | |
| 11128 | + | |
| 11129 | + | |
| 11130 | + | |
| 11131 | + | |
11128 | 11132 | | |
11129 | 11133 | | |
11130 | 11134 | | |
| |||
11139 | 11143 | | |
11140 | 11144 | | |
11141 | 11145 | | |
11142 | | - | |
| 11146 | + | |
| 11147 | + | |
| 11148 | + | |
11143 | 11149 | | |
11144 | 11150 | | |
11145 | 11151 | | |
| |||
0 commit comments