Repository navigation
fix(events): serve only published, placed events in the geojson feed - #1167
Conversation
A live-preview request lifts the published-only access clause, so the geojson feed carries drafts. Payload skips `required` on a draft save, so a never-published draft can have no region, and the Atlas widget parses every feature's `region` as an object: one null fails the whole feed and the preview shows the error screen. Production holds two such drafts (events 1932 and 2002), which broke every Region and Event live preview. The feed now ANDs `region exists` onto every read, alongside the finished-events filter. An event with no region has no place on the map and no webPath, so nothing a consumer could render is lost. Fixes SAHAJATLAS-WEB-2 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🚅 Deployed to the SahajCloud-pr-1167 environment in sahajcloud
1 service not affected by this PR
|
A live-preview token lifts the published-only access clause, which put every unpublished draft on every previewed map. The feed now requires `_status: published` for every caller. The previewed document never needed the feed: the widget renders it, and frames its map marker, from its own `draft=true` read. The `region exists` clause stays. Publishing enforces `required`, but deleting a region nulls `events.region_id` (`ON DELETE SET NULL`), and a published event with no region would fail the widget's parse for every visitor, not only in preview. Co-Authored-By: Claude Opus 5.5 <[email protected]>
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The diff is the size of its problem: two clauses, a doc line, three cases. Both are correct and neither touches an ordinary client — the access layer already applies _status: published there, so PUBLISHED bites only on a preview request, and region is a single required relationship, so exists is region_id IS NOT NULL.
One question about the approach. The leak lives in createAccessConfig (plugins/access/accessConfigs.ts:184), which lifts the published-only clause for a live-preview request on every drafts collection. Closing it per feed leaves that lift open everywhere else. The widget only needs a draft by id, so narrowing the branch would fix the class and delete PUBLISHED from this diff.
Findings
- should-fix — the clause is re-closed at one door while the access-layer lift stays collection-wide —
geojson.ts:60. - consider —
draft: 'true'in the new test does nothing —events-geojson.int.spec.ts:329.
What was checked
Read whole: geojson.ts, lifecycle/finished.ts, accessConfigs.ts, previewSecret.ts, Events.ts.
Ladder, on the two new constants: notFinishedWhere already owns the sibling clause, I checked whether they belong beside it. The only other events read that ANDs it (atlas/sitemap/resolve.ts:93) already filters region in <ids> and carries no preview token — so no. The file's four existing helpers each have one caller and a stated why.
Consumer side, SahajAtlasWeb: AgnosticFeedEventSchema (types/event.ts:149) still requires region. live-preview/request.ts attaches the token and draft=true to every request, which is how /api/events (the titles sliver, fetch.ts:264) still reads drafts. live-preview/populate.ts refuses any endpoint that is not <collection>/<id>, so the claim that the previewed document comes from its own read holds.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
|
@sydevs-bot address |
The handler forwards no `draft`, so the parameter reads as dead and the next reader deletes it. It is there because the widget's live-preview decorator sets it on every request, which is the shape the cases reproduce — the fix had to land in the read's `where` for that reason. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjY7r47DsEKBeR3dvku
|
Both review threads answered. Merged
Lean gate green. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
|
I could not apply the relay here, so this is the step left for you.
🤖 sydevs dispatcher |
Problem
Live preview of a Region or Event shows the Atlas error screen (Sentry SAHAJATLAS-WEB-2, 31 events since 2026-11-15, all on
sahajatlas.compreview loads).A live-preview request lifts the published-only access clause, so
GET /api/events/geojsonalso returns drafts. Payload skipsrequiredon a draft save, so a draft that was never published can have noregion. The widget'sAgnosticFeedEventSchemaexpectsregionto be an object, so one null fails the whole feed parse. The view boundary then renders the error.Production has exactly two such rows, both drafts that were never published: events 1932 (Cornwall, CA) and 2002 (empty). They match the two zod issues in the Sentry event (
[444].properties.region,[487].properties.region). The same leak also put every unpublished draft (47 today) on every previewed map.Fix
The feed now ANDs two clauses onto every read, next to
notFinishedWhere:_status: published, for every caller, including a live-preview request. The previewed document never needed the feed: the widget renders it from its owndraft=trueread, and frames its map marker from that read too. A Region preview now shows the events a visitor would see.region exists. Publishing enforcesrequired, but deleting a region nullsevents.region_id(ON DELETE SET NULL). Such an event would fail the widget's parse for every visitor, not just in preview.Like the finished-events filter, both run inside the read, so
totalDocsand pagination stay correct, and a caller'swherecannot opt out. The OpenAPI description documents both.Tests
New cases in
events-geojson.int.spec.ts›drafts and region-less events:I removed each clause in turn and confirmed its own case fails:
expected [3, 2, 1] to not include 3withoutPUBLISHED, andexpected [5, 2, 1] to not include 5withoutPLACED_IN_REGION.Ran locally: the whole
events-geojsonint spec (30/30), theopenapi-custom-endpointsunit spec,tscforsrc/and for the tests, ESLint and Prettier on the touched files.No widget change is needed. Once this deploys, the preview feed parses again.
🤖 Generated with Claude Code