diff --git a/.changeset/actions-param-record-id-is-input.md b/.changeset/actions-param-record-id-is-input.md new file mode 100644 index 00000000000..abb57fd6608 --- /dev/null +++ b/.changeset/actions-param-record-id-is-input.md @@ -0,0 +1,16 @@ +--- +'@objectstack/skills': patch +--- + +docs(skills): the actions page of objectstack-ui says a record id in an action's own params is input the body checks + +Clause-②: no +Metadata-protocol: none + +`skills/objectstack-ui/rules/actions.md`, in the section on the body's `ctx`, now says which ids the platform reads as the caller for an action body or a registered handler: the call's `recordId` and its `_selectedIds`, and no other. A record id that arrives in the action's own params (a lookup param, or a custom key a handler action passes through) is the body's input, and the body, which runs trusted, checks it against `ctx.user` before acting on it. + +`content/docs/ui/actions.mdx` says the same under "Authorization inside an action", beside the text on the selection read and the param pass-through, and points at the flow start door, which does load an input a flow reads as a record id in the caller's own scope. + +Nothing in the platform changes; this is how the action door already behaves. + +The text is paid for inside the file, which goes from 16282 to 16281 bytes and stays at 4071 priced tokens. What leaves: the `ctx` sentence's words "server-side", "target" and "scoped"; from the examples, the `errorMessage` line of the reassign example (the `successMessage` / `errorMessage` bullet above it still teaches the key), the `successMessage` line and the second `visible` clause of the convert example, and the `timeoutMs` line and the `status` value of the add-to-campaign example (a body's `timeoutMs` is taught in objectstack-data, `references/data-hooks.md`); and a few connecting words in the new-tab warning and the closing note on lines written past the action. diff --git a/content/docs/ui/actions.mdx b/content/docs/ui/actions.mdx index 04f80e8ad13..ba7d219a16c 100644 --- a/content/docs/ui/actions.mdx +++ b/content/docs/ui/actions.mdx @@ -758,6 +758,21 @@ a near-miss spelling of a built-in — `selectedIds`, `__selectedIds`, `_recordI which is refused `400` naming the built-in it meant, so a selection only ever arrives under the key the platform reads. +**A record id in the action's own params is not read.** For a script body or a +registered handler, the call's `recordId` and its `params._selectedIds` are the +only ids the platform reads as the caller. A record id that arrives in the +action's own params — a declared lookup param such as `campaign_id`, or a +custom key a param-less handler action passes through — is the body's input. +The param contract judges a declared param's presence and value shape and reads +no row, so nothing has shown that this caller can read the row the id names, +and the elevated `ctx.api` reads and writes that row either way. Check such an +id as the caller before the body acts on it: decide from `ctx.user` and the row +whether this caller may use it, by the rule your app holds for that object (its +owner, say), and refuse if not. A `type: 'flow'` action gets one more read from +the platform: an input the flow's own definition reads as a record id is loaded +in the caller's own scope before the run starts +([Run a flow via API](/docs/automation/flows#run-a-flow-via-api)). + **Flow actions.** A `type: 'flow'` action hands its target flow the same `record` — `record.id` stamped the same way — and the flow run's context (`AutomationContext`, the `@objectstack/spec` contract) declares the same key diff --git a/skills/objectstack-ui/rules/actions.md b/skills/objectstack-ui/rules/actions.md index 57a39aaac40..c1fe4cf936c 100644 --- a/skills/objectstack-ui/rules/actions.md +++ b/skills/objectstack-ui/rules/actions.md @@ -78,7 +78,6 @@ export const ReassignLeadAction = defineAction({ submitText: 'Reassign', undoable: true, successMessage: 'Lead {{ record.name }} reassigned.', - errorMessage: "Couldn't reassign this lead.", }); ``` @@ -99,9 +98,8 @@ export const ConvertLeadAction = defineAction({ icon: 'arrow-right-circle', type: 'flow', target: 'crm_lead_conversion', - visible: P`record.status == "qualified" && record.is_converted == false`, + visible: P`record.status == "qualified"`, confirmText: 'Convert this lead?', - successMessage: 'Lead converted.', onSuccess: { navigate: '/apps/crm_enterprise/opportunity/record/${result.output.opportunity_id}' }, refreshAfter: true, }); @@ -123,23 +121,24 @@ export const AddToCampaignAction = defineAction({ language: 'js', source: ` await ctx.api.object('campaign_member').insert({ - campaign_id: input.campaign_id, lead_id: ctx.recordId, status: 'sent', + campaign_id: input.campaign_id, lead_id: ctx.recordId, }); `, capabilities: ['api.write'], - timeoutMs: 10000, }, }); ``` ### Action body context (`ctx`) -A server-side `body` or registered `handler` receives `ctx` with `input` (the dialog params), `record` (the target row when a -`recordId` is in scope), `api` (scoped cross-object CRUD) and the caller. Read +A `body` or registered `handler` receives `ctx`: `input` (the dialog params), `record` (the row a +`recordId` names), `api` (cross-object CRUD) and the caller. Read the active organization as `ctx.user?.organizationId ?? ctx.session?.organizationId`. Bodies execute **trusted** (`ctx.api` / `ctx.engine` bypass RLS/FLS); an identity-assignment write is refused -(objectstack-automation → Elevation stops at identity assignment). `ctx.session.positions` (absent when the caller holds none) is +(objectstack-automation → Elevation stops at identity assignment). A record id in the action's own params (a lookup +param, a handler's custom key) is input: only `recordId` and `_selectedIds` are read as the +caller, so the body checks it against `ctx.user` before acting on it. `ctx.session.positions` (absent when the caller holds none) is **not an authorization input** — ask the security service for privilege (ADR-0095). ### Refusing by code (`refusals`) @@ -214,8 +213,8 @@ export const OpenInvoicePdfAction = defineAction({ > A printable document (an invoice) is a page that declares `print` — [Print pages](./pages.md#print-pages). -> ⚠️ **Never express new-tab behavior via `params`**, which is **user input** -> only: `params: [{ name: 'newTab', type: 'checkbox' }]` draws a checkbox. +> ⚠️ **Never express new-tab behavior via `params`** (**user input** only): +> `params: [{ name: 'newTab', type: 'checkbox' }]` draws a checkbox. ## Action Parameter Patterns @@ -263,7 +262,7 @@ export const AddInvoiceLineAction = defineAction({ }); ``` -Lines also written past the action (API, an agent, an import — one with +Lines written past the action (API, an agent, an import; one with automations off skips hooks) get the price from a `beforeInsert` hook on the line (objectstack-data → Lifecycle Hooks), `runAs: 'system'` when the writer cannot read it.