Repository navigation
feat(translations): add a hidden Sahaja Yoga glossary global - #885
sydevs-bot wants to merge 13 commits into
Conversation
`accessPlugin` carried two inline copies of the `admin.hidden` resolution, and only the collections' copy honoured a declaration: the globals branch replaced `hidden` with the project rule outright, so no global could hide itself from the admin menu at all. Collections could, which is what kept the gap invisible. `resolveHidden` is the one rule both branches now call. An explicit `true` wins outright, a declared function is ORed with the project rule, and anything else leaves the project rule alone — `false` means "no opinion", because an entity able to opt out of project visibility would appear in the nav of a project it has no place in. Collections' behaviour is unchanged by construction: the extracted function is the branch they already ran. Refs #883 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01U6z3jUTE1AK9vFM2EHGVXv
One row per Sahaja Yoga term, carrying that term's spelling in each locale.
Speech-to-text misspells these words and translators render them
inconsistently, so the transcription prompt and the translation checks read
one list rather than each carrying a copy. No drafts or versions: it is
reference data.
Three things keep it out of reach, and they are not interchangeable:
`admin.hidden: true` hides it from every manager, admins included, which
only works because the resolution now respects a declaration. That governs
the nav and the admin routes and nothing else.
`RESTRICTED_COLLECTIONS` is what stops it being READ. The global is in no
project, and for implicit read that means *shared* — readable by every
published client key. The entry is the first in that set that is a global;
nothing about the mechanism was collection-specific, since step 4a asks
about a `ContentSlug`.
`ALWAYS_HIDDEN_COLLECTIONS` keeps it out of `/api/docs`. Tier 2 would mark
it anyway, so the entry states intent rather than doing the work — the same
shape as the `user-submissions` POST. What had to be confirmed rather than
assumed is that the filter reaches `/api/globals/{slug}` at all, and it
does: `getCollectionFromPath` reads a global's slug there.
`key` carries no database uniqueness, because Payload has no unique
constraint inside an array, so the array's own validator is the whole
enforcement — two rows sharing a key make every consumer's lookup
ambiguous. Deliberately absent from `CACHE_TTLS.globals`: nothing reads this
over the API.
Refs #883
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01U6z3jUTE1AK9vFM2EHGVXv
56 terms in the seven locales `data.json` carries. While the global is hidden from the admin that file is its source of truth — nothing in the CMS can edit it, so a change goes into the file and a re-seed carries it. English is written first, and the row ids come back from that write. `key`, `category` and `keepAsIs` are not localized, so they live on the row rather than in a per-locale cell, and Payload matches an incoming array row to a stored one by `id` alone. Omit the ids and a second locale does not translate the English rows, it replaces them: 56 new rows holding only that locale's spellings, with English gone. A locale whose rows cannot be matched is refused rather than appended, so the failure is an error instead of 112 rows. A locale with no value for a term is written `null`, never English. Writing `null` rather than omitting the field is what makes a re-run idempotent — an omitted localized field keeps whatever is stored, so a value deleted from the file would otherwise survive forever. A `keepAsIs` term is seeded in English alone, and consumers use that spelling everywhere. The locale set is read off the file rather than declared here, and a code the CMS does not configure is an error: the write would be refused anyway, and the file is the only place the mistake can be fixed. Refs #883 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01U6z3jUTE1AK9vFM2EHGVXv
Every assertion here was watched failing against the real defect site.
The read matrix goes over REST rather than through `hasPermission`, because
`docs/rules/access.md` is explicit that adding a slug to
`RESTRICTED_COLLECTIONS` proves nothing on its own. Dropping that entry turns
both refusals into 200s.
Two things about that matrix were wrong before they were right. The manager
fixture HOLDS a role: `hasPermission` denies a manager with no resolvable
roles at step 3, before implicit read is considered, so a roleless fixture
answered 403 whether the global was restricted or not. And a 400 is not a
403 — the usage plugin refuses a client global read carrying no `select`,
and refuses `depth > 1` with no `populate`, and both were observed passing a
bare "not 200".
The dry-run case runs before anything has seeded, and that ordering is the
case. A dry run performed afterwards has no observable: it writes the file's
own data back, and `updatedAt` does not move on a global whose contents are
unchanged — measured, by removing the guard and watching the assertion stay
green.
`resolveHidden` is driven directly and through `accessPlugin` over a real
config. The second half is the one that matters: the rule can be perfect and
still unreachable if a call site drops it, which is exactly where the
original defect lived.
The `/api/docs` case says which tier it pins. It stays green with the
`ALWAYS_HIDDEN_COLLECTIONS` entry deleted, since tier 2 hides anything in no
project — what it does pin is that the filter reaches `/api/globals/{slug}`
at all, and the visible sibling read is what keeps that non-vacuous.
Refs #883
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01U6z3jUTE1AK9vFM2EHGVXv
Two guides said never to hand-write `admin.hidden` on a global, which was sound advice while the plugin discarded it. Both now carry the one case it is for — hiding an entity from admins too — and, beside it, the thing that case makes easy to get wrong: hiding governs the nav and the admin routes, and leaves `GET /api/globals/<slug>` untouched. A hidden global that should not be read needs `RESTRICTED_COLLECTIONS` as well, and the two layers are independent. `docs/rules/access.md` claimed all four collections in no project were named in that set. A global is in it now, so the claim is restated over both kinds, and the entry says why it is there — not personal data, but reference data that "in no project" would publish to every client key. `docs/rules/openapi.md` gains the half that is easy to assume: the list reaches a global because the path parser reads a slug off `/api/globals/`, while tier 2 is what actually hides this one. `seeds/AGENTS.md` carries the row-id rule, since the failure it prevents — replaced rows rather than translated ones — leaves no error behind. Refs #883 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01U6z3jUTE1AK9vFM2EHGVXv
`updateGlobal` already returns the rows it wrote, ids and all, so the read-back after the English write was a second query recovering what was in hand. Deleting it takes with it a try/catch, a null-returning error path and the sentinel that checked it. The seed's own idempotency cases prove the ids still arrive — they go red when the mapping is dropped. The dry run counted spellings by building 56 throwaway rows per locale; the count comes off the file directly now. `DEFAULT_LOCALE` comes from `src/lib/locales` rather than being re-declared, so the seed cannot disagree with Payload's own default. The duplicated `payload` guard collapses to one. `TermRow` in the global bought nothing — `Array.isArray` already narrows, and the name collided with the importer's own unrelated `TermRow`. The `accessPlugin` comment restated the function it calls, and the rule has one home in `resolveHidden`'s docblock. The int spec's `as unknown as Promise<SahajaGlossary>` was copied from a sibling whose global has a dynamic shape. `findGlobal` already resolves to the generated type here, so the cast was discarding real checking inside `termFor`; removed, and `typecheck:tests` agrees. The unit spec's six copies of the same cast become one `ask()` helper, and its absent-user case is dropped — `localizedRoleScope.spec.ts` already pins `createHidden` with no user, and the case exercised no branch of the resolution. Refs #883 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01U6z3jUTE1AK9vFM2EHGVXv
The English write sent `terms` with no row ids, so Payload treated all 56 as new, deleted every stored row and inserted replacements — `sahaja_glossary_terms_locales` is `ON DELETE cascade`, so each dropped row took every locale's spelling with it. What made it invisible is that the symptom looks like success. The count stays 56, no error is raised, and every locale `data.json` carries is rewritten from the file immediately afterwards and comes out correct. Only a locale the file does not carry is destroyed — `cs`, `pl`, `uk` — and its `translatorNotes` survives in the parent row, so even the global does not look emptied. Measured: a `cs` spelling went to `undefined` and every row id changed. So the stored ids are read BEFORE the first write rather than after it. Reading them back from the English write still gives the other locales correct ids, which is why that version passed every case the spec then had — the destruction has already happened by the time they are read. A key with no stored row is a new term and correctly goes id-less; a stored key absent from the file is deleted, which is what "the file is the source of truth" means. A failed read aborts the seed instead of continuing with an empty map, since an empty map is indistinguishable from "delete everything". The regression case asserts the `cs` spelling and the row ids directly, not just the count: a rebuild that happened to restore the same spellings would still renumber the rows, and would still have destroyed what the file does not carry. Watched failing against the one-line defect. Refs #883 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01U6z3jUTE1AK9vFM2EHGVXv
It had been missing `translations` and `wm-app-translations` since each landed, and this branch would have made it three. It now points at `VALID_SCRIPTS`, which is the list, so the next script added leaves one name to update rather than two places to disagree. Refs #883 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01U6z3jUTE1AK9vFM2EHGVXv
|
🚅 Deployed to the SahajCloud-pr-885 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 matches the ticket, and the one refactor is the one it asked for. It is complete: the only other collections-only transform holds no global, because no role grants translate on one.
The escalated redesign's counting holds — I verified what the PR body did not. Only managers, clients, users, user-submissions and sahaja-glossary sit in no project, and all five are listed. All 7 roles declare a project, and payload-* has explicit admin-only access. A net deletion, in its own PR, and it should also close a project-less role: step 4a hands project || null, read as the admin view.
Findings
should-fix— a locale falls back toen, so untranslated reads as English.SahajaGlossary.ts:93consider— theALWAYS_HIDDEN_COLLECTIONSentry is inert.specFilter.ts:44consider— the comment narrates removed behaviour.accessPlugin.ts:141
What was checked
Whole diff bar the generated snapshot, plus permissions.ts, roles.ts and systemEntities.ts. Membership counted from PROJECTS.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
`docs/rules/code-comments.md` forbids narrating the change: a comment has to read right to someone who never saw the diff. `visibility.ts`'s docblock, `docs/rules/admin-ui.md` and `src/globals/AGENTS.md` each carry the #883 story already. The breadcrumb stays. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012bK4Mu4sSm3FKtFYKht4mA
Two of the three paragraphs explaining the `sahaja-glossary` entry said only that tier 2 already marks the path. What earns a line is the state the entry guards: the global joining a project. The spec's own note stays — it is what stops a later reader taking that assertion for proof of the entry. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012bK4Mu4sSm3FKtFYKht4mA
`buildPayloadLocales` gives every non-English locale `fallbackLocale: 'en'`, so a plain read of this global hands back the English spelling wherever a locale has none — which is exactly the state an empty `term` exists to report. Both guides asserted the distinction holds without naming the read that erases it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012bK4Mu4sSm3FKtFYKht4mA
|
Addressed all three adversarial-review threads. Pushed Adopted — one commit per thread:
Nothing rebutted, nothing to ask. Lean gate green: lint, both typechecks, 2285 unit tests. No behaviour changed — the diff is comments and two guides. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
|
The red Railway's preview build for Green on Three previews failed inside one 84-second window. Every build finishing after it passed.
The merge commit brought only main's two auth commits. It touched no No fix exists to port. Redeploying the preview needs the Railway dashboard, which this run cannot reach. #880 and #879 carry the same red status. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Summary
sahaja-glossary: one row per Sahaja Yoga term, with that term's spelling per locale, seeded fromseeds/sahaja-glossary/data.json(56 terms, 7 locales).accessPluginwas discarding anyadmin.hiddena global declared.RESTRICTED_COLLECTIONSdoes.Changes
src/globals/SahajaGlossary/— the global itself. Its docblock carries the one thing a consumer must do: read withfallbackLocale: false.src/plugins/access/visibility.ts— newresolveHidden, the one rule both the collections and globals branches now apply. It replaces two divergent inline copies inaccessPlugin.ts, only one of which honoured a declaration.src/plugins/access/config/projects.ts—sahaja-glossaryjoinsRESTRICTED_COLLECTIONS, the first entry there that is a global.src/plugins/openapi/specFilter.ts— joinsALWAYS_HIDDEN_COLLECTIONS.seeds/sahaja-glossary/— the data file and its importer, registered inrun.ts,expectedCounts.tsand the seed route.Preview
/api/docs— nosahaja-glossarypathGET /api/globals/sahaja-glossary— 200 as the signed-in adminThe preview carries no content, so the global reads empty there until it is seeded.
Migration
src/migrations/20261002_213202_sahaja_glossary.tssahaja_glossary,sahaja_glossary_locales,sahaja_glossary_terms,sahaja_glossary_terms_localesand one enum. Touches no existing table, so no data is read or transformed.downdrops exactly those four tables and the enum.migration-validator: 4 pass, 0 fail (its two warnings are readingdown's ownDROP TABLEs, and its D1 note does not apply to Postgres).Test results
pnpm lint,pnpm typecheck,pnpm typecheck:tests,pnpm test:unit(2285 passed)sahaja-glossary14, plusproject-visibility,globals-client-reads,role-based-access,translations-globals— 135 passed togetherNotes for reviewer
One real defect was found during the review pass and fixed here — worth knowing because the symptom looks like success. The English write originally sent
termswith no row ids, so Payload deleted all 56 stored rows and inserted replacements; the terms' localized-values table isON DELETE cascade, so each dropped row took every locale's spelling with it. The count stays 56, nothing errors, and every localedata.jsoncarries is rewritten immediately afterwards and comes out correct — only a locale the file does not carry (cs,pl,uk) is destroyed, and itstranslatorNotessurvives in the parent row. Reading the ids back after the English write, which is what the ticket describes and what I first built, gives the other locales correct ids and still loses the data. The ids are now read before the first write. Measured, then pinned: the regression case asserts thecsspelling and the row ids directly, and fails against the one-line defect.Two findings declined, both legitimate, both widening this PR:
seeds/translations/import.ts,seeds/wm-app-translations/import.ts). Extracting it means editing a seed that publishes locales, with real regression risk. Its own PR.termsErrorOrNullin the int spec is the third copy of the same Payload field-error extractor (available-locales,wm-web-translations-seed). Extracting it edits two unrelated specs.One finding escalated to you rather than acted on, because it is an access-control redesign. A review lens argues this change should have made
hasPermissionstep 4a fail closed — test project membership directly — and deletedRESTRICTED_COLLECTIONS, rather than adding a fifth entry to a listdocs/rules/access.mditself calls "a holding pattern". Its claim is that the blast radius is zero entities: 5 collections/globals sit in no project and all 5 are already in the set,payload-*entities never reachhasPermission, and no role is project-less. The adversarial review has since counted those five and all seven roles and confirms it, and adds that a project-less role should close too. Still a net deletion in its own PR, not inside a feature PR.Detail
Why three mechanisms, and which are load-bearing. They are not interchangeable:
admin.hidden: trueRESTRICTED_COLLECTIONSALWAYS_HIDDEN_COLLECTIONSx-internalin the specThe third is kept because the ticket asked for it and because
clientssits in both lists for the same belt-and-braces reason (docs/rules/openapi.md). It earns one line, not three: tier 2 covers the path only while the global is in no project, so the entry is what holds if it ever joins one. The spec case says which tier it pins, so nobody reads it as proof of the entry.What had to be confirmed rather than assumed: that the OpenAPI filter reaches
/api/globals/{slug}at all. It does —getCollectionFromPathmatches the globals prefix before the collection one. The spec's sibling read on a project global stays visible, which is what keeps that non-vacuous.resolveHiddenis behaviour-preserving for collections by construction — it is the branch they already ran, extracted.A ? true : B≡A || Bhere. It also removes work:createHiddenis now built once at config time rather than per nav render, anddeclared === truereturns before it is constructed at all.Three assertions were vacuous before they were right, each caught by reintroducing the defect:
hasPermissiondenies a manager with no resolvable roles at step 3, before implicit read is considered, so a roleless fixture answered 403 whether the global was restricted or not.select, and refusesdepth > 1with nopopulate; both were observed passing a bare "not 200". Hence?select[terms]=true&depth=1.updatedAtdoes not move on a global whose contents are unchanged — measured by removing the guard and watching the assertion stay green.Declined:
keyuniqueness in the database. Payload has no unique constraint inside an array, so the array's ownvalidateis the whole enforcement. Verified live rather than assumed — Payload hands the validator the row array, so it is not dead code.Security review: clean. Both authorization-relevant edits are monotonically restrictive, the new seed surface is entirely behind the route's existing admin gate (
inlineDatais read after the 403), andinlineContentis a fixed-key lookup rather than a caller-chosen path. Also ruled out: the edge cache (absent fromCACHE_TTLS.globals, so no public copy), theclientEnglishFallbackoverrideAccessread (registered per-global on the three translations globals only), and every otherfindGlobalcaller (all constant slugs, so no confused-deputy read).Docs. Two guides said never to hand-write
admin.hiddenon a global, which was sound while the plugin discarded it; both now carry the one case it is for and, beside it, that hiding is not restricting.docs/rules/access.mdclaimed all four no-project collections were listed — restated over both kinds.seeds/AGENTS.md's API-route script list named five of eight scripts and had been missing two since they landed; it now points atVALID_SCRIPTS.src/globals/AGENTS.mdasserted that an untranslated spelling is never filled from English — true of what is stored, and false of a default read, so it now namesfallbackLocale: falseas the consumer's job.Not done, deliberately: no
CACHE_TTLS.globalsentry — nothing reads this over the API, and DYNAMIC is the fail-safe direction.Closes #883
🤖 Written by the sydevs autonomous loop — see what this is