Repository navigation
fix(events): verify must refuse invalid data, bookkeeping must not - #848
Conversation
A visitor's registration or feedback vote was rolled back by a manager's data problem. Both are unguarded afterChange hooks, so the refused Events write killed the visitor's transaction: the registration taking the last seat was refused outright, and a vote was lost behind "Could not record your answer". Lift ExpireEvents' `updateBookkeeping` to `@/lib/events/systemWrite` so the rule — a derived-bookkeeping write must not re-validate stored data — exists once, and route both hook sites through it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_0169Drz2oavTmFWekTxiAMRF
Verifying an event with invalid stored data keeps failing — the data is fixed first. What was wrong is where that failure sent the manager. The tokenized email page answered every failure with "contact the admin team" plus a support mailto, so the one failure a manager can clear themselves read as ours. It now names the failing fields and links to the event's admin edit page, keeping the mailto for everything else. `POST /api/events/:id/verify` reported invalid data as `403 not allowed`, telling a manager who may edit the event to ask for access they have. It now answers 422 with the field errors, and keeps 403 for access. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_0169Drz2oavTmFWekTxiAMRF
Lift `storeInvalid` out of the ExpireEvents spec into `tests/utils/storeInvalidEvent.ts` — four specs seed that shape now. Each new case also asserts the identical write through plain `payload.update` is still refused, so it passes only because the code under test bypasses validation. Each was watched failing against the unfixed code before being kept. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_0169Drz2oavTmFWekTxiAMRF
… write From the review pass over the branch: - The verify endpoint's catch answered 403 for every failure, so a database outage would reproduce #842's own misdiagnosis. Classify instead: a validation failure is 422, a `Forbidden` is 403, anything else is ours. - Spread `req.context` inside `updateEventBookkeeping` rather than at each call site, so no caller has to carry that caution itself. - `EventBookkeeping` is the helper's ceiling, not any caller's allowance. Each writer keeps its own narrow `data` type, so lifting the helper does not widen what ExpireEvents may write unvalidated. - `depth: 0` on that write. No caller wants the doc, and the default depth of 2 populated four relationships per write inside a visitor's transaction. - Lift `labelText` to `@/lib/utilities/staticLabel` rather than adding a sixth copy of the StaticLabel rule. - Fold the duplicated seed and non-vacuity assertion into `tests/utils/storeInvalidEvent.ts`. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_0169Drz2oavTmFWekTxiAMRF
`architecture.md` described the bypass as the nightly job's own. Three writers use it now, and what it deliberately excludes — verifying an event — is the part worth stating beside it. Also name `storeInvalidEvent` in the test guide and coverage map: seeding a document its own validators refuse is not something a reader can infer from the helper list. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_0169Drz2oavTmFWekTxiAMRF
|
🤖 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 size of #842 — verify keeps refusing, the two unguarded hooks stop, the rule has one home. Nothing structural exceeds the ticket, and no cross-repo surface moves.
On the version-row overwrite you flagged: accepting it is right. Guarding the hooks instead loses the flag flip and the tally #842 asks for, so there is no cheaper option.
Findings
- should-fix — the failing-field list renders as one run-on paragraph (
actions.ts:87). - should-fix — the docblock still names a Verify button the banner lacks (
verifyEventAction.ts:12). - consider —
eventAdminUrlis event-shaped for a collection-generic URL (adminUrl.ts:4). - consider —
validationFailure.tsholds nothing event-specific (validationFailure.ts:13).
What was checked
depth: 0 is safe — Events' only afterChange ignores its args. unpublishAllLocales does not unpublish alone: expire-events.int.spec.ts:231,253,364,419 pin _status across advances. Payload internals unchecked — this checkout has no node_modules.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
The invalid-data outcome joins one line per failing field, but VerificationCard renders `message` in a plain `<p>` with no whiteSpace, so HTML collapsed every newline to a space and the manager got one run-on sentence. `pre-line` on `cardMessage` is the whole fix — no other outcome message on this card carries a newline. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LVCVACXsSqdMjcoyLdjvZG
That button does not exist. Every ladder message in EventVerificationNotice tells the manager to republish, and nothing in `src/` calls this endpoint — so the one file a reader comes to for this endpoint's contract described a UI that was never built. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LVCVACXsSqdMjcoyLdjvZG
`eventAdminUrl` was event-shaped for a URL that is not: deliverProposal built the same string for user-submissions by hand, a fourth copy the helper could not take. `adminDocUrl(collection, id)` in lib/utilities covers all four and takes a CollectionSlug, so a wrong slug no longer type-checks. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LVCVACXsSqdMjcoyLdjvZG
Nothing in the file is event-specific — it imports payload and staticLabelText and nothing else — so lib/events claimed a scope the code does not have. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LVCVACXsSqdMjcoyLdjvZG
|
Addressed all four adversarial-review threads. Head is 66394b5. Adopted
Adopted in part, left open
Lean gate green. 54 more passed across 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Ardnived
left a comment
There was a problem hiding this comment.
Consider. Would it make sense to create a separate EventMetadata collection to track these things so that they could be updated independently without having any problems / interaction with the event's actual configuration? Would that allow us to significantly reduce the amount of custom code?
`updateEventBookkeeping` named the caller's intent and hid the hazard. The function's one surprising property is that it skips validation, and every call site has to weigh that. The file follows the function, since it holds little else. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vsn7nDQ2RfkQ18Lu8sZdeN
Payload exports the joiner from `payload/shared`. Using it keeps a `NEXT_BASE_PATH` deploy working, which the hand-built string ignored, and leaves the segment rules Payload's to change. Output is unchanged for this config: `routes.admin` is unset, so the route is Payload's `/admin` default. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vsn7nDQ2RfkQ18Lu8sZdeN
No label in this config is a per-locale object: every `label:` in `src/` is a string, and none of the three Payload plugins we load defines the object form. The remaining shape is a label function, which all three call sites already answered with their fallback, since resolving one needs an i18n context none of them holds. So the helper narrowed `unknown` down to the one branch that ever fired, and the file cost more than the three `typeof` checks now in its place. Behaviour is unchanged. submission-proposal and event-verification cover all three sites and pass untouched. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_0157QxDbJ8DDwjCKFRW9WvHU
|
Head is dcc3d4a. Adopted
Lean gate green. 54 passed across Still open for you 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
`main` #849 moved the verify card's styles into the shared `_components/PublicPage`, deleting the block this branch had edited. Took that deletion and carried the one behaviour it would have dropped — `whiteSpace: 'pre-line'` on the outcome message — onto `outcomeMessage` in its new home, so the invalid-data field list still renders one line per field. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SgXW9zAoViUb96gwRhVuDo
|
Resolved the conflict with One file conflicted: That deletion would have silently dropped this PR's one behaviour there, so I carried it over: It is a shared style now, so Lean gate green. 56 passed across 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
|
No code changed this round. Both open threads asked for a ticket and for the change to stay out of this PR, so head is still 492a5b3. Filed, and both threads resolved
One correction. The audit count I gave you was 13 files. It is 15 — No upstream Payload issue is linked yet. I found three candidates and verified none, so filing one is an acceptance criterion on #852. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Summary
ExpireEventsreads it from there.Changes
src/lib/events/updateEventWithoutValidation.ts— new. Lifted fromExpireEvents, now shared by all three bookkeeping writers. Named for the property every call site must weigh, not for the caller's intent.src/lib/registrations/fullness.ts,src/collections/UserSubmissions/hooks/eventFeedback.ts— route through it. Both are unguardedafterChangehooks, so the refused write killed the visitor's transaction.src/collections/Events/endpoints/verifyEventAction.ts— classify the failure instead of answering 403 for all of them.src/app/(frontend)/events/verify/actions.ts— name the failing fields and link to the event's edit page; keep the supportmailtofor everything else.src/app/(frontend)/events/verify/VerificationCard.tsx— render that field list as separate lines. A plain<p>collapsed every newline.src/lib/utilities/adminUrl.ts,src/lib/utilities/validationFailure.ts— one home each for two rules.adminUrl(path)is built on Payload's ownformatAdminURLand carriesadminDocUrlplus the twoManagers.tsauth-email links;validationFieldErrorstwo call sites.src/collections/UserSubmissions/lifecycle/proposedChanges.ts— reads a field's label itself, like the two sites invalidationFailure.ts. See "Reading a field label" below.src/collections/Managers/Managers.ts— the verify and reset links were the last hand-built absolute admin URLs. Both ignoredNEXT_BASE_PATH.tests/unit/event-localize-status-guard.spec.ts— new. PinslocalizeStatusoff on Events, which is the only thing makingunpublishAllLocalesa validation skip rather than a mass unpublish.Preview
⚠ A preview forks configuration, not data, so both are empty and neither can show the failure itself. See Manual verification.
Test results
lint,typecheck,typecheck:tests,test:unit(2164 passed)event-verification,expire-events,event-feedback,registrations-fullness; 53 more across the twouser-submissionsspecs covering the label readcollections/*/endpoints/). No findings.Manual verification
No preview can hold an event with invalid stored data, and none can be created through the API, since that state is the defect itself. The specs seed it at the db layer instead (
tests/utils/storeInvalidEvent.ts). Against a database that has one (events 176 and 651 in production):POST /api/events/<id>/verifyas a manager who may edit it → 422 with the field errors. As a manager who may not → 403.registrationsFullflips.Notes for reviewer
applyVerificationandreview.tsare deliberately untouched.unpublishAllLocalescannot unpublish an event here, and a spec now says so. Payload gates the per-locale_status: 'draft'write onversions.drafts.localizeStatus, which Events does not set. Prose inEvents.tswas the only thing holding that, and this PR moves the write onto visitor traffic — soevent-localize-status-guard.spec.tsasserts it.registrationsFullgot no publish gate, following the ticket's recommendation: the flag is derived bookkeeping and is harmless on an unpublished event. Feedback already gates on published (eventFeedback.ts)./admin/loginfor a logged-out manager. Deliberate — minting a session from a 10-day emailed verify token is a real widening and belongs to feat(auth): passwordless email-link login and manager invitations #664 with its own review.routes.admin) and chore(events): decide whether the unpublishAllLocales validation skip stays #852 (theunpublishAllLocalesvalidation skip).Detail
Reading a field label
An earlier revision of this PR lifted a shared
staticLabelTexthelper to read a Payloadlabel, which is typedLabelFunction | StaticLabel— a string, a per-locale object, or a function. You asked twice whether it earned a file. It did not, and the reason is narrower than my first answer: this config can only ever produce the string. Nolabel:insrc/is written in the object form, and neither is any in@payloadcms/plugin-form-builder,plugin-seoorplugin-nested-docs. A label function is possible, but all three call sites already answered one with their own fallback, since resolving it needs ani18nnone of them holds.So the helper narrowed
unknowndown to the one branch that ever fired. Each of the three sites now readstypeof label === 'string'itself, and the file is gone.The
formatAdminURLauditEvery
/adminstring insrc/was read. Two were absolute URLs leaving the app and are nowadminUrl(...). The rest are in-panelhrefs, and they stay literals: Next prependsbasePathto aLinkitself, which is why Payload defaultsincludeBasePathto false onceadminRouteis given — soformatAdminURL({ adminRoute: '/admin', path })would only restate the string it replaced. Adapting to a configuredroutes.adminis a different change: it touches 15 sites, three of which cannot calluseConfig(). Filed as #851, not taken here.Dismissed review findings
updateBookkeepingwrapper inExpireEvents, now a pass-through. Kept: it is where that job's own four-fielddatatype lives. Deleting it would let its four call sites writesystemMeta,confidenceScoreandregistrationsFullunvalidated and type-check clean — the guard would have weakened for every caller at the moment more callers started relying on it.afterChangehooks eachfindByIDthe same event per vote. Real, pre-existing, and outside this ticket. Not filed: it is a cost on a path this PR already makes cheaper, not a defect.Non-vacuity
Every new case also asserts the identical write through plain
payload.updateis still refused, so it passes only because the code under test bypasses validation. Each was then watched failing against the unfixed code and restored: with the fix reverted, all five behaviour assertions go red (422→400, warning→error, and the three bookkeeping cases). ThelocalizeStatusguard was watched red withlocalizeStatus: trueset on Events, at the real site, then restored.The
pre-linefix carries no spec. A style constant can only be asserted by restating it, and the spec that covers this outcome already pins the href and the field names.The label read carries no new spec either, and deliberately: it is a refactor with no behaviour to pin that
submission-proposalandevent-verificationdo not already pin. Those specs passing unchanged is the whole claim.Fixture pre-mortem
storeInvalidEventassumes Events is drafts-enabled, so alatest: trueversion row exists andupdateByIDreads the document from it. Verified againstsrc/collections/Events/Events.ts(versions: { drafts: true }); the helper throws rather than passing when that row is missing.storeEventOverImageLimitderives its row count fromEVENT_IMAGE_LIMITrather than a literal, so raisingmaxRowscannot silently make the seed valid.Not done
No migration — nothing schema-affecting changed. No OpenAPI entry for the new 422:
POST /api/events/:id/verifyis deliberately absent fromCUSTOM_ENDPOINT_PATHS, being a manager-only admin action.Closes #842
🤖 Written by the sydevs autonomous loop — see what this is