Skip to content

Commit bfd1049

Browse files
fix(core, console): the offboarding hand-over's owner follows each object's Change Owner switch (#36869)
Fixes #35399 Clause-②: no Metadata-protocol: semantic Skills-docs: none — no file under `skills/` teaches the object switch `userActions.transfer` or the offboarding hand-over (`git grep -i 'userActions\|change owner\|assigned-work' -- skills` on the branch head hits only list-view and interface `userActions`, a different key) ## 维护者速读 - 管理员封禁用户并交接其记录时:对象关闭了“更改负责人”,该对象记录的负责人就不再交接;明细对象默认不交接,作者打开开关后照常交接。不交接的记录仍计数,弹窗写明“该对象保持负责人不变”,不再误说“该字段可填多人”。 - 属于“记录负责人变更与离职交接”专题:离职交接与“更改负责人”按同一个开关判定。 - 若判错,会多交接或少交接某对象的负责人,其他用户字段不受影响;可撤回:作者改开关即可,已交接的记录可再用“更改负责人”改回。 - 无 ## What changes - **One rule for both doors.** `userAssignedWorkFields` (`packages/core/src/security/user-assigned-work.ts`) no longer carries its own `controlled_by_parent` reading (`accessFollowsMaster` is gone). An `owner_id` that is the platform's reassignable owner (`isTransferEligible`) follows `resolveUserActionTransfer` from `@objectstack/spec/data`, the resolution `changeOwnerOffReason` refuses Change Owner by. Off by the derived default on a detail, on otherwise, author-overridable both ways. - **Counted, not moved, with a reason.** A switched-off owner is no longer left out. Its row is counted with `transferable: false` and `reason: 'transfer_off'`. A multi-valued field's row now says `reason: 'multi_valued'`. `transferUserAssignedWork` moves only `transferable` rows, so `remaining` counts only what another call could move. New exported type `UserAssignedWorkHoldReason` (`@objectstack/core`). The client's `UserAssignedWorkSummary` row gains the optional `reason` member. - **App-authored user fields are unchanged.** An approver or assignee is handed over whatever the switch says. An `owner_id` on an object the platform gives no owner (`systemFields: false`) is app-authored too. - **Optional-master corner (scope note 2): follows the switch as is.** On a switched-off detail with `required: false` master, a null-master row keeps its owner. The docblock and the admin guide say how a Modify All holder moves it by hand. - **The panel words a row by why it stays.** `UserAssignedWorkPanel` picks `console.assignedWork.ownerKept` for `transfer_off`. Only a multi-valued row keeps `notTransferable`. The new key is in all 11 UI locales: ten are hand-translated, and zh-Hant is generated from zh-Hans (`gen:zh-hant`). The existing `notTransferable` text was already the multi-valued sentence and is unchanged. - **Stale prose rewritten** (scope notes 2, N2, and 3): the `user-assigned-work.ts` docblock lead sentence (rewritten per object), `security.assignedWork.count` in `packages/client/src/index.ts`, `registerUserWorkEndpoints` in `packages/rest/src/rest-server.ts`, the admin guide's hand-over section (which this change made false), and the Change Owner paragraph of the data API page. - **N4 (scope note 7069035638):** a dogfood case for `assertAssignableUser` on the real showcase, through the Change Owner door that shares it. A new owner who exists but sits outside the caller's organization (the caller's own `GET /data/sys_user/:id` answers 404, as armed) gets the same answer as an id that exists nowhere: status, code, field, and message apart from the id. The owner stays. File surface beyond the claim's list, declared: `packages/core/src/security/index.ts` (the type export), `content/docs/permissions/administrator-guide.mdx` and `content/docs/api/data-api.mdx` (prose this change made false or incomplete). The dogfood case went into the existing Change Owner dogfood file, not a new one. ## Tests All runs at head `a31b2c96` unless named (the core, client and dogfood runs were at `21720ae6` and `285d2848`. The later commits touch only `ui/` test files, the generated zh-Hant pack and docs). - `@objectstack/core`, whole package: `Test Files 156 passed (156)`, `Tests 3740 passed (3740)`. The `[#35399]` describe has 11 cases: switch on (bare and object form), switch off (bare and object form), derived default on a detail, the twin under every other sharing model, an app-authored `owner_id` on a `systemFields: false` object, a parity pin of the roster against `resolveUserActionTransfer` and `changeOwnerOffReason` over 9 definitions, count, transfer (with no read or write naming the detail's owner), and the optional-master null-master row. The #35344 interim pin (left out of the roster) is subsumed: the same fixtures now pin counted-not-moved, as the describe's lead comment says. - `@objectstack/client`, whole package: `Test Files 59 passed (59)`, `Tests 820 passed (820)`. - `@objectstack/rest`: `src/user-work-routes.test.ts` 7/7 (only a comment changed in `rest-server.ts`). - Typecheck: `@objectstack/core`, `@objectstack/client`, `@objectstack/rest` `typecheck` exit 0 (core's runs its test-layer gate too), and `@object-ui/app-shell` `type-check` exit 0 (src and `tsconfig.test.json`), after building its dependency closure. - Dogfood, `test/change-owner-endpoint.dogfood.test.ts` on the real showcase: `Tests 7 passed (7)`, including the new N4 case. - UI: `ActionParamDialog.banAssignedWork-30205.test.tsx` 16/16 (two new `objectstack#35399` cases). `ui/packages/i18n/` whole package (`--maxWorkers=1`): `Test Files 108 passed (108)`, `Tests 2011 passed / 13 skipped`. - The i18n run first went red, and both causes are fixed in this PR. zh-Hant is generated, so it is now regenerated from zh-Hans with `gen:zh-hant` instead of hand-written. The de paired-quote pin moves 134 to 135, with its note, for the one new de pair. - **Declared narrowing:** `@object-ui/app-shell`'s whole package (2476 test files) was not run locally. One `--maxWorkers=2` attempt was stopped by its recorded PID after about 30 minutes on this shared box. CI's sharded `Test UI` runs it. ## Acceptance notes - **The nested `security.sharingModel` spot is no longer read by the hand-over.** The removed `accessFollowsMaster` read `sharingModel ?? security.sharingModel`, as the access gates do. The spec's switch default (`derivedTransferDefault`) reads only the declared top-level `sharingModel`, and `security` is not an `ObjectSchema` key. So a raw-registered object that spells its detail model only in the nested spot now hands its owner over, and Change Owner already offered the action on it. The two doors agree, and a parity pin covers this shape. `git grep` finds no producer that writes `security: { sharingModel }` outside tests on this tree, so no card is filed. If the nested spot should count, the fix is one line in the spec's `derivedTransferDefault`, and both doors follow it. - **Spec prose for the switch** (`transfer`'s `.describe` in `object.zod.ts`, the `user-action-transfer.ts` docblock) still names only the Change Owner action. Neither statement is false (the switch still does not gate a plain `owner_id` write). Adding "and the offboarding hand-over" is a `packages/spec` `.describe` edit with `gen:schema && gen:docs`, outside this claim's file surface, so it is left for the seat to route. - Behaviour change for authors, named in the changeset: an object with `userActions.transfer: false` used to have its owners handed over and now keeps them. A detail with `userActions.transfer: true` used to keep its owner and now hands it over. ## Verification Read first, by risk: 1. `packages/core/src/security/user-assigned-work.ts`: `ownerTransferOff` and the roster loop (the only rule change). 2. `packages/core/src/security/user-assigned-work.test.ts`: the `[#35399]` describe, especially the parity pin against `resolveUserActionTransfer` and `changeOwnerOffReason`. 3. `ui/packages/app-shell/src/views/UserAssignedWorkPanel.tsx`: `notTransferableKey`. Two-minute check: `pnpm --filter @objectstack/core exec vitest run src/security/user-assigned-work.test.ts` shows every `[#35399]` case green. In the console, ban a user who owns an invoice line on the showcase: the line's row says it is not handed over because the object keeps its owner, and the hand-over leaves it. <details><summary>Local gates (dispatch-gates --ran: 110 derived, 106 run, 4 NOT MEASURED, 0 UNRUN)</summary> - 106 derived families exit 0. `pnpm check:test-source-alias` went red once, on this PR's own test, which loaded the locale packs inside a test body. That load moved to module top, and the gate is green at `a31b2c96`. `pnpm --dir ui exec vitest run scripts/` was SIGKILLed once under memory pressure. Re-run alone at `a31b2c96`, it gave `Test Files 172 passed / 2 skipped`. - NOT MEASURED, exit 3 (the gate refused its own prerequisite): `check-plugin-teardown-shape --self-test` (shallow clone), `spec check:skill-examples` (no built client-react), `check:dual-build-cjs-loads` (needs a whole-tree build), `check:type-check-debt` (re-measure prerequisite). CI runs all four. - `node scripts/check-nul-bytes.mjs` exit 0 at `a31b2c96`. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYnUnriLNg19SxQdg2p)_ --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent b01d8f9 commit bfd1049

23 files changed

Lines changed: 349 additions & 98 deletions
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
'@objectstack/core': minor
3+
'@objectstack/client': minor
4+
'@objectstack/rest': minor
5+
'@object-ui/app-shell': minor
6+
'@object-ui/i18n': minor
7+
---
8+
9+
fix(core, console): a banned user's hand-over follows each object's Change Owner switch, and the ban dialog says why a record stays
10+
11+
Clause-②: no
12+
Metadata-protocol: semantic
13+
14+
An object's Change Owner switch (`userActions.transfer`) now also decides whether the offboarding hand-over (`POST /api/v1/security/users/USER_ID/assigned-work/transfer`) moves the object's `owner_id`, and how the count (`GET /api/v1/security/users/USER_ID/assigned-work`) reports it. The hand-over reads the same resolution the Change Owner action refuses by (`resolveUserActionTransfer`), so the two never disagree:
15+
16+
- An object that turns the switch off keeps its records' owners where they are. Before, the hand-over moved them.
17+
- A `controlled_by_parent` detail that leaves the switch out keeps its owner (the default is off there), as before. A detail that sets `userActions.transfer: true` now has its owner handed over like any other object. Before, every detail's owner was skipped.
18+
- The object's own user fields (an approver, an assignee) are handed over whatever the switch says.
19+
20+
A kept owner is still counted. Before, a detail's owner was left out of the count; now its row answers `transferable: false` with `reason: 'transfer_off'`. A multi-valued user field answers `reason: 'multi_valued'`. `reason` is a new optional member of each `objects[]` row in `security.assignedWork.count`'s answer (`UserAssignedWorkSummary` in `@objectstack/client`, `UserAssignedWorkHoldReason` in `@objectstack/core`). It is present exactly when `transferable` is false.
21+
22+
The ban dialog words each kept row by its reason. A kept owner reads "Not handed over: this object keeps the owner of each record (Change Owner is off for it)." (zh: 不会交接:该对象的记录负责人保持不变(该对象已关闭“更改负责人”)。). A multi-valued row keeps its own sentence ("Lists several people, so it cannot be handed over here."), and a kept owner never shows it. The new `console.assignedWork.ownerKept` key is in all eleven UI locales.
23+
24+
To keep the old hand-over of an object you switched off, set `userActions.transfer` back on for it. Before this change the switch gated only the Change Owner action; it now gates that action and the hand-over, and nothing else: a plain `owner_id` write (an import, a hook, a `PATCH`) still needs only the transfer grant.

‎content/docs/api/data-api.mdx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,10 @@ Offered only on an object the platform gives a reassignable owner and whose
472472
`userActions.transfer` switch is on. The switch defaults to on, and to off on a
473473
`controlled_by_parent` detail. Any other object is refused as a whole with
474474
`403 CHANGE_OWNER_DISABLED`, whoever asks, a `modifyAllRecords` holder
475-
included. The switch gates this action only: a plain `owner_id` update (an
476-
import, a hook, a `PATCH`) still needs the transfer grant and nothing else.
475+
included. The same switch decides whether a banned user's hand-over
476+
(`/api/v1/security/users/USER_ID/assigned-work`) moves the object's owners.
477+
It gates these two actions only: a plain `owner_id` update (an import, a hook,
478+
a `PATCH`) still needs the transfer grant and nothing else.
477479

478480
An object whose owning package is disabled is refused first, before its switch
479481
is read, with the data door's own `404 OBJECT_PACKAGE_DISABLED`: nothing is

‎content/docs/permissions/administrator-guide.mdx‎

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,29 @@ hand:
114114
validation rules and hooks apply. It answers what moved, what failed and how
115115
many remain; call it again until `remaining` is 0.
116116

117-
The owner field of a detail object (`sharingModel: 'controlled_by_parent'`)
118-
is neither counted nor moved. On a detail the owner records who did the work
119-
(the person on a timesheet, the spender on an expense line), not who holds
120-
it; handing it over would make the successor appear to have done that work.
121-
A detail row that names its master is reached through that master, so hand
122-
over the master record instead. The detail's other user fields, such as an
123-
approver, are counted and moved as usual.
124-
125-
One row class has no master to hand over: a detail row whose master reference
126-
is empty, on a detail whose master is optional (declared `required: false`).
127-
Its owner reads and writes it, beside holders of View All / Modify All on the
128-
detail. Its owner is not counted or moved either, so after the ban only View
129-
All / Modify All holders reach it. To give such rows to someone else, a holder
130-
of Modify All on the detail filters the detail by owner and edits the owner by
131-
hand.
117+
Some holdings are counted but not moved, and the count says why on each row
118+
(`transferable: false` with a `reason`):
119+
120+
- `multi_valued`: a user field that lists several people. Replacing one person
121+
in a list is a different edit from reassigning a record.
122+
- `transfer_off`: the owner field of an object whose Change Owner switch,
123+
`userActions.transfer`, is off. The hand-over follows the same switch as the
124+
Change Owner action, so an object that turns it off keeps its records'
125+
owners where they are. The switch defaults to off on a detail object
126+
(`sharingModel: 'controlled_by_parent'`): there the owner usually records
127+
who did the work (the person on a timesheet, the spender on an expense
128+
line), and a detail row that names its master is reached through that
129+
master, so hand over the master record instead. A detail whose owner really
130+
holds the record (a contact under an account) sets `userActions.transfer:
131+
true`, and the hand-over then moves its owner like any other. The rule is
132+
per object: on a switched-off detail whose master is optional (declared
133+
`required: false`), a row with an empty master reference keeps its owner
134+
too, and after the ban only holders of View All / Modify All on the detail
135+
reach it; a holder of Modify All moves it by filtering the detail by owner
136+
and editing the owner by hand.
137+
138+
The switch governs only the platform owner field: an object's other user
139+
fields, such as an approver, are counted and moved as usual.
132140

133141
The hand-over is optional and never delays the ban. Once a user is banned, a
134142
new record or edit that sets a user field to them is refused with the field

‎packages/client/src/index.ts‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,21 @@ export interface MetaItemsListOptions {
253253

254254
/**
255255
* [#30205] `security.assignedWork.count`'s answer: per object and user field,
256-
* how many records hold the user, as the caller can read them.
256+
* how many records hold the user, as the caller can read them. A row with
257+
* `transferable: false` is counted but never handed over, and `reason` says
258+
* why: `multi_valued` (a multi-valued user field) or `transfer_off` (the owner
259+
* field of an object whose Change Owner switch, `userActions.transfer`, is off).
257260
*/
258261
export interface UserAssignedWorkSummary {
259262
userId: string;
260-
objects: Array<{ object: string; field: string; count: number; transferable: boolean }>;
263+
objects: Array<{
264+
object: string;
265+
field: string;
266+
count: number;
267+
transferable: boolean;
268+
/** Why the row is not handed over; present exactly when `transferable` is false. */
269+
reason?: 'multi_valued' | 'transfer_off';
270+
}>;
261271
total: number;
262272
truncated: boolean;
263273
unreadable: string[];
@@ -7042,9 +7052,11 @@ export class ObjectStackClient {
70427052
assignedWork: {
70437053
/**
70447054
* Per object and user field (the owner field and every app user
7045-
* field), how many records hold `userId`. Objects the caller cannot
7046-
* read are named in `unreadable`; `truncated` says more fields exist
7047-
* than were counted.
7055+
* field), how many records hold `userId`, each with whether
7056+
* `transfer` moves them and, when it does not, why (`reason`): a
7057+
* multi-valued field, or the owner field of an object whose Change
7058+
* Owner switch is off. Objects the caller cannot read are named in
7059+
* `unreadable`; `truncated` says more fields exist than were counted.
70487060
*/
70497061
count: async (userId: string): Promise<UserAssignedWorkSummary> => {
70507062
const res = await this.fetch(

‎packages/core/src/security/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,7 @@ export {
693693
type UserAssignedWorkField,
694694
type UserWorkEngine,
695695
type UserAssignedWorkCount,
696+
type UserAssignedWorkHoldReason,
696697
type UserAssignedWorkSummary,
697698
type UserWorkFailureDescriber,
698699
type UserWorkTransferFailure,

0 commit comments

Comments
 (0)