Repository navigation
feat(sy-atlas-config): name the atlas report-issue form on the config global - #823
Conversation
… global The widget's report-issue path had no authored `forms` document behind it, so every message it sent arrived with no field list, no `actionType` agreement and no operator-visible record of what the widget offers. `user-submissions` already refuses a `contact` row naming no form, so the widget's path was refused outright rather than merely undocumented. `reportIssueForm` is the relationship that closes that: an operator authors an ordinary contact form and names it here, exactly as WeMeditate Web does. Nullable on purpose. Unset is a live state the widget has to render — hiding report-issue — rather than an error, so a `required` relationship would also make the column NOT NULL on a table carrying a production row. `filterOptions` pins it to `actionType: 'contact'` so the refusal lands on the operator at authoring time. Without it `prepareUserSubmission` refuses the mismatch with a 400 at send time, one visitor at a time, with nobody who can fix it present. Refs #813 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_011T2g9wJShY6zF1oRZDoTb8
`Forms.recipient` is a relationship to `managers` carrying no field access, and `forms` ships the form-builder plugin's own `read: () => true`, which `accessPlugin` spreads last. `managers` sits in no project, and `isCollectionVisibleInProject` reads that as shared rather than restrictive — so a read of `forms` at `depth >= 1` populated the manager and handed a name and an email address to whoever asked, browser included. `managersOnlyFieldAccess` is the same lock `Clients.mailingList` carries, for the same reason. Delivery is unaffected: `recipientFor` resolves the recipient server-side with `overrideAccess: true`. Also corrects the three comments stating the rejected premise behind #813 — that the widget posts a `contact` row with no form at all. It does not, and `user-submissions` never allowed it. The `CONTACT_EMAIL` fallback stays load-bearing for the real reason: `recipient` is nullable, so a contact form whose author named nobody still has to deliver somewhere. Refs #813 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_011T2g9wJShY6zF1oRZDoTb8
The atlas's report-issue form is authored in the CMS and read by the widget, so `forms` belongs to the atlas as much as to WeMeditate Web. It buys two of the three things a project's `collections` list drives. OpenAPI visibility (`specFilter.ts`) is the load-bearing one: without it the widget's own contract for the form it must render is absent from the atlas spec. Admin nav is the second, and it reaches admin managers only — `createHidden` needs a write grant, and `atlas-manager` holds none on `forms`, so form authoring stays an admin task. The third, implicit read, is a no-op here: the form-builder plugin's `read: () => true` already outranks RBAC on this collection. The grant is still wanted — it makes the atlas client's read an intended rule rather than an accident of plugin defaults, which is what the new `hasPermission` case pins. Refs #813 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_011T2g9wJShY6zF1oRZDoTb8
Each one fails in a way the others cannot see, and each assertion was proven by reintroducing the real defect and watching that case go red: - Dropping `filterOptions` from `reportIssueForm` let a `subscribe` form be named on the global, which every report would then be refused against. - Dropping `recipient`'s field access returned the manager to the atlas client at depth 0 already — `select` names `recipient` and the fixture form has one, so neither half of the assertion can pass vacuously. - Dropping `forms` from the atlas project turned the `hasPermission` case false while both read cases stayed green. That is the useful half of the answer to the ticket's first open question: the form-builder plugin's `read: () => true` does reach these rows without the grant, so nothing else in the suite would notice the collection leaving the list. - Flipping `recipientFor` to `overrideAccess: false` sent every report to `CONTACT_EMAIL` instead of the named recipient. A field lock that also broke delivery would satisfy every other case here and fail silently in production. The delivery cases mock `sendUserMessage` and assert the address it is handed. `deliverContact` had no coverage at all — nothing under `tests/` named it. Refs #813 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_011T2g9wJShY6zF1oRZDoTb8
Three passages this change falsifies: `access.md` named `Clients.mailingList` as the only `managersOnlyFieldAccess` consumer. `Forms.recipient` is the second, and its reason is worth stating separately — the collection keeps a plugin `read: () => true`, so the lock is the only thing between a manager's address and a browser. `src/globals/AGENTS.md` enumerates `sy-atlas-config`'s fields, and the enumeration is what a reader checks against. `admin-ui.md`'s project table showed `forms` for We Meditate Web alone. The atlas column carries the caveat rather than a bare tick, because `createHidden` needs a write grant and `atlas-manager` holds none. Refs #813 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_011T2g9wJShY6zF1oRZDoTb8
…ck does not close Review findings, applied: `filterOptions` takes the plain-object form — the callback read none of its arguments, and `UserChoices` already spells a static filter this way. Four comments restated the nullable-`recipient` fallback. Before this branch each carried a real fact (the widget posted no form at all); the branch deletes that fact, leaving three that narrate the type. The statement stays once, at the field. The spec's duplicate `hasPermission` case is gone — `role-based-access` pins the same rule for all three client roles, which is strictly stronger, and it does so without paying a Payload bootstrap. The depth loop drops 2: a one-hop `relationTo: 'managers'` has only id and populated to distinguish. One finding is a fix, not a cleanup. The `recipient` docblock diagnosed a root cause — `managers` is in no project, so implicit read treats it as shared — and then locked one field, which reads as though the class were handled. It is not: a published client key reads `managers` directly, and `Events.manager` and `Regions.managers` carry no lock at all. Both reproduced against a booted Payload and filed as #821. The comment now says so. Rejected: a shared `testData.createForm` factory (six specs, outside this diff); exporting the `{read, create, update}` access triple (second occurrence, both sites carry a ⚠); dropping the `forms` project entry as inert (its OpenAPI visibility is the point, and it was asked for on the ticket). Refs #813 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_011T2g9wJShY6zF1oRZDoTb8
|
🚅 Deployed to the SahajCloud-pr-823 environment in sahajcloud
1 service not affected by this PR
|
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The diff is the ticket's size and shape. Four source files, one migration, two specs, no smuggled refactor. The cross-repo contract holds: SahajAtlasWeb reads sy-atlas-config with select: { availableLocales: true } at depth 0 (src/config/api/fetch.ts:720), so reportIssueForm is inert until #213 opts in. The forms project entry does buy only the OpenAPI row, as the body claims.
Findings
should-fix—Forms.clienthas no lock beside the newrecipientone, and the ⚠ note omits it.src/collections/Forms/fields.ts:70.
What was checked
managersOnlyFieldAccessisreq.user?.collection === 'managers', so it denies anonymous callers too.isCollectionVisibleInProjecthas four callers, none in relationship population.recipientForreads withoverrideAccess: true, so the lock cannot starve delivery.- WeMeditateWeb reads no
forms.recipientunderserver/,lib/,pages/,components/. testData.createClientreturnscollection: 'clients', so the new spec reads as a real client.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
`Forms.recipient` got the lock; `Forms.client`, two definitions below it in the same file, did not. Both sit on a collection that keeps the form-builder plugin's `read: () => true`, and this branch is what puts that collection in the atlas project — so a `sahaj-atlas-client` read at `depth >= 1` populated a whole `clients` document, plaintext `apiKey` included (#822). That payload is worse than the manager name and address the `recipient` lock closes. `Clients.mailingList` is the precedent for the same collection reached the other way round. `deliverSubscribe` resolves this field with `overrideAccess: true`, so the lock cannot starve a subscription — the same argument that makes `recipientFor` safe. The spec case was proven by dropping the `access` block and watching it go red at depth 0, where the bare id comes back. Refs #813 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_0154yFhSVDXv7XCxYkksAGzk
`Forms.client` now carries `managersOnlyFieldAccess`, and the count in the field-access section was two. Refs #813 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_0154yFhSVDXv7XCxYkksAGzk
|
Adopted the one review finding. Pushed
Nothing rebutted, nothing asked. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Summary
sy-atlas-configgainsreportIssueForm, a nullableformsrelationship filtered toactionType: 'contact'— the widget's report-issue path now has an authored form behind it.formsjoins thesahaj-atlasproject, which puts it in the atlas OpenAPI spec and the admin nav.Forms.recipientandForms.clientare both locked withmanagersOnlyFieldAccess. Without them, openingformsto the atlas hands a manager's name and email, and a wholeclientsdocument, to a browser.src/collections/UserSubmissions/changes.needsFormandperTypeFormwere already right.Changes
src/globals/SahajAtlasConfig/SahajAtlasConfig.ts— the new relationshipsrc/plugins/access/config/projects.ts—formsadded tosahaj-atlassrc/collections/Forms/fields.ts— therecipientandclientfield lockssrc/jobs/DeliverSubmissions/deliverContact.ts,src/lib/notifications/sendUserMessage.ts— three comments stated the rejected premise (that the widget posts a contact row with no form); correcteddocs/rules/access.md— the field-access section names all three fields carrying the lockPreview
Contract impact
sydevs/SahajAtlasWeb — the widget must now read the form id off
sy-atlas-config, fetch the form, render its authored fields, and post acontactrow naming it. sydevs/SahajAtlasWeb#213 and sydevs/SahajAtlasWeb#195 both need revising against this contract before either is implemented: #213 re-points the call ontoPOST /api/user-submissions, and on this contract it would be refused for naming no form.src/payload-types.tsis regenerated, so consumers runningtypes:cmspick upreportIssueForm.Migration
src/migrations/20260918_172634_atlas_config_report_issue_form.tsreport_issue_form_idcolumn tosy_atlas_config, an FK toformswithON DELETE set null, and a btree index. No data transformed.downdrops the constraint, index and column.Nullable is deliberate, and not only because unset is a live state the widget renders: a
requiredrelationship makes the columnNOT NULL, and that migration aborts the boot migration on any environment carrying cloned production data.Test results
pnpm lint,pnpm typecheck,pnpm typecheck:tests,pnpm test:unit(2135 passed)atlas-report-issue-form,forms-action-type,role-based-access,user-submissions-create,user-submissions-accessclientlock:atlas-report-issue-form(8),forms-action-type+user-submissions-access(18) — all greenEvery new assertion was proven by reintroducing the real defect and watching that case go red, per
tests/AGENTS.md. The four are listed in the test commit. The one worth naming here: flippingrecipientFortooverrideAccess: falsesends every report toCONTACT_EMAILinstead of the named manager. A field lock that also broke delivery would have satisfied every other case in the file and failed silently in production.The
clientlock's case was proven the same way: dropping itsaccessblock turns the new case red at depth 0, where the bare id comes back.Manual verification
sy-atlas-config.subscribeform.Step 3 needs the atlas side, so it cannot be done from this PR alone.
Notes for reviewer
Two pre-existing security defects surfaced during review, both reproduced against a booted Payload and filed. Neither is caused by this branch and neither is fixed here:
apiKey. The atlas key ships in the browser, so it escalates to every other service's credential. Treat the existing keys as disclosed.Events.manager/Regions.managers.The two field locks in this PR each close one instance of those mechanisms —
recipientfor #821,clientfor #822. Both docblocks say so explicitly, with a⚠pointing at the ticket, so the next person adding arelationTo: 'managers'orrelationTo: 'clients'field does not read either lock as evidence the class is handled.One ticket open question is answered, and it changes what a test means. "Is the
formsread already open, making the project entry half a no-op?" — yes. The form-builder plugin shipsformswithread: () => trueandaccessPluginspreads...collection.accesslast, so the read was open to anonymous callers already. The project entry therefore buys OpenAPI visibility and admin nav, not the widget's read. Proven by dropping the entry: thehasPermissioncase went false while both read cases stayed green. That is why the grant is pinned inrole-based-access.int.spec.ts— nothing else in the suite would noticeformsleaving the list.Dismissed review findings: a shared
testData.createFormfactory (six specs hand-roll one; outside this diff, and one lens called it the repo's convention); exporting the{read, create, update}access triple (second occurrence, both sites carry a⚠); dropping theformsproject entry as inert (its OpenAPI visibility is the point, and the ticket asked for it).Detail
Fixture pre-mortem. The spec's fixtures assume:
sahaj-atlas-clientis a client role scoped to thesahaj-atlasproject grantinguser-submissions: ['create']and nothing else (checked insrc/plugins/access/config/roles.ts);formsis in both thesahaj-atlasandwemeditate-weblists andmanagersin none (src/plugins/access/config/projects.ts); an API client read must sendselect(src/plugins/usage/hooks.ts); every partial write tosy-atlas-configmust carryavailableLocales, and['en']alone needs no relaxation (src/fields/availableLocalesField.ts).That last one is also why the
#822probe is worth describing: its first version left the other client'sapiKeyunset, gotnullback, and read exactly like "the field is protected". The exposure only appears once the fixture stores a key. The ticket carries that warning.The lock costs nothing at read time and saves a query.
managersOnlyFieldAccessis a synchronous property check, and field access runs beforerelationshipPopulationPromiseis queued — so a non-manager read of a form atdepth >= 1now skips a dataloader fetch againstmanagersper row, and one againstclients.filterOptionscosts one indexed PK lookup per form-state build and per save, guarded on the value being set, and never runs on the read path. Both internalsy-atlas-configreaders passdepth: 0(src/lib/atlas/regionOwners.ts,src/endpoints/atlas/seo/atlasLocales.ts), so the new relationship adds nothing towebUrlresolution — the one place a new relationship on this global could have hurt.deliverContacthad no test coverage at all before this branch; nothing undertests/named it.Closes #813
🤖 Written by the sydevs autonomous loop — see what this is
🤖 Generated with Claude Code
https://claude.ai/code/session_011T2g9wJShY6zF1oRZDoTb8