Repository navigation
Commit 909c8c9
fix(service-settings): a locked settings row binds every writer below the platform rung, at its own scope too (#28617)
<!-- claude-projects-attribution: {"github_login":"marchtian"} -->
_Requested by **田騏** · [project
thread](https://claude.ai/code/project/chan_01VmuUhXU9SSUzqJYyXSmYSi?thread=cmsg_01VmuUhXU9SSUzqJYyXSmYSi9paTx1Lu8ENYwwssthfK3h)_
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:设置行上的「锁定」现在对本组织管理员同样生效——组织管理员保存(或重置)本组织已被平台锁定的设置会被拒(409
SETTINGS_LOCKED,原因
locked-by-tenant);已锁定的全局设置行同样只有平台能改。平台管理员(manage_platform_settings)和系统内部调用仍可写入,写完锁定保持不变。
- 为什么改:按裁决「LOCKED = platform-locked; an org admin's save of a LOCKED
settings row is
refused.」加固:锁定是平台的决定,不该由被锁的组织自己改掉;设置页早已把这类字段显示为锁定,现在保存端与显示一致。
- 风险与回滚:只改 `@objectstack/service-settings` 的写入预检和内存存储的更新合并;读取接口不变;目前没有
HTTP 入口能给行加锁,只有已由系统写入锁定的行才会出现新的拒绝。回滚就是 revert 本 PR。
- 先看:`packages/services/service-settings/src/settings-service.ts` 的
`lockThatRefuses` / `writesAsPlatform` 两个新方法与 `setMany` 预检里调用它们的两处;然后是
`settings-organization-isolation.pin.test.ts` 新增的两个 describe 块。
- 两分钟验证:`pnpm --filter @objectstack/service-settings exec vitest run
src/settings-organization-isolation.pin.test.ts`,预期 36 个测试全过(新增 13 个,含经由
PUT 路由的 409 与 200 两条)。
- 需要你做的:无,席位落地。
## What changes
A locked settings row is platform-locked, and it now binds every writer
below the platform rung — at an upper rung as before, and at the write's
own rung too.
- `SettingsService.setMany`'s lock pre-flight is one judgment,
`lockThatRefuses(candidates, scope, platformRung)`, over the rows the
caller's cascade reads lock state from (the global row, and the tenant
row its reach prefers):
- a locked row at an **upper** rung refuses every write below it, the
platform's included (unchanged);
- a locked row at the write's **own** rung refuses every writer but the
platform rung. For a tenant-scope key that is the organization's own
locked tenant row (`locked-by-tenant`); for a global-scope key, the
locked global row (`locked-by-global`).
- The platform rung is `writesAsPlatform(ctx)`: a trusted in-process
caller (`enforced` unset — the seed/boot paths `assertPermitted` already
lets through, and the system write that sets a lock), or an enforced
caller holding `manage_platform_settings`, the capability every
platform-scope settings manifest writes behind. An organization
administrator holds `setup.write` and nothing more, so a lock binds it.
- The platform's write through a lock leaves the row locked: the
engine's update never carried `locked`; the in-memory store now merges
an update the same way (`{ ...previous, ...row }`) instead of replacing
the row, so the lock survives there too.
- The user rung carries no lock, on purpose: the cascade has never read
a user row's `locked` (`resolveKeyFromRows`), so `get()` reports none
and the pre-flight judges none — the two sides agree.
- The read side is unchanged. `get()`, `getMany()` and `getNamespace()`
already reported these rows as `locked: true`, and the Console's
settings page already rendered the field disabled; what they report as
locked is now exactly what a non-platform save is refused on.
- `content/docs/protocol/kernel/config-resolution.mdx` states the rule;
a `patch` changeset for `@objectstack/service-settings`.
## Tests
New pins in
`packages/services/service-settings/src/settings-organization-isolation.pin.test.ts`,
over a real `ObjectQL` engine (Map driver) through the plugin's own
engine adapter, under the `isolated` posture:
- `a locked row binds every writer below the platform rung` (11): the
organization administrator's save over its own locked tenant row is
refused (`SETTINGS_LOCKED`, `reason: 'locked-by-tenant'`, value and lock
unchanged); a reset over it, through `setMany` and through the built-in
`reset` action, is refused the same way; `get` / `getMany` /
`getNamespace` all report `locked: true` for that caller; the platform
administrator writes through and the row stays locked (and still binds
the organization administrator afterwards); a trusted in-process caller
writes through; another organization's administrator is not bound; an
unlocked row is saved over as before; a locked global row refuses a
non-platform write of a global key and the platform administrator writes
through it; a locked upper rung still refuses the platform
administrator's write below it; the user rung carries no lock; the
in-memory store keeps the lock through the platform's write.
- `the settings route answers a locked row the way the service does`
(2), through `registerSettingsRoutes` `PUT /api/settings/:namespace`
with the shipped `company` manifest: the organization administrator's
PUT is `409` with `error.code: 'SETTINGS_LOCKED'` and `details: {
namespace, key, reason: 'locked-by-tenant' }`, the value unchanged; the
platform administrator's PUT is `200`, and another organization's
administrator's PUT is `200`.
- The existing pin `a lock on one organization's tenant row does not
lock another organization's write` passes unchanged.
## Acceptance notes
- No same-meaning pin needed flipping: a sweep of `packages/**`, `ui/**`
and `examples/**` tests found no assertion that a same-rung locked row
accepts a write; the whole `service-settings` suite stays green
unchanged.
- A namespace reset (`resetNamespace`) is refused whole when any key it
would clear carries a lock that binds the caller — the shape it already
had for a locked global row over a tenant key.
- The platform administrator still sees a same-rung locked field as
locked in the Console (the read reports `locked: true` to every caller),
while the API accepts its save — the shape a globally-locked global key
already had. The read is not made caller-relative here.
## Verification
<details><summary>Red first, green, ablation</summary>
- Red, on `bca27ad3f1` with only the test file changed: `Tests 7 failed
| 29 passed (36)` — the seven refusal pins failed, every control passed.
- Green at `67ae5e93bc`: `Tests 36 passed (36)`; at `34942f02d8` the
whole package `Test Files 67 passed (67) · Tests 1120 passed (1120)`,
`tsc --noEmit` exit 0.
- Ablations through `scripts/ablation-replace.mjs` (mutation landed,
restored to the HEAD blob, `git diff HEAD` empty each time):
1. the own-rung clause removed from `lockThatRefuses` → 7 failed;
2. `writesAsPlatform` answering `false` for a `manage_platform_settings`
holder → 4 failed (every platform write-through pin);
3. the in-memory merge reverted to a replacement → 1 failed (the
in-memory pin).
</details>
<details><summary>Gates</summary>
All at head `34942f02d8` (after merging `origin/main` at `310cb96d76`,
which touched nothing in this package's closure):
- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 90 families; every one was run with
its exit code captured before any pipe, after a full `pnpm turbo run
build` (118/118 tasks): all 90 exited 0.
- `--ran` reconciliation: `90 derived, 90 run, 0 NOT-MEASURED, 0 UNRUN`
(a derived zero: every line carries its exit code).
- `pnpm --filter @objectstack/service-settings test`: `Test Files 67
passed (67) · Tests 1120 passed (1120)`; `pnpm --filter
@objectstack/service-settings typecheck` (`tsc --noEmit`, its program
includes `src/**/*.test.ts`): exit 0.
- Dogfood battery: not run — no `!` in the title and no `(narrowing)`
arm.
</details>
Session: https://claude.ai/code/session_017ihL2gLghEqeDKTbDTC7Zd
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 40e7bfc commit 909c8c9
4 files changed
Lines changed: 372 additions & 25 deletions
File tree
- .changeset
- content/docs/protocol/kernel
- packages/services/service-settings/src
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
79 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
80 | 86 | | |
81 | 87 | | |
82 | 88 | | |
| |||
213 | 219 | | |
214 | 220 | | |
215 | 221 | | |
216 | | - | |
| 222 | + | |
217 | 223 | | |
218 | 224 | | |
219 | 225 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
27 | 34 | | |
28 | 35 | | |
29 | 36 | | |
| |||
44 | 51 | | |
45 | 52 | | |
46 | 53 | | |
47 | | - | |
| 54 | + | |
| 55 | + | |
48 | 56 | | |
49 | 57 | | |
50 | 58 | | |
51 | 59 | | |
52 | 60 | | |
53 | 61 | | |
54 | 62 | | |
| 63 | + | |
| 64 | + | |
55 | 65 | | |
56 | 66 | | |
57 | 67 | | |
| |||
294 | 304 | | |
295 | 305 | | |
296 | 306 | | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 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 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 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 | + | |
| 537 | + | |
297 | 538 | | |
298 | 539 | | |
299 | 540 | | |
| |||
0 commit comments