Skip to content

fix(events): verify must refuse invalid data, bookkeeping must not - #848

Merged
sydevs-bot merged 18 commits into
mainfrom
claude/fix-842-event-write-validation
Sep 25, 2026
Merged

sydevs-bot merged 18 commits into
mainfrom
claude/fix-842-event-write-validation

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • A visitor's registration or feedback vote was rolled back by a manager's data problem. Both now write.
  • Verifying an event with invalid stored data still fails — what changed is where that failure sends the manager.
  • The rule "a derived-bookkeeping write must not re-validate stored data" now exists once, and ExpireEvents reads it from there.

Changes

  • src/lib/events/updateEventWithoutValidation.ts — new. Lifted from ExpireEvents, 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 unguarded afterChange hooks, 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 support mailto for 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 own formatAdminURL and carries adminDocUrl plus the two Managers.ts auth-email links; validationFieldErrors two call sites.
  • src/collections/UserSubmissions/lifecycle/proposedChanges.ts — reads a field's label itself, like the two sites in validationFailure.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 ignored NEXT_BASE_PATH.
  • tests/unit/event-localize-status-guard.spec.ts — new. Pins localizeStatus off on Events, which is the only thing making unpublishAllLocales a validation skip rather than a mass unpublish.

Preview

  • Admin events list — where the new "Edit this event" link points
  • Admin login — the gate a logged-out manager following that link lands on

⚠ A preview forks configuration, not data, so both are empty and neither can show the failure itself. See Manual verification.

Test results

  • Lean gate: ✓ lint, typecheck, typecheck:tests, test:unit (2164 passed)
  • Targeted specs: 75 passed across event-verification, expire-events, event-feedback, registrations-fullness; 53 more across the two user-submissions specs covering the label read
  • Latest review round: no code changed — the two open threads asked for tickets, not edits. Last gate run stands.
  • Security review: ran (the diff touches collections/*/endpoints/). No findings.
  • Build: N/A — Railway builds the preview

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):

  1. Open that event's reminder email link. The page should name the failing field and offer Edit this event, not the support mailto. Each failing field is its own line.
  2. POST /api/events/<id>/verify as a manager who may edit it → 422 with the field errors. As a manager who may not → 403.
  3. Register for it up to its limit → the registration is accepted and registrationsFull flips.

Notes for reviewer

  • The asymmetry is the point, and it was your call (2026-09-23): verify keeps refusing, bookkeeping stops refusing. applyVerification and review.ts are deliberately untouched.
  • unpublishAllLocales cannot unpublish an event here, and a spec now says so. Payload gates the per-locale _status: 'draft' write on versions.drafts.localizeStatus, which Events does not set. Prose in Events.ts was the only thing holding that, and this PR moves the write onto visitor traffic — so event-localize-status-guard.spec.ts asserts it.
  • Accepted, per the ticket's open question: a bookkeeping write overwrites the newest version row rather than appending, so it can land on top of a manager's unsaved draft version. Both ways of skipping validation behave this way, so there is no third option. This now happens on registration and vote traffic, not only nightly — the one consequence of this PR I would most want a second opinion on.
  • registrationsFull got 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).
  • The edit link lands on /admin/login for 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.
  • Both remaining review threads are settled and resolved. You asked for a ticket on each and for neither change here: refactor(admin): weigh building in-panel hrefs from routes.admin #851 (in-panel hrefs against a configured routes.admin) and chore(events): decide whether the unpublishAllLocales validation skip stays #852 (the unpublishAllLocales validation skip).
  • Your EventMetadata question is option 3 of chore(events): decide whether the unpublishAllLocales validation skip stays #852, not this diff. It is a schema change with a migration, and it would replace this fix rather than extend it.
Detail

Reading a field label

An earlier revision of this PR lifted a shared staticLabelText helper to read a Payload label, which is typed LabelFunction | 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. No label: in src/ is written in the object form, and neither is any in @payloadcms/plugin-form-builder, plugin-seo or plugin-nested-docs. A label function is possible, but all three call sites already answered one with their own fallback, since resolving it needs an i18n none of them holds.

So the helper narrowed unknown down to the one branch that ever fired. Each of the three sites now reads typeof label === 'string' itself, and the file is gone.

The formatAdminURL audit

Every /admin string in src/ was read. Two were absolute URLs leaving the app and are now adminUrl(...). The rest are in-panel hrefs, and they stay literals: Next prepends basePath to a Link itself, which is why Payload defaults includeBasePath to false once adminRoute is given — so formatAdminURL({ adminRoute: '/admin', path }) would only restate the string it replaced. Adapting to a configured routes.admin is a different change: it touches 15 sites, three of which cannot call useConfig(). Filed as #851, not taken here.

Dismissed review findings

  • Delete the updateBookkeeping wrapper in ExpireEvents, now a pass-through. Kept: it is where that job's own four-field data type lives. Deleting it would let its four call sites write systemMeta, confidenceScore and registrationsFull unvalidated and type-check clean — the guard would have weakened for every caller at the moment more callers started relying on it.
  • Two afterChange hooks each findByID the 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.update is 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). The localizeStatus guard was watched red with localizeStatus: true set on Events, at the real site, then restored.

The pre-line fix 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-proposal and event-verification do not already pin. Those specs passing unchanged is the whole claim.

Fixture pre-mortem

storeInvalidEvent assumes Events is drafts-enabled, so a latest: true version row exists and updateByID reads the document from it. Verified against src/collections/Events/Events.ts (versions: { drafts: true }); the helper throws rather than passing when that row is missing. storeEventOverImageLimit derives its row count from EVENT_IMAGE_LIMIT rather than a literal, so raising maxRows cannot silently make the seed valid.

Not done

No migration — nothing schema-affecting changed. No OpenAPI entry for the new 422: POST /api/events/:id/verify is deliberately absent from CUSTOM_ENDPOINT_PATHS, being a manager-only admin action.

Closes #842

🤖 Written by the sydevs autonomous loop — see what this is

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
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-848 September 23, 2026 21:13 Destroyed
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 23, 2026
@sydevs-bot

sydevs-bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running
CI fix 1

recent dispatches
  • 18:01Z address-review · attempt 1 · session · done
  • 18:01Z address-review · attempt 1 · session
  • 17:16Z resolve-conflicts · attempt 1 · session · done
  • 17:16Z resolve-conflicts · attempt 1 · session
  • 15:06Z address-review · attempt 1 · session · done

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐 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 — eventAdminUrl is event-shaped for a collection-generic URL (adminUrl.ts:4).
  • consider — validationFailure.ts holds 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

Comment thread src/lib/events/adminUrl.ts Resolved
Comment thread src/lib/utilities/validationFailure.ts Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 23, 2026
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
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-848 September 23, 2026 21:37 Destroyed
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Addressed all four adversarial-review threads. Head is 66394b5.

Adopted

Adopted in part, left open

Lean gate green. 54 more passed across event-verification and user-submissions-review-lifecycle.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 23, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review September 23, 2026 21:49
@sydevs-bot
sydevs-bot requested a review from Ardnived September 23, 2026 21:49

@Ardnived Ardnived left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread src/lib/utilities/validationFailure.ts Resolved
Comment thread src/lib/utilities/staticLabel.ts Resolved
Comment thread src/lib/utilities/adminUrl.ts Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed awaiting labels Sep 24, 2026
`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
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 24, 2026
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
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-848 September 24, 2026 15:12 Destroyed
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Head is dcc3d4a.

Adopted

  • Is staticLabel.ts unnecessary abstraction? — deleted. No label: in src/ uses the per-locale object form, and nor does any of the three Payload plugins we load. The only other shape is a label function, which all three sites already answered with their fallback. Each now reads typeof label === 'string' itself.

Lean gate green. 54 passed across event-verification and user-submissions-review-lifecycle, which cover all three sites. They pass untouched — that is the claim, since this changes no behaviour.

Still open for you

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot added awaiting bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. awaiting labels Sep 24, 2026
`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
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-848 September 25, 2026 17:28 Destroyed
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Resolved the conflict with main and pushed the merge.

One file conflicted: VerificationCard.tsx. #849 moved its style block into the shared _components/PublicPage, and this branch had edited that same block. I took #849's deletion — every consumer now imports those styles from the shared module.

That deletion would have silently dropped this PR's one behaviour there, so I carried it over: whiteSpace: 'pre-line' now sits on outcomeMessage in PublicPage, with its comment. The invalid-data outcome still renders one line per failing field.

It is a shared style now, so OutcomeBody gets pre-line on the unsubscribe and sign-in pages too. Those messages carry no newlines, so they render unchanged.

Lean gate green. 56 passed across event-verification, manager-signin-page and event-feedback.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot added awaiting bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. awaiting labels Sep 25, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

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 — AdminNavLinks.tsx's object-literal href escaped my grep, and redeemMagicLink.ts arrived with #847. #851 carries the list.

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

@sydevs-bot sydevs-bot added awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 25, 2026
@sydevs-bot
sydevs-bot added this pull request to the merge queue Sep 25, 2026
Merged via the queue into main with commit d70cb8c Sep 25, 2026
42 of 44 checks passed
@sydevs-bot
sydevs-bot deleted the claude/fix-842-event-write-validation branch September 25, 2026 18:37

This branch was successfully deployed

No deployments
sahajcloud / SahajCloud-pr-848 — 492a5b35 Deployed Sep 25, 2026 by railway-app[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

fix(events): verify must refuse invalid data, bookkeeping must not

3 participants