Repository navigation
Commit c493adb
feat(plugin-auth): import-users assigns positions from a
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi93wBXqBG95NSfVqXRSzNT9n)_
Fixes #33113
Clause-②: yes (widening)
Metadata-protocol: none
## 维护者速读
- 改了什么:管理员批量导入用户(`POST /api/v1/auth/admin/import-users`)新增一列
`positions`(岗位机器名,多个用 `;` 分隔),用户建好后第二遍逐个指派岗位;控制台用户导入向导多了这一列和一句列说明。
- 为什么改:按裁决 6920428750「C,只加岗位列」,托管演示组织和真实客户都能用一份 CSV
建好带岗位、带上级的人员,下游应用不再自写建账号脚本。
- 风险与回滚:只加不减,不带 `positions` 列的文件行为不变;岗位按管理员自己的权限写入,和 Setup
里指派岗位走同一套校验;回滚即还原本 PR。
- 先看:`packages/plugins/plugin-auth/src/admin-import-users.ts` 的
`assignRowPositions` 与第二遍循环;同文件 `grantBlocked` 那段(缺 seam
或管理员自身上下文解析不出时,用户照建,只把每个岗位逐行记为被拒,code 分别是 `NOT_IMPLEMENTED` /
`PERMISSION_DENIED`);`auth-plugin.ts` 新增的一行 `createGrant`。
- 两分钟验证:`pnpm --filter @objectstack/plugin-auth exec vitest run
src/admin-import-users-manager-pass.test.ts -t positions`,预期 13 例全绿。
- 需要你做的:无,席位落地。
## What changes
`POST /api/v1/auth/admin/import-users` admits one new column,
`positions`, per the maintainer's ruling 6920428750 (verbatim:
「C,只加岗位列,p1」).
- **The column.** `positions` holds position machine names, several
separated by `;` (an array on a JSON row). The name and spelling are the
ones `admin/import-sso-users` already reads
(`packages/plugins/plugin-auth/src/pending-sso-users.ts:188` and `:590`
on `main`, documented at
`content/docs/permissions/authentication.mdx:1294`), so one CSV shape
serves both identity import doors. Reading of the ruling: 「只加岗位列」 limits
the import to this one new column; it does not limit the column to one
value, since a user may hold several positions and the sibling door's
column already carries a list. The cell is parsed by the one reader both
doors now import (`name-list-cell.ts`, moved out of
`pending-sso-users.ts` unchanged and not re-exported from the package
index).
- **Second pass, like `manager_id`.** The cell is stripped before the
identity write and assigned after `runImport` returns, beside the
manager pass, so every row of the batch exists.
- **Same checks as Setup.** Each assignment is a `sys_user_position`
insert through the data engine under the importing administrator's own
execution context, through the `createGrant` seam create-user and the
pending doors already use (`auth-plugin.ts` gains one line wiring it
into this mount). The position catalog refusal, the
delegated-administration gate and the grant-holder membership refusal
judge it as they judge Setup's form; none is re-derived in the importer.
- **Per row, the user still created.** `rows[].positions` lists each
named position with `assigned`, `already_assigned` (an upserted user who
already holds it; nothing written), `unresolved` (the refusal is the
catalog's `fields[].field === 'position'` / `reference_not_found`) or
`refused` (any other refusal, with its `code`). A cell that is not a
list reads `'unreadable'`. The sentence rides `rows[].error` when free;
no `rows[].code` is stamped, for the manager pass's documented reason.
`summary.positions` counts `{ assigned, alreadyAssigned, unresolved,
refused }`, and the run-level audit row carries the same split. The
import only adds positions.
- **A host that cannot judge the grant costs the positions, never the
users.** When the host wires no grant seam, or the caller's own
execution context does not resolve, the users are still created (`200`,
the answer `main` gives the same file) and every named position is
reported `refused` on its row, with code `NOT_IMPLEMENTED` (no seam) or
`PERMISSION_DENIED` (no context), counted under
`summary.positions.refused`; nothing is written to `sys_user_position`.
Dry runs do not assign, and a dry run answers as `main` does. The open
question was first read as **A** at L1 review (refuse the whole file
`501` / `403` before any write; a reading, not a ruling, and withdrawn
in L1 comment 6936586013) and is now **per row**, because A narrowed the
same input: on `main` that file answers `200` and creates the users (see
Acceptance notes, FROM). Per row is also what ruling 6920428750 says of
a position that cannot be assigned.
- **No permission-set column** (ADR-0090: a position carries its sets).
`demoStaff` is untouched and stays development-only.
- **Console.** The Users import wizard offers `positions` as a target
column, and its options panel explains it
(`console.identityImport.positionsHint`, added to all 11
`@object-ui/i18n` packs, as `all-locales-key-parity` requires).
- **Docs.** `content/docs/permissions/authentication.mdx` › Bulk Import
Users documents the column and its outcomes, including that an
unreadable cell's `rows[].positions` is the string `'unreadable'`
(counted under `summary.positions.unresolved`), not an array, and that
positions which cannot be judged at all are refused per row
(`NOT_IMPLEMENTED` / `PERMISSION_DENIED`) while the users are still
created.
## Tests
-
`packages/plugins/plugin-auth/src/admin-import-users-manager-pass.test.ts`:
the existing harness gains an optional grant seam and a
`sys_user_position` insert double that refuses an unknown name the way
the catalog refusal does and a denied one with `PERMISSION_DENIED` —
only for non-system writes, so a system-context write would slip past it
and fail the assertions. A new top-level `describe` holds 13 cases:
assignment under the administrator's context after the last create; CSV
`;` parsing; unresolved per row with every other row landing; refused
with the code; `already_assigned` on upsert; unreadable cell; the cell
never reaching `createUser`; no seam needed without the column; a **FROM
control** (the file measured on `main`, on a host with no seam: `200`,
both users created, `summary.errors: 0`, both rows `ok`); no seam →
every named position `refused` / `NOT_IMPLEMENTED` on its row, the row
without the column untouched, `summary.positions.refused: 3`, nothing
written; no context → `refused` / `PERMISSION_DENIED`, the user created
and `ok`; a dry run with no seam answers `200` with nothing written and
no refusal; dry run assigns nothing.
-
`ui/packages/app-shell/src/views/__tests__/identityImportFields.emailRule-11913.test.tsx`:
a new top-level `describe` pins the `positions` target column and the
options-panel hint.
- No existing assertion was changed. The manager-pass harness gained an
optional grant seam and a `sys_user_position` double; its existing cases
are untouched.
## Acceptance notes
- **FROM, measured on `origin/main` d4c0c12.** `main`'s
`admin-import-users.ts`, driven with a `sys_user` declaration reader and
two rows carrying a non-empty `positions` cell (`sales_rep`;
`sales_rep;area_manager`), answered `200`, `summary.created: 2`,
`errors: 0`, both rows `ok: true` / `created`, as JSON rows and as CSV;
`createUser` received only `email` and `name`. The dry run answered
`200`, two rows `created`, nothing written. So on `main` the column is
**silently dropped and the users are created**. Against that FROM this
PR only widens: the column now assigns positions, and every input that
answered `200` and created users on `main` still does. An earlier
revision of this PR refused that file whole (`501` on a host with no
grant seam, `403` when the caller's own context does not resolve), which
narrowed the same input; that revision is withdrawn. Those two cases now
create the users as `main` does and report each named position `refused`
(`NOT_IMPLEMENTED` / `PERMISSION_DENIED`) on its row; the FROM control
test pins the `200` and the created users. Hence `Clause-②: yes
(widening)` with no `(narrowing)` arm.
- Scope of the acceptance: a single-organization deployment, where an
imported user is given the default organization's membership by the
`user.create.after` reconciler before the position is written. In
multi-organization mode `import-users` does not join the importing
admin's current organization (unlike create-user), so the grant-holder
membership refusal answers each position `refused` / `VALIDATION_FAILED`
on its row; the user is still created. Filed: #34535.
- The Console import wizard offers no `manager_id` target column today,
although the endpoint has admitted it since its own ruling; filed:
#34536.
- The skills that teach the import are a separate `domain:skills` card,
per the claim; filed: #34537.
- The tenant-audit census page and its counts file move by one write
call site (the new grant insert); the figures are re-measured, not
edited by hand.
- `already_assigned` reads an existing hold by `(user_id, position)`
regardless of organization, for upserted rows only.
## Verification
<details><summary>Targeted tests</summary>
- `pnpm --filter @objectstack/plugin-auth exec vitest run --maxWorkers=2
src/admin-import-users-manager-pass.test.ts
src/pending-sso-users.test.ts src/admin-import-users.test.ts` → `Test
Files 3 passed (3)`, `Tests 151 passed (151)` (VERDICT command-exit 0,
r3 head).
- `pnpm --filter @objectstack/plugin-auth test` → `Test Files 280 passed
(280)`, `Tests 5780 passed | 10 skipped (5790)` (r3 head).
- `pnpm --filter @objectstack/plugin-auth typecheck` → exit 0;
`check:test-typecheck: OK` (r3 head).
- `ui`: `vitest run` of `identityImport.test.ts`,
`identityImportFields.emailRule-11913.test.tsx`,
`identityImport.csvBatches-13315.test.tsx` and all of `packages/i18n/` →
`Test Files 105 passed (105)`, `Tests 1924 passed | 13 skipped` (VERDICT
command-exit 0, r1; r3 does not touch `ui/`). The zh-Hant line is the
generator's output (`node scripts/gen-zh-hant.mjs`), and the de line
avoids a quote pair so the `de-quote-pairing` count pin stays as it is.
- `pnpm --filter @object-ui/i18n type-check && pnpm --filter
@object-ui/app-shell type-check` → VERDICT command-exit 0.
</details>
<details><summary>Ablations (each mutation landed on disk via
scripts/ablation-replace.mjs, then restored to the HEAD blob)</summary>
1. (r1) Assignment written under `SYSTEM_CTX` instead of the
administrator's context → 3 cases red (the context assertion and the two
refusal cases, since the checks stand down for system writes).
2. (r1) Second pass skipped → 6 red.
3. (r3) The withdrawn whole-file refusal restored (an early `return
fail(501, 'NOT_IMPLEMENTED', …)` when the file names positions and no
seam is wired) → 2 red: the FROM control and the per-row
`NOT_IMPLEMENTED` case.
4. (r3) The per-row refusal branch disabled (`if (grantBlocked &&
false)`) → 2 red: the `NOT_IMPLEMENTED` and `PERMISSION_DENIED` cases.
</details>
<details><summary>Derived gates</summary>
`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 111 commands on head d3c32ee (r1),
on the r2 head d69957c, and on the r3 head 987b7e7 (after the
per-row change and a merge of `main`; `packages/spec` was rebuilt first
because the merge moved its sources); each was run with stdin closed and
its exit captured before any pipe: all 111 exit 0 on each head. On r3,
`pnpm --dir ui exec vitest run scripts/` first exited 1 on one 15 s test
timeout (`check-i18n-call-site-keys.test.ts` › main passes exactly the
arguments…) while the plugin-auth full suite shared the box; the file
alone then passed 152/152, and the whole family re-run on an idle box
exited 0, which is the exit recorded. `--ran` reconciliation on each
head: `111 derived, 111 run, 0 NOT-MEASURED, 0 UNRUN`.
`check:tenant-audit-census` first read the new `sys_user_position`
insert as one more engine write call site (321 → 322); the generated
tables were rewritten with `node scripts/tenant-audit-census.mjs
--write` and the page's hand-written figures moved by one in the same
commit (`content/docs/permissions/tenant-audit-census.mdx`,
`docs/audits/2026-08-tenant-audit-write-call-sites.counts.md`). Every
family CI runs is read from this PR's check runs.
</details>
<!-- signed: repo:objectstack#2 · os-steve ·
session_01ADHkmRXuRn93HphKp7kXEz -->
---------
Co-authored-by: Claude <noreply@anthropic.com>positions column (#34531)1 parent 8dd8192 commit c493adb
22 files changed
Lines changed: 659 additions & 45 deletions
File tree
- .changeset
- content/docs/permissions
- docs/audits
- packages/plugins/plugin-auth/src
- ui/packages
- app-shell/src/views
- __tests__
- i18n/src/locales
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1269 | 1269 | | |
1270 | 1270 | | |
1271 | 1271 | | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
1272 | 1295 | | |
1273 | 1296 | | |
1274 | 1297 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
| 96 | + | |
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
| 135 | + | |
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
200 | | - | |
| 200 | + | |
201 | 201 | | |
202 | | - | |
203 | | - | |
| 202 | + | |
| 203 | + | |
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
213 | | - | |
| 213 | + | |
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
220 | | - | |
| 220 | + | |
221 | 221 | | |
222 | 222 | | |
223 | 223 | | |
224 | | - | |
| 224 | + | |
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
| |||
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
236 | | - | |
237 | | - | |
| 236 | + | |
| 237 | + | |
238 | 238 | | |
239 | | - | |
| 239 | + | |
240 | 240 | | |
241 | | - | |
| 241 | + | |
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
248 | | - | |
| 248 | + | |
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
253 | | - | |
| 253 | + | |
254 | 254 | | |
255 | 255 | | |
256 | 256 | | |
257 | | - | |
| 257 | + | |
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
| |||
307 | 307 | | |
308 | 308 | | |
309 | 309 | | |
310 | | - | |
| 310 | + | |
311 | 311 | | |
312 | 312 | | |
313 | 313 | | |
314 | | - | |
315 | | - | |
| 314 | + | |
| 315 | + | |
316 | 316 | | |
317 | | - | |
| 317 | + | |
318 | 318 | | |
319 | 319 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
| 36 | + | |
| 37 | + | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
| 93 | + | |
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
98 | | - | |
| 97 | + | |
| 98 | + | |
99 | 99 | | |
100 | | - | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
| 141 | + | |
141 | 142 | | |
142 | 143 | | |
143 | 144 | | |
| |||
0 commit comments