Repository navigation
fix(sharing): a declared sharing rule grants in an organization created after boot, without a restart - #37012
Conversation
…ed after boot The per-record rule hooks bound once at boot on the objects of the rules served then. Under a walled posture a declared rule is served once per existing organization, so a server that booted with no organization bound no hook on a declared rule's object, and an organization created later was served the rule with nothing to evaluate it until the next restart. The hooks now bind per object from the declarations and stored rows (SharingRuleService.listRuleHookObjects), never from the organizations a declared rule is served in at that moment; the organization is resolved when a record is evaluated. Boot and the sys_sharing_rule rebind share one binder (rebindRuleHooks). Claude-Session: https://claude.ai/code/session_01QSeKYpEsWWE9Y5YtSsDgqZ Co-authored-by: Claude <noreply@anthropic.com>
…Hooks ADR-0057 anchors the plugin's boot binding of the per-record rule hooks as sharing-plugin.ts#bindRuleHooks. Boot and the sys_sharing_rule rebind now go through one private bindRuleHooks method, which calls rebindRuleHooks. Claude-Session: https://claude.ai/code/session_01QSeKYpEsWWE9Y5YtSsDgqZ Co-authored-by: Claude <noreply@anthropic.com>
The system-context census row for the rule hooks' afterDelete elevation read is keyed to bindRuleHooks. rebindRuleHooks now hands bindRuleHooks the object set as rows, so the read stays in the symbol that row names; bindRuleHooks' rules parameter widens to the two fields it reads. Claude-Session: https://claude.ai/code/session_01QSeKYpEsWWE9Y5YtSsDgqZ Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QSeKYpEsWWE9Y5YtSsDgqZ Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 1 package(s): 11 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 1 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 12 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 098e898f4cd135e80f8e68d9028ce9866bb53efe && git checkout 098e898f4cd135e80f8e68d9028ce9866bb53efe
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin a73edb3cd784e212c7b8b21757a44c0cfed9adfe e67a0507cedb338f8669ae31e4a5e82139586a5a && git checkout -B drift-repro a73edb3cd784e212c7b8b21757a44c0cfed9adfe && git merge --no-ff e67a0507cedb338f8669ae31e4a5e82139586a5a
node scripts/docs-audit/affected-docs.mjs --json a73edb3cd784e212c7b8b21757a44c0cfed9adfe
|
|
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ 席位核对 — ACCEPT · L1 · head
|
…tstack-ai#36965) Fixes objectstack-ai#36942 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:每个环境都会自带「任务」「备忘」两个对象,普通成员默认就能新建、查看、修改(不能删除),任何应用都能把它们放进菜单;菜单和字段文字已有十一种语言。 - 为什么做:起步应用专题的第一步,平台自带任务和备忘,权限各自独立,不挂到其它记录。 - 出错会怎样:成员只看得到自己建的任务、分配给自己的任务和自己写的备忘,别人的看不到;只新增两个对象和一条成员默认权限,可以整体撤回。 - 要你做的:无。 ## What changes - `packages/platform-objects/src/work/` (new): `sys_task` and `sys_note`, ordinary customizable objects (no `isSystem`, attachments on, comment feed left on). - `sys_task`: `title` (required), `description` (rich text), `status` (`todo` / `in_progress` / `done`, default `todo`), `due_at`, `assignee_id` (user, default `current_user`), `completed_at` (read-only), and a declared `owner_id`. - `sys_note`: optional `title`, rich-text `body`, a read-only `heading` (the title, or the body's first line when the title is empty) that is the object's `nameField`, and a declared `owner_id`. - Default list views: tasks `assigned_to_me` (assignee is me, status not done, by due time), `created_by_me`, `all` (kanban by status); notes `mine`, `all`. - Sharing, the object's own only: `sharingModel: 'private'` over the declared `owner_id` (a `sys_*` object never gets the injected one; the security plugin stamps it with the creator), plus one declared sharing rule `sys_task_assignee` (the existing record-relative `field` recipient naming `assignee_id`, access `edit`). Nothing links to, grants or derives access from another record. - `completed_at` and `heading` are kept by before-write hooks (`work/hooks.ts`). They assign the platform value over the writer's, because the engine's create-side read-only strip leaves a `sys_*` object to its own guards. - `PlatformObjectsPlugin` registers both objects and the sharing rule on a manifest of their own (`com.objectstack.platform-objects.work`, project database) and installs the hooks in `start()`. A refused registration is logged at `warn`. - `member_default` (`packages/plugins/plugin-security/src/objects/default-permission-sets.ts`) grants `sys_task` and `sys_note` read, create and edit, no delete, in the `sys_comment` shape, per maintainer ruling 7131539862 (option A, verbatim 「1. objectstack-ai#36942 任务/备忘默认权限: A。」). It opens the objects; no row policy is added. The rider (a per-object update alternative for `sys_task`) is **not** added: measured below, the `owner_only_writes` floor does not refuse the assignee's edit. - `packages/spec/src/system/constants/platform-object-names.ts`: `sys_note` and `sys_task` join `PLATFORM_OBJECTS_BY_PACKAGE['platform-objects']`. - Labels: `packages/platform-objects/scripts/i18n-extract.config.ts` imports both objects; the bundles are regenerated by `node scripts/check-i18n-bundles.mjs --write` and the ten translated locales hand-written (zh-CN 任务 / 备忘, zh-Hant 任務 / 備忘, ja-JP タスク / メモ, ko 작업 / 메모, es-ES Tarea / Nota, fr Tâche / Note, de Aufgabe / Notiz, pt-BR Tarefa / Nota, ru Задача / Заметка, ar مهمة / ملاحظة), all 33 leaves per locale. Five leaves equal the English word and stay source-hashed as such: de and pt-BR `Status`, fr `Description`, `Note`, `Notes`. - `packages/cli/src/utils/organization-ownership-inventory.ts`: ADR-0131 D10 fate rows for `sys_task` and `sys_note`, beside `sys_unit`: fate `attribution`, census `PMAIN`, no anchors (members write them, the organization column is stamped from the writing context, and no parent row anchors a task or a note). Without them every `os migrate organization-ownership` / `os dev` ceremony refused with "sys_note carries organization_id but the ADR-0131 D10 inventory gives it no fate". - `packages/cli/src/commands/migrate/organization-ownership.declared-rule-mirrors.integration.test.ts`: its `servedRules` helper lists the rules served on the fixture's object (`listRules({ object: 'crm_deal' }, …)`), because platform packages declare sharing rules of their own that every boot serves (`sys_task_assignee`). Every rule the fixture declares or inserts is on `crm_deal`, so both `toEqual` assertions still count each of them exactly; nothing is loosened. The edit put the file under `check:test-source-alias`'s source-reach half, so it now also pays its two dynamic workspace loads (`@objectstack/platform-objects/system`, `@objectstack/driver-sql`) at module top, as that gate prescribes. - `scripts/platform-object-tenancy-census.json` regenerated by its generator: registered 108 → 110, in reach 57 → 59 (both `organization_id`), out of reach unchanged at 51. - Changeset, all at patch: `@objectstack/platform-objects` (the objects), `@objectstack/spec` (the registry names), `@objectstack/plugin-security` (the `member_default` grant) and `@objectstack/cli` (the two inventory fate rows). `Clause-②: yes (widening)`: `defineStack` now accepts a top-level action whose `objectName` is `sys_task` or `sys_note`, and the public surface grows; nothing narrows. `Metadata-protocol: none`, on the `sys_unit` roster-addition precedent: no metadata key, type or schema value is added, and a reference that already parsed now resolves. ## Tests - `packages/plugins/plugin-security/src/task-note-objects-36942.test.ts` (new, 6 cases, real runtime, one boot, the organization created after `bootstrap()`: `ObjectKernel` + `ObjectQLPlugin` over in-memory better-sqlite3, `PlatformObjectsPlugin`, `SecurityPlugin` with the platform sets only, `SharingServicePlugin`; members hold `member_default` and nothing else, with the positions an ordinary member holds: `user`, `org_member`, `everyone`): - both objects register from `PlatformObjectsPlugin` with no application declaring either; - `member_default` carries exactly read, create and edit, no delete and no widening bit, on both; - status to done writes `completed_at` through the engine's write path, and leaving done clears it; - a task is read by its creator and its assignee, and not by a third member, by id and by list; - a note is read by its creator only, by id and by list (the assignee of another task included); - the assignee edits the task and marks it done (`landed`, `completed_at` written, `updated_by` the assignee); the third member's edit answers `RECORD_NOT_FOUND` / 404 and the row is unchanged. - `packages/platform-objects/src/work/work-objects.test.ts` (23 cases): declarations, sharing, views, the completion stamp and the note heading as units, plugin registration and its loud refusal. - `packages/lint/src/validate-object-references.test.ts`: the item-6 pin, an app that declares neither object puts both in its navigation with `requiresObject` beside `objectName`; `defineStack` accepts it and `validateObjectReferences` reports nothing. - `packages/platform-objects/src/apps/translations/bundle-ownership.test.ts`: the bundle owns both objects, and the duplicate-label walk covers them in every locale. ## Acceptance notes **The ruling's premise holds with the grant in place.** A second member holding the same baseline reads neither another member's task nor note, by id or by list (the runtime test above). Ablation of the two `member_default` lines: 5 of the 6 cases go red (the creator's insert is refused without an object grant), and the file restores byte-identical to HEAD. **Assignee edit under the ownership floor: allowed, measured with the floor in force.** The runtime test's members carry the positions the auth layer gives an ordinary member (`user`, `org_member`, the `everyone` anchor), and `owner_only_writes` is bound to `org_member`. A one-off probe on this composition (not committed) read the update-row filter `member_default` gives the assignee on `sys_task`: `null` with no positions, `{"created_by":"usr_tn_assignee"}` with the member's positions, so the floor applies. Under it, the assignee's `update` of a task another member created still goes through (`landed`, `completed_at` written), because the `sys_task_assignee` rule's `edit` share replaces the floor as the floor's deferral to the sharing verdict says. The third member's edit is refused with `RECORD_NOT_FOUND` / 404 and the row is unchanged. So the rider's per-object alternative is not added. **Navigation entries need `requiresObject`.** `defineStack` refuses `{ type: 'object', objectName: 'sys_task' }` in an app that does not declare `sys_task`, and accepts it with `requiresObject: 'sys_task'` beside it (seat decision Q3 = A: the contract stays). The starter app (objectstack-ai#36944) spells the gate. **Found on the way, filed as objectstack-ai#36982 and fixed there (objectstack-ai#37012, merged into this branch):** a declared sharing rule wrote no per-record grants in an organization created after boot until the next boot. The runtime test now runs on ONE boot with the organization inserted after `bootstrap()`, as a fresh environment's first sign-up does, and the `sys_task_assignee` grant is still written: the assignee reads and edits the task, and the second member still reads neither the task nor the note, by id or by list. Also noted, not changed: `sys_*` objects get no recycle bin (ADR-0148), are not AI-readable unless they opt in with `aiReadable`, and are skipped by the user-deactivation "assigned work" census. The app-facing platform catalog for project authors (`skills/objectstack-project/references/platform-catalog.md`, built from a hand-kept subset) does not list either object yet; that is follow-up objectstack-ai#37058. ## Verification Read first: 1. `packages/plugins/plugin-security/src/objects/default-permission-sets.ts`: the two `member_default` lines and their ruling comment, beside `sys_comment`. 2. `packages/platform-objects/src/work/hooks.ts` › `stampTaskCompletion`: the insert branch assigns over the client value; the update branch acts only when `status` is in the write. 3. `packages/platform-objects/src/work/sharing-rules.ts`: the assignee rule (`field` recipient, `edit`). Two minutes: `pnpm --filter @objectstack/plugin-security exec vitest run src/task-note-objects-36942.test.ts` → 6 passed. <details><summary>Local readings</summary> Head `ab1bfc643c0` unless a line names another. That head merges origin/main (`719ef290776`). - `pnpm --filter @objectstack/plugin-security exec vitest run src/task-note-objects-36942.test.ts`: the members hold `user`, `org_member` and `everyone`; one boot, the organization inserted after `bootstrap()`. Test Files 1 passed, Tests 6 passed. - Floor probe (one-off file, not committed; same boot): the update-row filter `member_default` gives the assignee on `sys_task` is `null` with no positions and `{"created_by":"usr_tn_assignee"}` with the member's positions. Under that filter the assignee's update is `landed` and the third member's update is refused `RECORD_NOT_FOUND` / 404. - Ablation of the two `member_default` lines (head `f55bc30d727`): 5 failed, 1 passed; the restored blob equals HEAD. - `vitest run --project integration src/commands/migrate/organization-ownership.declared-rule-mirrors.integration.test.ts` (head `39ff0ba2a26`): 2 passed. Neighbours (head `a34239ba506`): the platform-global column drop, the `os dev` ceremony and the sqlite-wasm integration files: Test Files 3 passed, Tests 15 passed. The inventory unit test: 26 passed. - `pnpm --filter @objectstack/plugin-security test` (head `f55bc30d727`): Test Files 289 passed, Tests 7296 passed, 45 skipped. `pnpm --filter @objectstack/platform-objects test`: Test Files 126 passed, Tests 2161 passed. - Full `pnpm build` on this head: exit 0. `node scripts/pm/dispatch-gates.mjs --commands`: 106 families, all run with exit codes captured before any pipe, and all 106 exit 0. `--ran` with the codes: 106 derived, 106 run, 0 NOT-MEASURED, 0 UNRUN. The derivation warned that the tree is 2 commits behind origin/main, and that 2 derivation files changed across that range; this round makes one push only, so I did not merge again. - PR check-runs on this head: every required context is success (Test Core, Lint & Repo Gates, TypeScript Type Check, Build Core, Governed Surface Queue Guard, Type Check UI, Test UI, Build & E2E UI, Live E2E UI, Dogfood Regression Gate), and Check Changeset is success too. Lint UI was skipped. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYpEsWWE9Y5YtSsDgqZ)_ <!-- signed: repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ --> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
Fixes #36982
Clause-②: no
Metadata-protocol: none
维护者速读
What changes
SharingServicePluginbound its per-record rule hooks once at boot, on the objects of the rules it served then. Under a walled posture a declared rule is served once per organization that exists (ADR-0131 D2), so a kernel that booted with no organization bound no hook on a declared rule's object. The organization-created middleware (addDeclaredRuleScope) added the new organization's scope and bound nothing, so a record written in that organization got nosys_record_sharegrant until the next restart. It under-granted; it never over-granted.SharingRuleService.listRuleHookObjects()(new): the objects the record hooks bind on — every object an activesys_sharing_rulerow names, plus every object an active DECLARATION names, whatever organizations serve it at that moment and whatever the activation ledger says of it. The binding is per object and organization-agnostic; the organization is resolved when a record is evaluated (evaluateAllForRecordlists the projections live, each sweeping inside its own organization at the driver), so isolation is unchanged.rule-hooks.ts: newrebindRuleHooks(engine, service, logger)readslistRuleHookObjects(), then unbinds and callsbindRuleHookswith that object set; the read runs before the unbind, so a failed read keeps the previous bindings (as before).bindRuleHooks'rulesparameter widens to the two fields it reads (object_name,active), a non-breaking widening; its hook bodies are unchanged and stay in that symbol (the system-context census row keys theafterDeleteelevation read to it).sharing-plugin.ts: boot and thesys_sharing_ruledata-change rebind both go through one privatebindRuleHooksmethod (the binding site ADR-0057 anchors assharing-plugin.ts#bindRuleHooks), which callsrebindRuleHooks, so the two cannot derive different object sets. The organization-created middleware is unchanged: it still adds the scope, and the hooks already bound now serve it.Why per object rather than a rebind in the organization-created middleware: a rebind there would re-derive the hook set from the served projections each time, which is exactly the snapshot that drifted (and an unknown-scope boot, or a ledger switch, would still bind nothing). Binding from the declaration cannot drift with the organizations at all. A hook on an object no projection serves yet evaluates no rule and grants nothing.
Tests
packages/plugins/plugin-sharing/src/declared-rule-late-organization.test.ts(new, real stack, ONE boot):ObjectKernel+ObjectQLPluginover better-sqlite3 +SharingServicePlugin,isolatedposture (thetenancyservice plus the engine posture accessor the security plugin hands it), a package-declaredfieldrule (assignee_id, edit) on a private object; every organization is inserted afterbootstrap().57445a69981(expected [] to deeply equal [ ObjectContaining ]), green with the fix.organization_idB; A's watcher does not read it. Green on origin/main and with the fix.sharing-rule.test.ts(walled describe):listRuleHookObjects()names the declared rule's object with no scope, with unknown scopes, and with the rule switched off in the ledger (whilelistRulesserves nothing in each); a stored row's object joins; an inactive declaration binds nothing.rule-rebind.test.ts: mocks moved fromlistRulestolistRuleHookObjects, the rebind seam's new read; assertions unchanged.e67a0507ced(fix committed first;scripts/ablation-replace.mjs, anchor x1 to x0, blob6558c83dc6c3tod440ba76857c): the declaration loop inlistRuleHookObjectsremoved, so only served projections bind. Over the three touched suites:Tests 2 failed | 160 passed— exactly the two new pins (the one-boot late-organization case and thelistRuleHookObjectspin). Restored: blob6558c83dc6c3equals the HEAD blob,git diff HEADempty. No dist rebuild needed: the suites import the subject fromsrc.e67a0507ced:pnpm --filter @objectstack/plugin-sharing test— Test Files 78 passed, Tests 1629 passed, 11 skipped;pnpm --filter @objectstack/plugin-sharing typecheck— exit 0,check:test-typecheck: OK(the new test is in thetsconfig.test.jsonprogram,--listFilesOnly1 hit).Derived gates at e67a050
node scripts/pm/dispatch-gates.mjs --commands(7 paths vs merge base57445a699): 73 families, all run after a fullpnpm build(120 tasks, lock VERDICT command-exit 0), each exit captured before any pipe: 73 exit 0.--ran: 73 derived, 73 run, 0 NOT-MEASURED, 0 UNRUN (exit 0). On the first pass two families were red and are green now:check:adr-symbol-anchors(ADR-0057 anchors the plugin's binding site assharing-plugin.ts#bindRuleHooks; kept as the private method) andcheck:system-context-census(row 31 keys the rule hooks'afterDeleteelevation read tobindRuleHooks; the hook bodies stay in that symbol).test:repois CI's (Test Core).Acceptance notes
main, one boot should do: the declaredsys_task_assigneeobject is bound at boot from the declaration, and the organization inserted afterwards is served by those hooks. Not measured here (that test lives in plugin-security on feat(platform-objects): built-in sys_task and sys_note objects #36965's branch, outside this card's surface); left to 平台内置任务、备忘对象(第一步:不挂关联) #36942's follow-up.SharingServicePluginbut no engine posture accessor (no security plugin) reads its sharing posture as walled while the engine applies no tenant scope, so an organization-authored rule's per-record pass matches records of other organizations there. Seen while building this fixture; the fixture now sets the posture as a deployment does. No tenant wall exists in that composition either, so nothing crosses one; noted, not filed.Verification
Read first:
packages/plugins/plugin-sharing/src/sharing-rule-service.ts(listRuleHookObjects, the derivation),packages/plugins/plugin-sharing/src/rule-hooks.ts(rebindRuleHooks),packages/plugins/plugin-sharing/src/sharing-plugin.ts(the privatebindRuleHooksand its two callers).Two minutes:
pnpm --filter @objectstack/plugin-sharing exec vitest run src/declared-rule-late-organization.test.ts— expect 2 passed; onorigin/mainthe first case fails with no grant row.Generated by Claude Code