Repository navigation
Commit 16a96ac
feat(rest): Change Owner endpoint, single and bulk, gated by the object switch (#36154)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XTCm3Tiq5siADJ7ktfMSAiu)_
Fixes #35402
Clause-②: yes (widening): new error code `CHANGE_OWNER_DISABLED` (403);
new routes `POST /api/v1/data/:object/:id/change-owner` and `POST
/api/v1/data/:object/change-owner`; new client methods
`data.changeOwner` and `data.changeOwnerMany`.
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:本卡用户无感;它提供改负责人的服务端操作(单条和批量),界面按钮由后续的界面卡接上。
- 为什么做:改负责人三张卡的第二张,落实你定的「专门的改负责人操作,按对象开关开放」。
- 出错会怎样:只影响新增的改负责人请求;普通编辑和导入改负责人的规则不变,可以直接撤回。
- 要你做什么:无。
## What changes
Two new doors under the data surface. Both run as the caller, and both
read the object switch from #35401 first.
- `POST /api/v1/data/:object/:id/change-owner` with `{ ownerId | queue,
notify? }` hands one record to a person, or moves it into an ownership
queue (ADR-0142). It answers `{ object, id, ownerId, queue?, notified
}`.
- `POST /api/v1/data/:object/change-owner` with `{ ids, ownerId | queue,
notify? }` does the same for up to 500 ids, one by-id update per row. It
answers the #30205 report shape (`updated`, `failed`, `failures[]` with
each row's id, code and sentence) plus the target and `notified`. Every
row that did not move is listed; none is skipped or sampled.
Order of checks, per request:
1. The authenticated-caller floor, the closed query set (no parameters),
and the object's API exposure for `update`: the same gates every `/data`
write passes.
2. The object switch. An object the platform gives no reassignable
owner, or whose `userActions.transfer` is off (explicitly, or by the
`controlled_by_parent` default), is refused as a whole with `403
CHANGE_OWNER_DISABLED`, whoever asks, a `modifyAllRecords` holder
included, before any read or write.
3. The target. A person must be one the caller can read, and not banned
(the hand-over's own check, now shared as `assertAssignableUser`). The
check follows the write path's rule for a user reference (#29029): a
user the caller cannot read answers as one that does not exist (`404`,
`reference_not_found`), on Change Owner and on the hand-over alike. A
queue target needs the object to carry the `queue` column.
4. Each record goes through the ordinary engine update under the
caller's context. So the owner guard in the security plugin decides it
as it decides a hand edit of `owner_id`: edit on the record plus
`allowTransfer` or `modifyAllRecords`, and the ADR-0142 queue
admissions. Without the grant the answer is the data door's own `403
PERMISSION_DENIED` and the owner stays.
There is deliberately no second permission check in the endpoint. The
write gate is the same verdict the explain engine's record-level
`transfer` operation reports, so a pre-check would only restate it.
`notify: true` sends the new owner one notification under the new
`record.owner_changed` topic, naming the record (or the count, for a
bulk move). Its title rides `keyedText`
(`messages.recordOwnerChangedTitle` /
`messages.recordsOwnerChangedTitle`, the object's label itself keyed as
`objects.<object>.label`), so it renders in the new owner's own language
at delivery; the English sentence is the literal delivered when no entry
renders. It is skipped for a queue target, when the caller is the new
owner, when nothing moved, or when no messaging service is mounted. A
failing send never fails the transfer; `notified` reports what happened.
A plain `owner_id` update is untouched: the switch gates this action
only, so imports and hooks still need only the transfer grant (ruling
7000907189 point 2).
Package by package:
- `@objectstack/core`: `changeRecordOwner`, `changeRecordsOwner`,
`changeOwnerOffReason`, `changeOwnerOffRefusal`,
`CHANGE_OWNER_DISABLED`, `CHANGE_OWNER_NOTIFICATION_TOPIC`,
`CHANGE_OWNER_NOTIFICATION_TEXT`, and `assertAssignableUser` (extracted
from the assigned-work hand-over; it now reads the target through the
caller's own read first, as above).
- `@objectstack/rest`: the `change-owner-routes.ts` registrar, its two
route-ledger rows (`data-actions` family, sdk disposition), and its
entries in the REST censuses (query slots, docblock floors, objectQL
slot consumers, write-echo dispositions, hook-sentence rows, route
envelope).
- `@objectstack/client`: `data.changeOwner` and `data.changeOwnerMany`.
- `@objectstack/spec`: `CHANGE_OWNER_DISABLED` in the error-code ledger,
under `@objectstack/core` because core stamps it (the provenance gate
requires the stamping package's key). The `userActions.transfer`
liveness row is now `live`. Two docblocks (`user-action-transfer.ts`,
`object.zod.ts`) now say the endpoint reads the switch instead of
"nothing reads it yet": prose only.
- `@objectstack/service-messaging`: `record.owner_changed` in the
platform topic list, and the notice's two title entries in every shipped
locale of its `messages` bundle (the `en` entries are core's own
English, so they cannot drift).
- Docs: `content/docs/api/data-api.mdx` documents both routes, their
bodies, the 500 cap, the per-row report and `CHANGE_OWNER_DISABLED`.
The row cap is the existing `USER_WORK_TRANSFER_ROW_CAP` (500), as the
seat asked; no new constant.
## Tests
- `packages/core/src/security/change-record-owner.test.ts`: off and
ineligible objects (switched off, `controlled_by_parent` default,
`ownership: 'org'`, a `sys_*` object, a `managedBy` object) refused for
single and bulk with no engine call; the opted-in detail; unknown object
404; person and queue writes; queue on an object with no `queue` column
400; `PERMISSION_DENIED` and `RECORD_NOT_FOUND` passthrough; banned and
unknown targets; a target the caller cannot read, active or banned,
answers as unknown and its ban is never read (single, bulk, and the
hand-over); the mixed bulk report; empty, over-cap and duplicate ids
refused before any write; notify cases.
- `packages/rest/src/change-owner-routes.test.ts`: the HTTP faces, every
refusal pinned by status and code in the nested envelope, and the closed
body.
- `packages/qa/dogfood/test/change-owner-endpoint.dogfood.test.ts`: the
real showcase, real security plugin, real sharing, on the `private`
`showcase_private_note`.
## Acceptance notes
The rulings, quoted from #35315.
7000556646: "**Chosen: a dedicated Change Owner action, the Salesforce /
Dynamics 365 shape. Not a plain editable owner field.**" … "**Sharing.**
Sharing is recomputed on transfer. The previous owner's access follows
the sharing rules, not the old ownership."
7000907189, point 2: "**The switch gates the dedicated action, not the
raw write.** The Change Owner endpoint (single, bulk and cascade)
refuses an object whose switch is off. A plain `owner_id` update stays
governed by `allowTransfer` alone, so import mappings and hooks are
unaffected. An author who wants a hard block declares `owner_id`
`readonly`."
7000907189, Bulk: "The bulk form issues per-row by-id updates under the
caller's context and reports per-row failures. A predicate update
carrying `owner_id` has no pre-image and is refused by the owner guard
(`security-plugin-authz-middleware.ts` ~1778–1783). Reuse the #30205
report shape and row cap (`UserWorkTransferReport`,
`USER_WORK_TRANSFER_ROW_CAP`)."
Done-when, each pinned by code and status:
| Done-when | Answer | Where |
|---|---|---|
| Ineligible or switched-off object, even for `modifyAllRecords` | `403
CHANGE_OWNER_DISABLED`, single and bulk, owner unchanged | core unit,
rest, dogfood (admin on `showcase_invoice_line`) |
| Edit without transfer | `403 PERMISSION_DENIED`, owner unchanged; in
bulk, the row's failure code | rest, dogfood |
| Mixed bulk batch | `200` with a per-row report. Dogfood: `updated: 2,
failed: 1`, the other member's note listed as `RECORD_NOT_FOUND`. Core
and rest: one moves, a `PERMISSION_DENIED` row and a `RECORD_NOT_FOUND`
row listed | core unit, rest, dogfood |
| Queue target (ADR-0142) | `200`, `owner_id: null, queue: note_triage`;
refused `403 PERMISSION_DENIED` without the grant | core unit, dogfood |
| Notify | one `sys_notification` event for this record, delivered to
the new owner's inbox alone; title keyed | core unit, dogfood |
**Measured, not assumed:** on the showcase, after alice (holding the
transfer grant) hands her private note to bob:
- `created_by` stays alice; `owner_id` is bob.
- bob: `GET` 200, `PATCH` 200.
- alice: `GET` 404, `PATCH` 404. The `private` OWD gives her no row
access once she is not the owner, and being the creator, which the
`owner_only_writes` floor keys on, does not give it back. Read from the
code, not measured separately: the floor narrows writes on rows the
caller can already reach and grants no access of its own.
Cascade (ruling point 4) is phase 2 and not here.
Known and left as they are: a Change Owner to the record's current owner
is written like any other and counted as moved; the two route-ledger
rows carry no `responseSchema` (the client's result types are written by
hand, as for the hand-over); no pin yet for a grant holder who can read
a record but not edit it (the owner guard decides it as for a `PATCH`).
Prior rulings read:
change,owner,server,single,bulk,endpoint,gated,object,switch,per-row,report
→ 349 hits; ADR-0027 Decision §12, ADR-0081 Decision §3, ADR-0139 D4,
ADR-0029 D3, ADR-0029 D9.5, ADR-0057 D9, ADR-0061 D2, ADR-0071 Decision
§1, ADR-0093 D7; thread: none; repo: objectstack-ai/objectstack
Both counts: 349 ADR hits by keyword, 9 decisions surfaced, 0 bearing on
this change (they match on words like "change", "object" and "switch");
the rulings this change follows are the two #35315 comments above.
## Verification
Read first: `packages/core/src/security/change-record-owner.ts` (the
order of checks and the change set), then
`packages/rest/src/change-owner-routes.ts` (the refusal envelope), then
the dogfood file's MEASURED case.
Two-minute check: `pnpm --filter @objectstack/dogfood exec vitest run
test/change-owner-endpoint.dogfood.test.ts` after a dogfood closure
build. Expect 6 of 6 passing.
<details><summary>Local runs</summary>
On 06b053c:
- core `vitest run` (full): Test Files 164 passed, Tests 3810 passed.
- rest `vitest run` (full): 8 census failures on the first run, each
naming the new module; fixed and re-run: Test Files 7 passed, Tests 960
passed.
- spec error-code ledger tests 36/36; rest ledger conformance 23/23;
client URL and ledger coverage 12/12; service-messaging full 1060/1060.
- typecheck: core, rest, client, service-messaging clean.
- Derived local gates (`dispatch-gates --commands`, 127): failures found
and fixed: `check:docs`, `check:liveness`,
`check:dispatcher-error-vocabulary`, `check:engine-double-contract`; all
exit 0 on re-run. Not measurable here: `check-plugin-teardown-shape
--self-test` (shallow clone), `check:dual-build-cjs-loads` and
`check:i18n` (whole-repo build); left to CI.
Review round 1 (L1 7068420281, contract 7068497336), on the commits
after a8787f4:
- core `src/security` 75 files, 1455 tests passed; the target-read pins
fail with the caller read removed (ablation: 3 failed) and pass with it.
- rest `user-work-routes`, `change-owner-routes`, hook-sentence ledger:
730 passed.
- service-messaging translations + keyed notification text: 29 passed.
- dogfood `change-owner-endpoint.dogfood.test.ts`: 6 of 6 (lock VERDICT
command-exit 0).
- `check:where-matcher`, `check:test-source-alias`,
`check:keyed-text-bounds`, `check:i18n-stale-fill`, `check:liveness`,
`check:doc-authoring`, `check:doc-route-spelling` exit 0.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01FEkQ5pJZvcko4CsCLefrvi)_
https://claude.ai/code/session_01FEkQ5pJZvcko4CsCLefrvi
<!-- signed: repo:objectstack#4 · os-project-manager ·
session_01FEkQ5pJZvcko4CsCLefrvi -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 4ab2c82 commit 16a96ac
31 files changed
Lines changed: 1833 additions & 49 deletions
File tree
- .changeset
- content/docs
- api
- references/api
- packages
- client/src
- core/src/security
- qa/dogfood/test
- rest/src
- services/service-messaging/src
- translations
- spec
- liveness
- state-counts
- src
- api
- data
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
455 | 455 | | |
456 | 456 | | |
457 | 457 | | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
458 | 537 | | |
459 | 538 | | |
460 | 539 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
424 | 424 | | |
425 | 425 | | |
426 | 426 | | |
427 | | - | |
| 427 | + | |
428 | 428 | | |
429 | 429 | | |
430 | 430 | | |
| |||
517 | 517 | | |
518 | 518 | | |
519 | 519 | | |
| 520 | + | |
520 | 521 | | |
521 | 522 | | |
522 | 523 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
| 131 | + | |
131 | 132 | | |
132 | 133 | | |
133 | 134 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
295 | 295 | | |
296 | 296 | | |
297 | 297 | | |
| 298 | + | |
298 | 299 | | |
299 | 300 | | |
300 | 301 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
279 | 313 | | |
280 | 314 | | |
281 | 315 | | |
| |||
8255 | 8289 | | |
8256 | 8290 | | |
8257 | 8291 | | |
| 8292 | + | |
| 8293 | + | |
| 8294 | + | |
| 8295 | + | |
| 8296 | + | |
| 8297 | + | |
| 8298 | + | |
| 8299 | + | |
| 8300 | + | |
| 8301 | + | |
| 8302 | + | |
| 8303 | + | |
| 8304 | + | |
| 8305 | + | |
| 8306 | + | |
| 8307 | + | |
| 8308 | + | |
| 8309 | + | |
| 8310 | + | |
| 8311 | + | |
| 8312 | + | |
| 8313 | + | |
| 8314 | + | |
| 8315 | + | |
| 8316 | + | |
| 8317 | + | |
| 8318 | + | |
| 8319 | + | |
| 8320 | + | |
| 8321 | + | |
| 8322 | + | |
| 8323 | + | |
| 8324 | + | |
| 8325 | + | |
8258 | 8326 | | |
8259 | 8327 | | |
8260 | 8328 | | |
| |||
0 commit comments