Repository navigation
fix(access): scope meditation edits to the editor's language - #999
Conversation
A meditation is one language, in its hidden `locale` select, but `meditations-editor` is granted per locale and the grant it carries names none. So the collection-wide grant let a French or Czech editor open an English meditation by its URL and rewrite its label, narrator, thumbnail, type, music tag and frames for every English listener. Two French and two Czech managers hold the role on production. `scopeMeditationWrite` narrows a non-admin manager's write to the locale `hasPermission` already evaluated their role in, so the answer is the language this request's roles came from rather than the one the document claims. `update` and `delete` return a `Where`, which `updateByID` reports as 403 when it matches nothing. `create` has to answer with a boolean, because `executeAccess` reads a `Where` as a grant and an object there would allow every language. Version history follows without an edit: `withDerivedGrants` derives `readVersions` from `update` and translates the clause onto `version.locale`. Reads are untouched — `filterMeditationsByLocale` already scopes `find` and `count`, and skipping writes is why this gap existed. Narrators keep their unscoped grant, since every language draws on the same ones. The fixtures carry a frame each: `Meditations.frames` demands at least one on every update, so a frameless meditation fails validation before any of these cases reaches its assertion. Checked against the live field, not assumed. Six of the ten cases go red with the branch disabled; the four that stay green are the controls for what must not change. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014S9XqDjmUMJo5H5Eq5VGes
Where the rule lives, what each operation answers, and the three things it leaves alone — reads, narrators, and admins. The collections guide's Meditations locale section says writes are scoped elsewhere, since the hook it describes deliberately skips them. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014S9XqDjmUMJo5H5Eq5VGes
`access.create` runs before the field pass that fills `locale`, so an absent one has to pass there — and `duplicate` sends an empty `data`, then clones the SOURCE document's locale rather than taking the default, because `getFallbackValue` prefers `siblingDoc` over `defaultValue`. So a French editor could `POST /api/meditations/<english id>/duplicate` and land a new English meditation in the app's English catalogue, editable by nobody but an admin. The access scoping cannot see it: the language does not exist in `data` when the gate runs. `restrictCreateToRequestLocale` checks the filled value in `beforeValidate`, the first point the language is known. One rule for each of the two moments a create's language can arrive, rather than two copies of one rule — the same split as `restrictUploadToAdmin`, which guards `req.file` in a hook because a file is not a field. Found by the branch's own review pass, which two lenses reached independently. The case fails with the hook unwired and nothing else does. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014S9XqDjmUMJo5H5Eq5VGes
Its body only ever returns `LocaleCode | undefined` — its own docblock says so with a ⚠ — while the declared `RoleScope` made every caller that scopes a `Where` on the answer write an unreachable `'union'` branch and guess what one would mean. Declaring the narrower type deletes that branch at the source. `RoleScope` stays the parameter type of a permission check, where a caller may still state `'union'` deliberately. Also `incoming == null` for the two-sided null check, the spelling 20-odd sites in `src/` already use, and a comment on `meditations-editor`'s grant saying it is locale-scoped elsewhere — the convention `atlas-manager` already set eleven lines below it, and the misreading that produced #980. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014S9XqDjmUMJo5H5Eq5VGes
The suite's own create helper had grown a second copy of the meditations upload contract — the raw `Buffer`, the browser's mimetype spelling, the label generator. `testData.createMeditation` takes an `as` bag instead, so a spec asserting who may create one passes a user rather than rebuilding the upload. Its `locale` is the REQUEST locale, which this collection keeps separate from the document's own `locale` field: a spec about who may write which language needs the two to differ. The bilingual case now runs over REST. `createManager` returns the document as its create locale read it, so `user:` on a local-API call carries a FLAT `roles` array that `extractRoles` grants in every locale — only the auth strategy hydrates the per-locale record. The case would have passed with the French-only editor substituted, which the docblock now states so the next reader picks the right route. The duplicate case counts English meditations either side of the attempt rather than matching a fixture label a sibling case rewrites when it fails. And `meditations.int.spec.ts` said this derivation was unconditional and pinned no `Where` translation; it is conditional now, and that case pins it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014S9XqDjmUMJo5H5Eq5VGes
The section said writes are scoped without naming the one create the access function cannot answer for. Says which two moments a create's language can arrive, and which guard owns each. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014S9XqDjmUMJo5H5Eq5VGes
|
🤖 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 fix is the size of the ticket: writes narrow in the one place the other two narrowings already live, and reads, narrators and admins stay untouched. The duplicate route is a second hole the ticket missed, and the hook that closes it is forced — access.create is handed data alone, so it cannot see duplicateFromID. Two reservations, neither blocking: the create arm of the access function looks redundant with that hook, and one story is now told four times across code and docs.
Findings
consider—accessConfigs.ts:118— the create arm may refuse nothing the hook does not.consider—restrictCreateToRequestLocale.ts:11— four copies of the duplicate carve-out.consider—testData.ts:631— two spellings of the fixture'slocale.
What was checked
- #980 against the diff: every acceptance criterion has a case. The two extras — the duplicate guard, the
roleScopeFromLocalenarrowing — are each forced by the fix. - Read whole:
accessConfigs.ts, the new hook,Meditations.ts(localerequired, defaults to the admin locale,update: () => false),roles.ts(onlymeditations-editorwrites meditations). - Payload internals read, not assumed:
create.jsruns access, then fieldbeforeValidate, then collectionbeforeValidate;duplicate.jscallscreateOperationwithdata: {};getFallbackValuepreferssiblingDocoverdefaultValue;updateByIDthrowsForbiddenon a where policy matching nothing. - No consumer contract touched: no
payload-types.ts, noresponseTypes.ts, client roles unaffected. - Both
## Previewlinks answer 404, so the preview is still building. The body already states the data is unseeded.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
…tion-locale-writes
The same story was told four times: docs/rules/access.md, this JSDoc, the hook's, and src/collections/AGENTS.md. Both JSDocs keep the rule and the non-obvious why, and point at the doc that owns the rest. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_016V71DUvxB8FmxCJTYQNn85
A stated locale survives the field pass, so restrictCreateToRequestLocale sees it too and the split is not a necessity. Says why the access arm stays anyway, so nothing reads as load-bearing that is not. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_016V71DUvxB8FmxCJTYQNn85
The `as` spread re-set `locale` after the line above had resolved it, so
`{ locale: undefined }` would have blanked the computed value. Destructures
it out instead.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016V71DUvxB8FmxCJTYQNn85
|
Addressed all three review threads, on 1961db8. The base merged clean (053f8e7, no conflicts). Adopted
Kept, with the framing fixed
Gate: lint, both typechecks, 2642 unit tests, then 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
…tion-locale-writes #1007 split the two largest guides, moving the Meditations locale section out of src/collections/AGENTS.md and into src/collections/Meditations/AGENTS.md. This branch had extended that section in its old home with the write-scoping bullet, so the two edits landed on the same lines. Took main's split in src/collections/AGENTS.md and carried the bullet into the new guide, keeping both: the detail lives where #1007 put it, and the #980 breadcrumb survives. The rest of the section was identical on both sides. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FvDwu8xnNo1TkZgFVBVXgi
|
Merged Took main's split, and carried the write-scoping bullet into the new guide — the detail lives where #1007 put it, and the No code conflicted: main's three code edits since the last merge are comment-only pointer updates, and touch no file this branch changes. Lean gate green — lint, both typechecks, 2653 unit tests. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
227 files / 2917 tests on the merged tree, the lane in 53.54 s inside the gate. Main's #1014 added two spec files and this push's declaration cases added nineteen tests; PERF.md is the single writer of every tier figure, so its four consumers move with it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WxbGYkh4n15V3YH2iySgqd
|
Built A and pushed d3ec179. Answered — classifying every top-level Merged The security sweep caught one of mine: the walk skipped an unnamed group, which Payload flattens to the top level — scoped, but with no create hook, so Gate green: 227 / 2917, plus 132 integration cases. Still yours — whether 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Three conflicts, all the unit-lane counts again. #1034 added a unit spec and re-measured, so neither side's figures described the merged tree. The counts are re-measured here rather than picked: 228 files and 2924 tests, from two runs of the lane on the merged tree. PERF.md is the single writer, so AGENTS.md, tests/AGENTS.md and docs/rules/testing-reqs.md all take the same pair. main's new session row is kept under the PR labelling this branch introduced, and the numbering follows the dates. The gate's warm figure takes main's 112 s over this branch's 103 s — the target is held to the slowest measurement. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BqU6prAi33yWgUTScUkwLV
|
Merged Neither side described the merged tree — #1034 added a unit spec and re-measured, this branch had re-measured its own — so the lane was re-measured here instead of picking a side: 228 files / 2924 tests. PERF.md is the single writer, so main's new session row is kept, relabelled Lean gate green (128 s). 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
|
@sydevs-bot revise and go with option 1 for this comment: #999 (comment) ie. Add scoping for the |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The collection half is the size of its ticket and sits in the right layer, beside the two narrowings already there. The field declaration and the Clients rename are the reviewer's own asks. Nothing is smuggled in.
But the PR does not close the hole its ticket opens with. POST /api/meditations/:id/transcribe, which main added after this branch opened, still reads meditations: update with no language condition, so the grant this PR narrows everywhere else stays collection-wide at one door. Option 1 was chosen today and nothing is built for it.
The declaration mechanism is sound. Its one weak seam is that it hand-copies Payload's flattening rule, which already cost a duplicate bypass once this push.
Findings
blocker—src/plugins/access/config/roles.ts:33— the transcribe endpoint reads this grant unscoped.should-fix—src/plugins/access/accessPlugin.ts:96— the raw-fields walk duplicates Payload's own rule.should-fix— PR body, § Detail — "The two meditation endpoints areGETonly" is stale. There are three, and the third is the blocker.
What was checked
- #980 against the diff: every criterion has a case, the two
(review, …)ones included. Twelve cases, none reachingtranscribe. - Read whole:
localeScopedWrites.ts,accessConfigs.ts,accessPlugin.ts,transcribe.ts,RetryTranscript.tsx, the rename migration. Meditationsdeclares nomanagersormanagerfield, so the document-manager fallback is not a second write path around the scope.- Its three endpoints, registered at
Meditations.ts:113:lecturesandsongsareget,transcribeispost. - All three
## Previewlinks answer 404, so the preview is still building.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
`main` added `POST /api/meditations/:id/transcribe` after this branch opened (#984, #1011). It proves `meditations: update` in `req.locale` and then reads the meditation and writes `meditation-transcripts` with `overrideAccess`, so the access function's `Where` reaches none of it — the grant this branch narrows everywhere else stayed collection-wide at that one door, and a `fr`-only editor could delete an `en` meditation's transcript and buy a new paid run. The handler now compares the row's own language, before the 409s and before the transaction that deletes the previous transcript. `isOutsideWritableLocale` is the predicate `restrictCreateToRequestLocale` already needed, so the comparison has one home rather than two: a non-admin manager whose `req.locale` differs from the document's language is refused, and the admin bypass answers first as it does for a write. The Transcript tab hides Transcribe-again on the same condition. A button that can only answer 403 is what the access layer avoided for Save. The predicate is mirrored in `transcriptModel.ts` rather than imported: the module owning the refusal pulls `payload` in with it, and the tab is a `'use client'` component. Both halves watched failing. With the refusal disarmed the new int case reads `expected 200 to be 403`; with the control's gate removed the tab case offers a button on a French meditation. The existing "admits them in theirs" case now uses a French meditation, since an `en` row with `?locale=fr` is the refusal this adds. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01J5xLK465nuE74yP41pduBW
`localeColumnMeaning` answered for two readers over two shapes: `accessPlugin` handed it a collection's raw `fields` to decide whether to attach the create hook, and `createAccessConfig` handed it the booted `flattenedFields` on a write. The raw half had to reproduce Payload's flattening rule — which containers add no path of their own — to agree with a query, and the int guard shares the function, so it cannot see that copy drift. Reproducing it already cost something once on this branch: narrowed to rows and collapsibles, the walk scoped an unnamed group's column at the access layer and left the collection without the create hook, which is the `duplicate` bypass again. So the hook attaches to every collection and asks `collection.flattenedFields` itself, standing down unless that list declares `document-language`. The walk takes the flattened shape and nothing else, and its container descent is gone with the rule it was reproducing. One reader, one shape. The stand-down was watched failing: removed, the new unit case refuses a create on a collection whose column is `'unrelated'`. `role-based-access`, `meditations`, `event-imports`, `meditation-transcription` and `meditation-transcripts` int specs pass, 170 cases. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01J5xLK465nuE74yP41pduBW
228 files / 2929 tests, the lane at 56.6 and 57.0 s in two gate runs. This push added five unit cases and no spec file. PERF.md is the single writer of every tier figure, so its three consumers take the same pair. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01J5xLK465nuE74yP41pduBW
|
Built option 1 and pushed 9f0702f, 66b9658, 5f90518. Base already merged, nothing behind Adopted — the transcribe endpoint reads this grant unscoped. The handler compares the row's own language before the 409s and before the transaction, so a refused caller reaches no delete and no paid run. The Transcript tab hides the button on the same condition. Adopted — the raw-fields walk duplicates Payload's own rule. The hook attaches everywhere and asks The stale § Detail sweep is corrected: three endpoints, not two. Security review: no exploitable path. Every odd Gate green: 228 / 2929, plus 170 integration cases. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Five conflicts, four of them the pinned unit-lane counts and one an import list. Both sides' additions are kept everywhere. - `src/plugins/eventImport/importCollection.ts`: both sides added an import. This branch classifies `imports.locale` as `'unrelated'` (#912); main's #1013 declares the collection's retention windows. Both are used. - `src/migrations/index.ts`: both sides registered a migration. Ordered by timestamp, so #1013's `20261024_161437` precedes this branch's `20261025_195340`. - `tests/PERF.md`: both sides' session rows are kept, ordered by date, under the PR labelling this branch introduced, so main's #1013 and #1034 rows take it too. Ordinals follow the dates. - `docs/rules/testing-reqs.md`, `tests/AGENTS.md`: the counts differed only because each side added a spec file. Measured on the merged tree instead: 229 files / 2938 tests, 59.58 s on 4 cores. A sixth change the merge could not report. #1013's `20261021_152406_retention_registry` lands behind this branch's newer `20261025_195340`, so the newest snapshot still named the three replaced task slugs and `migrate:create` re-emitted both `task_slug` enum rebuilds — without the `DELETE`s that migration runs before it casts, which would abort the boot migration on the first legacy row. `20261026_204230_merge_1013_main_snapshot` keeps only its snapshot, the third time this branch has healed the chain that way. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01437mP62cow1952SftEcyXL
|
Merged
One change the merge could not report. #1013's Gate green: lint, 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
`imports.locale` is the admin locale an upload happened in, which the job writes its classes in (#912). It says nothing about who may write the row — so it was the one counterexample to the rule the reviewer asked for: that a top-level column named `locale` IS a document's own language. Renaming it is what makes that rule true of the whole config, as the same rename made it true of `Clients.language` earlier on this branch. The migration renames the column rather than dropping and adding it, which is what drizzle's own default would do — blanking the locale of every import already stored, so a run still pending at the deploy would create its classes in the default language instead of the uploader's. `varchar` either side, no index and no enum type, so nothing is retyped. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_018gME9vapmFgfep9i7PYxi2
The declaration machinery is gone: `localeColumn`, `LocaleColumnMeaning`, `localeColumnMeaning` and the undeclared verdict, with the two `custom:` declarations and the memo over them. A collection is locale-scoped when it carries a top-level `locale` field at all, which `isLocaleScopedCollection` answers in one line off `flattenedFields`. That turns the rule into an invariant the names carry, so it is written down where a field author will meet it: never spell a column `locale` unless it is the document's own language. `Clients.language` and `imports.uploadLocale` are the two that were renamed to keep it true, and the one hazard the declaration was defending against — a column meaning something else acquiring the scope silently — is now impossible to introduce without renaming something. A new column could still arrive, so the int guard moves from "declares a meaning" to "is one of these": it names every collection carrying the column, `meditations` alone today, and reds when another appears. Watched failing with `imports.uploadLocale` spelled `locale` again — `['imports', 'meditations']` against `['meditations']`. Its docblock now also carries what confirming such a column costs: the locale branch returns before the `user-submissions` one in `createAccessConfig`, so a `locale` column there would replace that collection's row restriction with a language clause. The WeakMap verdict cache goes with the walk it was caching. It existed because reading a declaration off the field list cost a descent; a name comparison over the same list does not. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_018gME9vapmFgfep9i7PYxi2
|
Pushed 4c80a12 and 1d4fb7b. The branch was already level with Adopted — the declaration is gone. A collection is locale-scoped when it carries a top-level Asked, same thread left open — the file is not eliminated. Three things are left, none of them classification: the access clause, the create hook Gate green: 229 files / 2935 unit, 132 int. Security review found no exploitable path. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
`timeout 300 pnpm db:migrations:create <name> --skip-empty < /dev/null` exited **0**, wrote nothing, and printed the rename-vs-create prompt. The outcome table had no row for that: the nearest one is "silent CLI death", whose signal says "no output", and following it sends a run down the escalation ladder instead of to `scripts/migrate-create-pty.py`, which answers the prompt in one re-run. Observed on this branch's second rename. The cause is the redirect the table itself prescribes: `/dev/null` is an EOF the prompt's TUI reads as an abort, so the hang the section documents is what happens with no stdin, not with that command. Both outcomes are stated now, each with its signal. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_018gME9vapmFgfep9i7PYxi2
Summary
meditations-editorcan no longer write a meditation in another language.duplicateroute too, which states no language and clones the source's.POST :id/transcribeis scoped the same way — the one door aWheredoes not reach (review, 2026-10-26).localeIS the document's own language — that is the whole opt-in, with nothing declared per collection and no list anywhere (review, 2026-10-26).Clients.locale→Clients.language(review, 2026-10-25) andimports.locale→imports.uploadLocale(review, 2026-10-26).src/migrations/AGENTS.md's outcome table had no row for the rename prompt refusing a redirected stdin, which is what this push's migration hit.Change outline
The access layer gains one more narrowing, in the same place as the two it already has: the grant decides whether, this decides which rows. A hook covers the create the access function cannot answer for. Both halves live in
src/plugins/access/localeScopedWrites.ts, besideregionSubtreeAccess.ts, and reach a collection because that collection carries a top-levellocalefield at all — no collection wires a hook or an access rule, and none declares anything either.Behaviour —
createAccessConfig's per-operation access functionaccess[operation]({ req, id, data }) src/plugins/access/accessConfigs.ts hasPermission({ …, locale: roleScopeFromLocale(req.locale) }) granted → read + client + drafts → { _status: 'published' } write + manager + regions|events → scopeRegionSubtreeWrite(…) + write + manager + locale-scoped → scopeLocaleWrite(operation, locale, data) + create → data.locale absent, or equal to the role's locale # boolean + update | delete → { locale: { equals: <the role's locale> } } # Where user-submissions + manager → managerSubmissionScope(user.id) else → true denied → the document-manager fallback, else falseFlow — the two moments a create's language can arrive
The access gate runs before the field pass, so it can only answer for a create that states a language.
duplicatestates none and then clones the source document's.createOperation(data) node_modules/payload/…/create.js executeAccess({ data }, access.create) scopeLocaleWrite('create', 'fr', …) data.locale stated → must equal 'fr' # refused here, one layer early - data.locale absent → allowed, and the default was assumed to fill it + data.locale absent → allowed; nothing is known yet beforeValidate — FIELDS # the language exists only from here getFallbackValue(locale) # fills an `undefined` value only duplicate → cloned from the SOURCE doc # NOT the default ordinary create → defaultValue ⇒ req.locale + beforeValidate — COLLECTION # appended by accessPlugin + restrictCreateToRequestLocale src/plugins/access/localeScopedWrites.ts + no top-level `locale` column → stands down + non-admin manager + data.locale !== req.locale → 403 # the complete rule beforeChange …The one door a
Wheredoes not reach —POST :id/transcribemainaddedPOST /api/meditations/:id/transcribeafter this branch opened (#984, #1011). It provesmeditations: updateinreq.localeand then reads the meditation and writesmeditation-transcriptswithoverrideAccess, so the access function's clause reaches none of it — the grant this PR narrows everywhere else stayed collection-wide there alone, and afr-only editor could delete anenmeditation's transcript and buy a new paid run.meditationTranscribe(req) src/collections/Meditations/endpoints/transcribe.ts requireManagerPermission(meditations, update) # a grant, in req.locale — never a language findByID(id, { overrideAccess: true }) + isOutsideWritableLocale(req, meditation.locale) → 403 phase / cooldown refusals # 409, 429 initTransaction → delete the old transcript, create the nextThe refusal sits ahead of every other refusal and ahead of the transaction, so a refused caller reaches no delete, no create and no queued run — a case asserts the previous transcript is still the one that was there.
isOutsideWritableLocaleis the predicaterestrictCreateToRequestLocalealready needed, so the comparison has one home rather than two.The Transcript tab hides the Transcribe-again button on the same condition (
mayTranscribeLocale) — a button that can only answer 403 is what the access layer avoided for Save. Mirrored there rather than imported: the module owning the refusal pullspayloadin with it, and the tab is a'use client'component.Scope — which collections this reaches
The reviewer's second call on 2026-10-26 was to make the rule the column's name, document it, and delete the machinery that asked each collection to declare its meaning. So nothing declares anything:
isLocaleScopedCollectionis now oneflattenedFields.some(field => field.name === 'locale'), and with it golocaleColumn,LocaleColumnMeaning,localeColumnMeaning, the undeclared verdict and theWeakMapthat memoized the declaration walk. The module is 113 lines, down from 160.The rename is what makes the documented rule true.
imports.localewas the one counterexample — the admin locale an upload happened in, which says nothing about who may write the row — so a presence rule would have scoped that collection the day it took a write grant. It isuploadLocalenow, by the same argument that renamedClients.localetwo rounds ago, anddocs/rules/access.mdstates the invariant where a field author meets it: never spell a columnlocaleunless it is the document's own language.A new column could still arrive, so the int guard changes question rather than going away:
role-based-access.int.spec.tswalks the booted config and names every collection carrying a top-levellocale—meditationsalone — so a second one reds the suite until someone confirms the column really is a language. It needs the booted config becauseimportsis plugin-created and so absent from thesrc/collectionsbarrel.Renames — two columns that were not document languages
Neither collection is localized, and both columns read as Payload's localization locale, which is what drew three review rounds asking whether the scoped set could be derived from the column's presence. It can — once the names tell the truth.
Both migrations are hand-written, and that is the point. Payload's generator adds the new column and drops the old one, which blanks the value on every row already in the database — every service's configured language, and the locale of any import still pending at the deploy, which would then create its classes in the default language instead of the uploader's.
ALTER TABLE … RENAME COLUMNcarries the values across, and forclientsALTER TYPE … RENAME TOcarries the enum: both member lists are byte-identical either side (183 codes, same order — only the field's name changed), so nothing is retyped and no row is recast. Neither column carries an index. Each generated.jsonsnapshot records the same end state a rename produces and is kept as generated; a probedb:migrations:createon the result writes no files, so the chain is clean.Types — the scope a
Whereis built fromroleScopeFromLocale's body only ever returned a locale code; its declared type made every caller write an unreachable branch for the one member it cannot return.RoleScopestays the parameter type of a permission check, where a caller may still state'union'deliberately (admin nav visibility).Preview
Verifying this by hand needs a per-locale editor and two meditations, and a fresh Railway preview carries neither — this repo configures no
previewUrl.seed, so there is nothing to run. Data: not seeded yet. The links open the right screens; creating the records is step 1 of Manual verification below.Test results
pnpm lint,pnpm format:check,tsc --noEmit,tsc -p tsconfig.test.json, 229 files / 2935 unit tests (77 s)role-based-access,event-importsandmeditations— 132 passedmigration-validator4 pass / 1 warn on the new one — the warn isRENAME, which is the changeflattenedFields),meditationsstill answers true through its unnamed tab, theduplicatehook is still attached to every collection, and the change's net direction is more scoping rather than less — an undeclared column used to be scoped by nothing. It enumerated the collections carrying a top-levellocalethree independent ways (grep, the generated types, the booted config) and found onlymeditations, and diffed the new snapshot against the previous one across every table: the sole difference anywhere isimports.localebecomingimports.upload_locale.Each guard was watched failing. With the access branch disabled, 7 of the 12 cases go red; the 5 that stay green are the controls for what must not change — the editor's own-language update and create, the Create button's capability check, an admin in either locale, and narrators. With only the
beforeValidatehook unwired, exactly one case goes red, onexpected 200 to be 403. This push watched the new invariant guard: withimports.uploadLocalespelledlocaleagain it reds on['imports', 'meditations']against['meditations'], which is the whole protection the declaration used to give.Manual verification
type: managerholdingmeditations-editorin French only —rolesis per locale, so switch the admin locale selector to French before ticking it. Create two meditations, one with the admin in English and one in French./admin/collections/meditations/<en id>). No Save button, and no History tab.POST /api/meditations/<en id>/transcribe?locale=franswers 403 and the existing transcript is untouched. On the French meditation the button is there and works.uploadLocalenow, andimportswrites are scoped by region, never by language.pnpm payload migrate:downputs each back underlocale.Notes for reviewer
transcribeshares with it — so "eliminate the file" is a choice between keeping it and splitting those acrossaccessConfigs.tsand a hook-named module. Your call on that thread; nothing is built for either.createanswers with a boolean on purpose.executeAccesstreats any object as a grant, so aWherethere would allow every language.localehas to pass the access gate, or the collection-level capability check — which carries no data at all — would hide the Create button from every per-locale editor. A case pins that it staystrue.createarm is defence in depth, not a forced split.restrictCreateToRequestLocaleis the complete rule: the field pass fills only anundefinedvalue (beforeValidate/promise.js:182), so a statedlocalereaches the hook untouched and is refused there too. The arm is kept because an access config scopingupdateanddeletebut notcreatereads as an oversight to the next reader, and it refuses a stated language one layer earlier. Nothing depends on it alone.updateByIDreports aWherepolicy that matched nothing as a refusal. Read offnode_modules/payload/dist/collections/operations/updateByID.js, not assumed.WeakMapearned its place while the answer cost a walk for a declaration, and afield.name === 'locale'comparison over the same flattened list does not.createAccessConfigthe locale branch returns before theuser-submissionsone, so a top-levellocalecolumn on that collection would replacemanagerSubmissionScope's row restriction with a language clause. No such column exists, and the int guard reds the day one does — its docblock carries this, since that guard is where somebody will be deciding.isOutsideWritableLocalerefuses nothing over an absent or non-string language, andscopeLocaleWrite's create arm already allowsdata.locale == null— the Create-button reason above. So a draft create statinglocale: nullcould in principle land a language-less row that any editor's transcribe call then passes. Nothing is built for it:localeisrequired, so the row can never be published;access: { update: () => false }means it can never be promoted to a real language;filterMeditationsByLocalehides it and the update clause does not match it, so not even its author can edit it. It grants no authority over any other language's content. Say if you want it closed anyway — the place would be the create hook refusing an absent value, not widening the predicate the endpoint also calls.payload-types.ts, whichaudit-contractsresyncs on merge, but neither repo reads either field: SahajAtlasWeb'sClientSchemadeliberately omitsclients.languageand strips it on parse, andimportsis restricted and in no project, so no client key has ever seen it. One downstream touch-up remains, and it is prose only: that schema's comment and its spec name the fieldlocale, which stops being SahajCloud's spelling the moment this merges. Not filed as its own PR yet, because it would make SahajAtlasWeb wrong in the meantime — it is correct until this lands.clients.localeandimports.localefor a few seconds after each is gone. The first has one reader, an operator script, and the admin degrades to a blank select. The second is read only by the import job, and only for a run queued inside that window, which would write its classes in the default language rather than the uploader's.beforeValidatehooks, not before them, so it reads whatever they settled on.testData.createManagerreturns the document as its create locale read it, souser:carries a flatrolesarray thatextractRolesgrants in every locale — only the auth strategy hydrates the per-locale record. The cases that turn on holding a role in one locale and not another go through REST, and the suite docblock says so.tests/PERF.md's pinned unit-lane counts are refreshed here: 229 files / 2935 tests. This push removed three unit cases with the declaration they covered, and PERF.md is the single writer of every tier figure.Detail
Why the access layer and not a hook, for the main fix.
docs/rules/access.mdmakes the collection access config the one answer to "who may write this row", andwithDerivedGrantsreadsupdateto derivereadVersions— so version history follows with no second edit. A hook alone would have left the admin edit view rendering a Save button that fails only on submit, and would have had to be mirrored for the versions read. ThebeforeValidatehook is what makes the create rule complete: it is the only one of the two that can see alocalethe field pass filled.Why reads are untouched.
filterMeditationsByLocalealready appends{ locale: { equals: req.locale } }tofindandcount, and deliberately skips writes — which is the gap this closes. Its versions-read guard (#745) is why the derivedreadVersionstranslates the clause ontoversion.rather than declining it.Why the flattened list is still the only shape. The declaration is gone but the hazard it was read with is not: sanitization splices every container that adds no path of its own — a row, a collapsible, an unnamed tab or group — straight into the top level, and
Meditations.localesits inside an unnamed tab. A walk over the rawfieldswould have to reproduce that rule to agree with a query, and reproducing it once missed an unnamed group: the column scoped at the access layer, the collection left without the create hook, and theduplicatebypass reopened. Both callers hand overflattenedFields, so there is no copy of Payload's rule to keep.Fixture pre-mortem.
Meditations.framescomposesjsonFieldValidationwith "at least one frame on update", so a frameless fixture fails validation before any case reaches its assertion — which is how the first run of this suite failed. Verified against the live field insrc/collections/Meditations/Meditations.ts; both fixture meditations now carry a frame. The other assumptions were checked the same way:enandfrare configured insrc/lib/locales/index.ts, andmeditations-editorgrantscreateandupdateonmeditationsinsrc/plugins/access/config/roles.ts.Why each rename needed a hand-written migration, in full. The drizzle prompt that decides rename-vs-create cannot be answered by a non-TTY run, and
scripts/migrate-create-pty.pyanswers it with the highlighted default, which iscreate— two prompts for this one, one for UP and one for DOWN, eight for theclientsrename. That is the right default when a change really is a drop plus an add, and the wrong one here, so the DDL was replaced and each snapshot kept.src/migrations/AGENTS.mdis where that trade is written down. Worth noting for the second one:pnpm db:migrations:createexited 0 with no files written, having printed the prompt, which the outcome table had no row for — the nearest one is silent CLI death, whose signal says "no output"./dev/nullis an EOF the prompt reads as an abort, so the documented hang needs no stdin at all. Both outcomes are rows now.Review findings dismissed, with reasons. A review pass proposed trimming four cases as redundant: the fr-only update refusal, the
?locale=enREST half, half the admin case, and the narrator case. Each is kept — each is a stated acceptance criterion on the ticket, and the?locale=enhalf is the only case proving the hydrated per-locale roles deny at the layer above this one.Write paths swept. The collection registers three endpoints (
Meditations.ts:113):lecturesandsongsareget, andtranscribeis thepostthis branch scopes. The rest:meditation-transcriptscarries no write grant in any role;cascadeFrameNodeChange'sdb.updateOneis reachable only from aframeswrite, which no role grants; the transcription job runs admin-only. BulkPATCH /api/meditations?where=…, the trash path and version restore all combine thisWherethrough Payload's own operations. The security pass re-ran the sweep across every permission-gated endpoint in the repo: the only other one isframes/by-narrator, andframesandnarratorsare shared across languages and carry nolocalecolumn, so no comparison is owed there.What the renames do not reach.
managersOnlyFieldAccesswas never onClients.languageand still is not — it sits in the Sahaj Atlas collapsible, which carries no field lock either side.RESTRICTED_COLLECTIONSnamesclientsandimportsby slug, so restriction is unaffected. Noselectundersrc/names either field, and neither field'stypeoroptionschanged, so no new value is accepted anywhere.imports.uploadLocalekeeps the collection's ownaccess.update: () => false, and itsbeforeChangestamp still overwrites the column on create, so a caller-supplied value cannot survive.The base merge. Four conflicts, all the unit-lane counts and the prose around them. Both sides' rows are kept in
tests/PERF.md: main's two 2026-10-23 sessions came from #1014, so they take the PR labelling this branch introduced and the numbering follows the dates. Tier 1's slowest per-edit selection takes main's wording — it re-measured the widest selection at 8.7 s on the 3 specs naming@/payload.config, the spec main added, which beats this branch's 8.0 simportGraphfigure, and that target is held to the slowest measurement rather than the newest.Closes #980