Skip to content

Commit a03c3d4

Browse files
feat(plugin-approvals): approval steps reach the record activity stream as approval feed items (#37188)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBEaJzgBWzjWCNjBjkVoeRto)_ Fixes #35723 repo:objectstack#3 · os-support-ai · session_01WGufzg3KqwSpt61Y8ovKK7 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:在走审批的记录详情页「动态」里,每个审批步骤(提交、通过、驳回、退回修改、重新提交、撤回、取消)都显示为一行,按读者的语言显示(中文读者看到「已批准 · 经理审批」),点「看审批」直接打开该记录的「审批」页签;以前这里看不到任何审批。 - 为什么做:记录详情页专题里「动态流审批一行」那一半——上一张卡只画了这一行的样子,但没有任何地方产出审批条目,这张卡补上产出方。 - 出错会怎样:最坏情况是动态里少了或多了审批行,或某行显示成英文;审批本身、审批页签和锁定都不受影响。撤回本 PR 后,已写入的审批行仍在动态表里保留最多 14 天,且失去本 PR 的可见性限制,会以普通系统行的样子展示给所有能看该记录的人。 - 要你做什么:无 ## What changes - **Producer (plugin-approvals, new module `approval-activity-feed.ts`).** An `afterInsert` hook on the decision log `sys_approval_action` appends one `sys_activity` row per step of kind `submit`, `approve`, `reject`, `revise` (sent back for revision), `resubmit`, `recall` and `cancel`, about the record the request governs. Other kinds (reminder, reassign, thread comment, ...) write none, and no decision comment rides on the row. An object with `enable.activities: false` gets no entry, as the CRUD mirror writes none for it. Shape follows ADR-0052 section 5, so no published vocabulary moves: `type: 'system'` (platform-only; the app activity door refuses it), `metadata.kind: 'approval'` plus the step's action, its stored label and the two machine names its label is translated by (`flow_name`, `step_name`), `source_object: 'sys_approval_request'` / `source_id` naming the request. - **In the reader's language (route b, round 2).** `summary` stores the English sentence from plugin-approvals' own catalog (`approvalActivity*` in `translations/messages.ts`, ten ids added to all eleven shipped packs); a new `sys_activity` middleware (`bindApprovalActivityLocale`) re-composes it on `find` / `findOne` for a non-system read that carries a locale, with the approvals door's own lookup (`readerLabelsFor`): the sentence is `messages.approvalActivity*` in the reader's locale, and the step label is `flows.FLOW.approvals.NODE.label` read the way the approvals tab reads it, else the stored label. A list that projects `summary` alone borrows the recognition columns and hands back only what it asked for. A system read, a read with no locale or no `i18n` service, or a key the pack misses serves the stored line. No `sys_activity` on the deployment (no plugin-audit) means no write; a failed append never fails the step and is logged once at `error` with consequence and fix. `approval-service.ts` is untouched (overlap with PR #37145 and branch `claude/project-thread-x90m5y` avoided). - **Read gate (same module).** A `sys_activity` middleware narrows `find` / `findOne` / `count` / `aggregate` so an approval row is served only when the approvals service would serve the caller its request (`RequestVisibilitySource`, the same source the request-table gates read). A read pinning `object_name` + `record_id` asks with that record, so an object that opts into `enable.approvalsVisibleToReaders` serves its readers too. Every non-approval row passes untouched; plugin-audit's parent-record gate still applies on top; failure to resolve fails closed for approval rows only. Count and rows agree. - **Console (plugin-detail).** `activityRowToFeedItem` reads the triple `type: 'system'` + `metadata.kind: 'approval'` + `source_object: 'sys_approval_request'` as the `approval` feed kind (`APPROVAL_ACTIVITY_FEED_TYPE`), so `PRODUCED_FEED_TYPES` now contains `approval` and the unproduced-kind diagnostic no longer names it. New `RecordViewApprovalsContext` carries the stream's 「看审批」 callback into `RecordActivityRenderer` and `RecordChatterPanel`. - **Host (app-shell `RecordDetailView`).** The approval tag's opener is extracted as `openRecordApprovals` (approvals panel if drawn, else the 审批 tab) and supplied through `RecordViewApprovalsContext` only when the reader is served approvals; otherwise the line has no link. - **Docs.** `content/docs/frontend/plugins/plugin-detail.mdx`: `approval` joins the produced-kinds table (six produced, seven not); the unproduced example becomes `call`. - **Ledgers.** `approver-address-readers.test.ts` classifies the two new `actor_id` reads as `display`; the tenant-audit write census for plugin-approvals is regenerated (one new elevated `sys_activity` insert); `content/docs/permissions/system-context.mdx` row 17 owns the new middleware's `isSystem` read (its register regenerated with `--write`). ## Round 2 (L1 REWORK on dc76347) - **S1, route (b): the server re-composes on read.** It is the #26167 precedent's own shape: plugin-audit's `activity-summary-message.ts` stores the sentence plus its code and re-composes it per reader in a `sys_activity` middleware, and this row's code is already on it (`metadata.action`, now with `flow_name` / `step_name`). The step label must be translated through the app's flows pack, which lives in the server's `i18n` service and is read by the approvals door's `reader-locale-labels` lookup; the console holds no such pack. Server-side, every reader of the column (the record page, the API, an export) gets the same line, and no console locale pack moves. Pinned for a zh-CN reader: `已批准 · 经理审批` and `已提交审批`, with the step label from an app flows pack. - **S2:** handled by the zone (claim amended). - **N1:** done in the same code path: `revise`, `resubmit` and `cancel` write entries (`Sent back for revision · STEP`, `Resubmitted for approval`, `Approval request cancelled`, the last attributed to no one), each pinned. - **N2:** the flag is honored, as the CRUD mirror honors it (`audit-writers.ts` writes no activity row for an object with `enable.activities: false`); pinned. - **N3:** the step half is pinned exactly (`Approved · Manager review`, `Rejected · Manager review`), plus the stored metadata. - **N4:** the 维护者速读 revert sentence now says rows already written stay up to 14 days and, without the read gate, are served to every record reader as generic system lines. ## Tests <details><summary>Readings, round 2 (head 06a3c76)</summary> All local runs went through `scripts/pm/os-verify-lock.sh`; verdict lines quoted. Round-2 head `06a3c7640b` (after merging `origin/main` at `93bd45957b`). - `pnpm --filter @objectstack/plugin-approvals exec vitest run` + `typecheck` (head `06a3c764` minus the cancel pin): `Test Files 129 passed (129)`, `Tests 1929 passed (1929)`, `check:test-typecheck: OK`, `VERDICT command-exit 0`. - `src/approval-activity-feed-35723.integration.test.ts` at `06a3c7640b`: `Tests 7 passed (7)` (approve/reject/recall, send back + resubmit, cancel on record delete, muted timeline, zh-CN reader, reader without approval access, record-reader opt-in). - Ablation (S1): `node scripts/ablation-replace.mjs` replaced the `bindApprovalActivityLocale(...)` call in `approvals-plugin.ts` with a no-op (anchor 1 to 0, blob changed); the zh-CN pin went red (`Tests 1 failed | 6 passed (7)`, the six others green), restore verified (`blob == HEAD`, `git diff HEAD` empty). - Local gate subset: `dispatch-gates --ran` reconciles `106 derived, 104 run, 2 UNRUN`; 101 exit 0. `check:i18n` first exit 3 (PREREQUISITE NOT MET), then its own one-command prerequisite build and re-run: `check-i18n-bundles: OK (10 package(s) — all bundles in sync, no undeclared authoring keys)`, `VERDICT command-exit 0`. `check:system-context-census` (red in CI on `05d82f29`) fixed in `f0b51c92`: `OK — 202 elevation read sites ... the generated register (178 symbol(s)) matches the tree`, self-test all cases passed. NOT MEASURED locally, CI runs them: `check:dual-build-cjs-loads`, `spec check:skill-examples` (exit 3, unbuilt dist outside the closure); `pnpm --dir ui exec vitest run scripts/` and `check:type-check-debt` (declared narrowing: the first was OOM-killed in round 1, the second needs a whole-workspace build; no `ui/` file and no package's type-check set changed this round). - `overlap-check --branch=claude/issue-35723-approval-feed-items`: `VERDICT clean exit 0`. - Round 1 readings (UI suites, record-page ablation) stand for the unchanged `ui/` files: `RecordDetailView.*` 100 files / 858 tests, plugin-detail 417 files, both `type-check` exit 0. - Full dogfood: not owed (no `!` in the title, no `(narrowing)` arm). </details> ## Acceptance notes - `sys_activity` keeps its own lifecycle (rows reaped after 14 days); the 审批 tab keeps the full history. Steps taken before this lands write no backfilled rows. - The console restates the three writer values (`recordActivityFeed.ts`) because plugin-detail cannot depend on the server plugin; both sides are pinned by tests. - The producer reads the decision log rather than calling in from each decision method, so a step the service learns to record elsewhere reaches the stream with no second call site. - New UI pin for the mapper and stream lives in a card-named file `recordActivityFeed.approvalStep-35723.test.tsx` (it renders React; the shared `recordActivityFeed.test.ts` is a non-JSX file). The record-page pin joined the shared `RecordDetailView.harness.test.tsx` as its own top-level block. ## Verification First read (by risk): 1. `packages/plugins/plugin-approvals/src/approval-activity-feed.ts` — `bindApprovalActivityReadGate` (who sees an approval row), `bindApprovalActivityLocale` (the system-read pass-through and the borrowed columns), and the producer hook's transaction and tenant context. 2. `ui/packages/plugin-detail/src/renderers/recordActivityFeed.ts` — `isApprovalStepRow`, the mapping branch. 3. `ui/packages/app-shell/src/views/RecordDetailView.tsx` — `openRecordApprovals` / `viewApprovals`, a plain function below the page's early returns (a hook there breaks hook order). Two-minute check: `pnpm --filter @objectstack/plugin-approvals exec vitest run --maxWorkers=2 src/approval-activity-feed-35723.integration.test.ts` — expect 7 passed: one entry per step (approve / reject / recall, send back and resubmit, cancel on record delete), none on a muted timeline, a zh-CN reader served `已批准 · 经理审批`, none served to a reader without approval access while other entries stay, and served under the record-reader opt-in. --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzg3KqwSpt61Y8ovKK7)_ https://claude.ai/code/session_01WGufzg3KqwSpt61Y8ovKK7 <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufzg3KqwSpt61Y8ovKK7 --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 0a1b69c commit a03c3d4

19 files changed

Lines changed: 1409 additions & 52 deletions
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@objectstack/plugin-approvals': patch
3+
'@object-ui/plugin-detail': patch
4+
'@object-ui/app-shell': patch
5+
---
6+
7+
feat(plugin-approvals): a record's activity shows its approval steps, to the users who can read its approvals
8+
9+
Clause-②: no
10+
Metadata-protocol: none
11+
12+
A record under approval used to show no approval in its activity: nothing wrote an activity entry for an approval step, so the activity stream's one-line approval entry was reachable only from items a host supplied by hand.
13+
14+
- **One activity entry per approval step.** plugin-approvals now appends one `sys_activity` entry for each step it records in its decision log, about the record the request governs: submitted, approved (`Approved · Manager review`, the step's label after the dot), rejected (`Rejected · Manager review`), sent back for revision (`Sent back for revision · Manager review`), resubmitted, recalled, and cancelled (the record was deleted). Other actions (a reminder, a reassignment, a thread comment, …) write none, and an object that sets `enable.activities: false` gets none, as the CRUD mirror writes none for it. The entry carries no decision comment. It follows ADR-0052 §5, so no published vocabulary changes: `type` is the built-in `system`, the domain kind is `metadata.kind: 'approval'` (with the step's action, its label and the flow and step names beside it), and `source_object` / `source_id` name the request. A deployment without plugin-audit has no `sys_activity` and gets no entries.
15+
- **Each entry reads in the reader's language.** The stored `summary` is the English line from plugin-approvals' own catalog (`approvalActivity*` messages, shipped in all eleven of its locales). A read that carries a locale is served the line re-composed in that locale, and the step's label is read from the app's language pack (`flows.<flow>.approvals.<node_id>.label`) the way the approvals tab reads it, else the stored label: a zh-CN reader sees `已批准 · 经理审批`. A system read, or a read with no locale, gets the stored English line. A failed append never fails the approval step; it is logged once at `error`.
16+
- **Only the users who can read the record's approvals read those entries.** A read of `sys_activity` keeps an approval entry only when the approvals service would serve the caller its request: a participant (submitter, current or past approver), the override actor, or a reader of the record where the object opts into `enable.approvalsVisibleToReaders`. Every other entry is served as before, and plugin-audit's rule that the record must be readable still applies. The record page's activity count and its rows agree.
17+
- **The stream draws each entry as the approval line, and 「看审批」 opens the approvals.** The console reads an activity row with `type: 'system'`, `metadata.kind: 'approval'` and a `sys_approval_request` source as the `approval` feed kind (`APPROVAL_ACTIVITY_FEED_TYPE`, exported from `@object-ui/plugin-detail`), so `approval` now counts as produced. The record page supplies the new `RecordViewApprovalsContext`, and the approval line's 「看审批」 opens the record's 审批 tab, the same place the approval tag in the header opens; with no approvals the reader is served, the line has no link. The entry keeps `sys_activity`'s own lifecycle (reaped after 14 days); the 审批 tab keeps the full history.

‎content/docs/frontend/plugins/plugin-detail.mdx‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ edited (`is_edited` on the row).
510510
511511
### Feed kinds with no producer
512512

513-
`FeedItemType` publishes thirteen kinds. ObjectUI produces **five** of them:
513+
`FeedItemType` publishes thirteen kinds. ObjectUI produces **six** of them:
514514

515515
| kind | produced by |
516516
|---|---|
@@ -519,22 +519,23 @@ edited (`is_edited` on the row).
519519
| `event` | `sys_activity` type `scheduled` |
520520
| `system` | `sys_activity` type `system`, **and** any author-extended type the map has never seen (it renders through the generic presentation rather than vanishing), **and** a `completed` row a milestone fired (`metadata.kind: 'milestone'`) |
521521
| `comment` | `sys_comment` rows, merged in by the console's record page and handed to the block through the discussion context |
522+
| `approval` | `sys_activity` type `system` with `metadata.kind: 'approval'` and `source_object: 'sys_approval_request'`, which plugin-approvals writes once per approval step (submitted, approved, rejected, recalled); served only to the users who can read the record's approvals |
522523

523-
The other eight — `email`, `call`, `note`, `file`, `record_create`,
524-
`record_delete`, `approval`, `sharing` — have no producer on any ObjectUI
524+
The other seven — `email`, `call`, `note`, `file`, `record_create`,
525+
`record_delete`, `sharing` — have no producer on any ObjectUI
525526
surface. A `types` list of only such kinds renders a **permanently empty**
526527
timeline. Since objectui#5877 it also emits one `console.warn` per distinct
527528
kind, so the emptiness is diagnosable instead of looking like "a working
528529
feature with no data yet".
529530

530531
Beside the default composer such a list is refused before it ever renders.
531-
`types: ['approval']` leaves out `'comment'` while `showCommentInput` defaults
532+
`types: ['call']` leaves out `'comment'` while `showCommentInput` defaults
532533
to `true`, so `os lint`, `os validate`, `os build`, the page save door and the
533534
console's schema mirror report it at error as `component-props-invalid` at
534535
`properties.showCommentInput` (`properties.feed.showCommentInput` on
535536
`record:chatter` / `record:discussion`). Add `'comment'` to `types` when the
536537
block should take comments, or set `showCommentInput: false` when it should
537-
stay comment-free; `types: ['approval']` with `showCommentInput: false` parses
538+
stay comment-free; `types: ['call']` with `showCommentInput: false` parses
538539
and renders the empty timeline above. A page already stored with the shape
539540
still loads; its next save is refused.
540541

‎content/docs/permissions/system-context.mdx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ bugs — it is the protection or the side effect that silently does not happen.
120120
| 13 | Per-request performance timings disclosed | observability | Get: timing headers a normal caller cannot pull | `isPerfDisclosurePrincipal` |
121121
| 15 | MCP stdio bridge skips the object API-exposure gate | mcp | Get: the bridge reaches objects whose `apiEnabled` / `apiMethods` would refuse an external caller | `enforceApiExposure` |
122122
| 16 | **Read-audit rows are not written** | plugin-audit | Lose: the "a person opened this record" trail. `sudo()` keeps the caller's `userId`, so this flag is the only thing separating a human read from a platform one | `installReadAuditWriter` |
123-
| 17 | Approval snapshot payload redaction skipped, and so is the snapshot query guard and the reader-locale label overlay | plugin-approvals | Get: the whole snapshot on `find` / `findOne` — the audit/replay channel — and a filter, sort or grouping by it on any read; and a request's `process_label` / `current_step_label` as stored, never in a locale the context carries, so nothing the platform reads back and writes again holds a reader's language. Lose: field-visibility redaction over approval payloads, the refusal of a query over the snapshot for a reader withheld a field of the objects it can reach, and the flow and step labels in the reader's language | `bindSnapshotRedactionMiddleware`, `bindSnapshotPredicateGuard`, `bindReaderLocaleLabelsMiddleware` |
123+
| 17 | Approval snapshot payload redaction skipped, and so is the snapshot query guard and the reader-locale label overlay | plugin-approvals | Get: the whole snapshot on `find` / `findOne` — the audit/replay channel — and a filter, sort or grouping by it on any read; a request's `process_label` / `current_step_label` as stored, and an approval entry's `sys_activity.summary` as stored (its English line), never in a locale the context carries, so nothing the platform reads back and writes again holds a reader's language. Lose: field-visibility redaction over approval payloads, the refusal of a query over the snapshot for a reader withheld a field of the objects it can reach, and the flow and step labels and the approval entry's line in the reader's language | `bindSnapshotRedactionMiddleware`, `bindSnapshotPredicateGuard`, `bindReaderLocaleLabelsMiddleware`, `bindApprovalActivityLocale` |
124124
| 18 | REST anonymous-deny seam satisfied | rest | Get: `enforceAuth` passes with no `userId`. Not reachable from the wire — `isSystem` is never set on an inbound request | `enforceAuth` |
125125
| 18b | Settings namespace read scope not applied | service-settings | Get: a read of `sys_setting`, `sys_setting_audit` or `sys_platform_setting` across every namespace, whatever each namespace's `readPermission` names — the settings service's own reads of its stores take this path. Lose: the per-namespace read gate the generic data API applies to every other caller, the same rule the settings routes enforce | `settingsReadDoorMiddleware` |
126126
| 18c | **Credential-column filter / sort refusal not applied** — a `where`, `orderBy`, per-aggregation `filter` or `expand` entry naming a `password` / `secret` column is evaluated | objectql | Get: the server's own match on a stored credential value, a lookup that never returns it. Every other caller, administrators included, is refused `400 INVALID_FIELD` for anything but a has-a-value check (ADR-0100). Lose: nothing a wire caller reaches — `isSystem` is never set on an inbound request | `rejectCredentialEvaluation` |
@@ -572,6 +572,7 @@ and CI refuses one that differs from what the tree produces.
572572
| `packages/objectql/src/stored-metadata-type-read-gate.ts#storedMetadataTypeReadFilter` | 1 | 18d |
573573
| `packages/observability/src/perf-timing.ts#isPerfDisclosurePrincipal` | 1 | 13 |
574574
| `packages/plugins/organizations/src/organizations-plugin.ts#start` | 1 | 62 |
575+
| `packages/plugins/plugin-approvals/src/approval-activity-feed.ts#bindApprovalActivityLocale` | 1 | 17 |
575576
| `packages/plugins/plugin-approvals/src/approval-service.ts#assertAttachmentsUploadedByCaller` | 1 | 43 |
576577
| `packages/plugins/plugin-approvals/src/approval-service.ts#comment` | 1 | 43 |
577578
| `packages/plugins/plugin-approvals/src/approval-service.ts#isOverrideActor` | 1 | 43 |

‎docs/audits/2026-08-tenant-audit-write-call-sites.counts/plugins/plugin-approvals.md‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ a row or a number here — fix the code, or the census, and regenerate.
1414

1515
| Measure | Value |
1616
|---|---:|
17-
| Write call sites | 41 |
18-
| Object name statically decidable | 39 |
17+
| Write call sites | 42 |
18+
| Object name statically decidable | 40 |
1919
| Object name chosen at run time | 2 |
2020
| Object name spelled inline | 38 |
21-
| Object name spelled through a `const` | 1 |
21+
| Object name spelled through a `const` | 2 |
2222
| Object name is an `object: string` parameter | 1 |
2323
| Object name is some other run-time expression | 1 |
24-
| Against a tenancy-enabled object | 39 |
24+
| Against a tenancy-enabled object | 40 |
2525
| Against an object declaring tenancy off | 0 |
26-
| Threading a tenant context | 41 |
26+
| Threading a tenant context | 42 |
2727
| Provably carrying none (options read, no context key) | 0 |
2828
| …and decidably tenancy-enabled | 0 |
2929
| Options argument unreadable | 0 |
3030
| …and decidably tenancy-enabled | 0 |
31-
| Threading a decidably elevated (`isSystem`) context | 39 |
31+
| Threading a decidably elevated (`isSystem`) context | 40 |
3232
| Threading a decidably non-elevated context | 0 |
3333
| Threading a context of undecidable elevation | 2 |
34-
| Receiver carried a readable engine type | 41 |
34+
| Receiver carried a readable engine type | 42 |
3535
| Receiver erased, placed by the object NAME | 0 |
3636
| Receiver erased, placed by an `object: string` PARAMETER | 0 |
3737
| Receiver erased, placed by an `UNTYPED_RECEIVERS` row | 0 |
@@ -48,6 +48,7 @@ a row or a number here — fix the code, or the census, and regenerate.
4848
| file | verb | object | tenancy | tenant context | n |
4949
|---|---|---|---|---|---:|
5050
| `packages/plugins/plugin-approvals/src/action-slot-backfill.ts` | `update` | `sys_approval_action` | enabled | elevated | 2 |
51+
| `packages/plugins/plugin-approvals/src/approval-activity-feed.ts` | `insert` | `sys_activity` | enabled | elevated | 1 |
5152
| `packages/plugins/plugin-approvals/src/approval-service.ts` | `update` | `object` | undecidable | context, elevation undecidable | 1 |
5253
| `packages/plugins/plugin-approvals/src/approval-service.ts` | `insert` | `sys_approval_action` | enabled | elevated | 17 |
5354
| `packages/plugins/plugin-approvals/src/approval-service.ts` | `delete` | `sys_approval_approver` | enabled | elevated | 2 |

0 commit comments

Comments
 (0)