Repository navigation
feat(api): let an admin block a submitter, and purge spam sign-ups - #1060
Conversation
A sender we never want to hear from again could keep submitting, with the 24-hour `repeat_sender` rule as the only brake. `blockedAt` on the Registrant record is the lasting half of that brake, set by a person. Screening reads it first, before the MX lookup: a primary-key read is cheaper than a DNS round trip, and a blocked sender should cost neither. The refusal is the ordinary `spam` path, so the create still answers 201, nothing is delivered, and a blocked sender's registration drops out of fullness, reminders and votes with every other refusal. `users` could not carry the field until the collection was openable. `admin.hidden: true` unregisters a collection's routes as well as hiding its nav entry, so a Registrant was reachable by nobody and the docblock claiming admins see them was wrong. The function form fixes both. The orphan sweep now keeps a blocked Registrant whatever its count says, in the real and the dry-run branch alike, or a block would expire the night the sender's last submission aged out. And `machineSpam` drops its type exclusion: a `spam` registration or subscription records no attendance and no consent, so it is evidence like every other refusal and ages out at 90 days with them. Refs #630 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXHir3nSxpuvaZaLC3
…gistrant route Each new assertion was watched failing against the real defect before it was kept: - the machine-spam window reaching a durable type, with the old type exclusion restored; - the orphan sweep deleting a blocked sender, in both branches, with the block guard removed; - screening passing a blocked sender on contact, proposal, registration and the subscribe row a registration spawns, with the block read removed; - the Registrant route, with `admin.hidden` back at `true`. The refusal for a non-admin is an invariant rather than a reproduction: no role has ever held `users` write. It is asserted beside the read grant that makes it meaningful, so a future grant cannot open the block quietly. Fixtures checked against the real config: `atlas-manager` holds `users: ['read']` and no write (`src/plugins/access/config/roles.ts:81`, the only `users` grant in the file), and `accessPlugin` composes a hand-written `hidden` function rather than replacing it (`src/plugins/access/accessPlugin.ts:121`), with a collection in no project visible to all (`config/projects.ts:341`). docs/architecture.md described a pipeline with no block in it and an orphan sweep that only submissions could pin. Refs #630 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXHir3nSxpuvaZaLC3
…ssary `Users.admin.hidden` is gone entirely rather than rewritten. `accessPlugin` derives it, and for this collection the derivation already answers what a hand-written `!isAdminManager(user)` would: no role grants `users` a write, so only the admin bypass clears `hasAnyPermission`, and `users` is in no project, so project visibility never narrows it. The hand-written form was a second spelling of the role table — and the worse one, since a role granted `users: ['update']` later is admitted by the derivation and would have been refused by the predicate. `DURABLE_TYPES` is gone. Once `machineSpam` stopped composing it, nothing in `src/` read it; the list and its docblock described a rule no window enforced. The rule now sits in the window that applies it, and the two type names sit in the spec that asserts the invariant. `blockedAmong` is folded into its one caller and inverted: asking `users` for the rows with no block returns the set to sweep directly, so the helper, the second Set and the in-loop test all go, and "blocked" is spelled once, as a `where`. Also: the orphan sweep said a registration or subscription is one "which no window selects", which the window change had just made false. Refs #630 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXHir3nSxpuvaZaLC3
…rite no key The project-visibility section named `Users` as a collection hiding itself with `hidden: true`, which this branch made false, and offered only the two hand-written forms. The third option is the one `users` wanted: write no key and let the derivation answer, wherever the role table already decides. Refs #630 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXHir3nSxpuvaZaLC3
|
🚅 Deployed to the SahajCloud-pr-1060 environment in sahajcloud
1 service not affected by this PR
|
sydevs-bot
left a comment
There was a problem hiding this comment.
1 question for the reviewer, one per thread.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
|
🤖 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
This matches #630's shape, and in one place is smaller than it: DURABLE_TYPES is deleted rather than re-documented, because the spec pinning it was its only reader. Both heavy lenses pass. No new module, helper or type — the two reads reuse relationId and Payload's own select/exists. The contract change is additive, and nothing downstream reads it.
I checked the admin-only claim rather than took it. createHidden gates on write permission, and roles.ts:81 is the only users grant and is read — so deleting the hidden key leaves admins alone, and the new spec asserts that against an atlas-manager, the one role holding that grant.
Every finding is prose. Nothing here asks for a design change.
Findings
should-fix—Users.ts:21: one argument, stated three times in this diff.consider—ScreenSubmissions.ts:181: says what line 197 already says.consider—orphanedUsers.ts:95: the body cites the wrong precedent for an exposure it is right to leave.
What was checked
- Read whole on the branch:
Users.ts,orphanedUsers.ts,screen(),visibility.ts,accessPlugin.ts:120-140,CleanupCollections.ts:100-142,roles.ts. - Ladder:
relationIdalready existed and now serves both call sites, replacing an inlinetypeoftest.exists,selectand the derivedhiddenare Payload's own. - Consumers:
blocked_senderwidens a union in a read position only. GreppedSahajAtlasWeb/srcandWeMeditateWeb/server— type mirrors, plus two live-preview specs that stripscreeningResult. No client role grantsusers, so a populatedEvents.submitterstill falls back to a bare id andblockedReasonreaches no client.payload-types.tsis additive, 11 lines. - Preview: both links answer 200, but signing in needs
PREVIEW_ADMIN_EMAIL, which this environment has not got.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
Six lines argued an absent key, and the same argument stood twice more in this branch — in `docs/rules/admin-ui.md` and in the PR body. The rule file is the copy that outlives the diff, so it keeps the reasoning and the field config keeps a pointer to it. Refs #630 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjUsF8seYfdCmb6gEys
The note above `relationId(submission.user)` said what the comment sixteen lines down says about `senderEmail`, and the `if (userId != null)` beneath it is the fact itself. Refs #630 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjUsF8seYfdCmb6gEys
|
Addressed the adversarial review's three findings. Base was already current, so no merge. Adopted
Open for you
Lean gate green. Comment-only diff, so no spec changed. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
One conflict, in `src/migrations/index.ts`, where both branches appended a migration. Both are kept, ordered by timestamp: main's data-only `20261101_191500_atlas_drop_time_in_place` (#1057) runs before this branch's `20261101_202242_block_submitter`. They touch different tables, so the order is the chain's convention rather than a dependency. The snapshot chain stays healthy without a merge-snapshot migration. The newest snapshot by filename is this branch's, which the next `migrate:create` diffs against; main's is the prior snapshot re-stamped, because its migration is data-only and emits no DDL. Compared as objects, `20261101_191500_atlas_drop_time_in_place.json` equals `20261027_190500_pages_blank_slug_to_null.json`, and `20261101_202242_block_submitter.json` equals it plus the two `users` columns — so the newest snapshot already carries both branches' schema (`src/migrations/AGENTS.md`, the out-of-order snapshot trap). `src/payload-types.ts` merged cleanly and holds both edits: `blockedAt` and `blockedReason` on Registrants, and no `time_in_place`. Lean gate green: lint, format, typecheck, typecheck:tests, 2992 unit tests in 234 files. Integration specs for both sides, 53 passed — `atlas-drop-time-in-place.int`, `screen-submissions.int`, `retention-submissions.int`, `user-submissions-access.int`. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjZTTJ1b1acnDtHuMzR
`blockedReason` was only ever written, never cleared, so a second block posted without a reason kept the lifted block's text and the record read as though it were current. The button makes that easy to reach: it pre-fills the textarea from the stored reason, so an admin who clears it sends no `reason` at all. A block now writes its own reason, `null` included. Unblock still keeps it as history. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjW1aDBUWoTktqTjaWh
…olumn Both jobs' comments argued the reverse: that the stored column was authoritative and a `users` join would be the derived copy. Dropping `sender_email` inverted that — the field is `virtual: 'user.email'`, so these reads already go through the join. The fact worth keeping is the one the inverted comment hid: Payload resolves a relationship-path virtual in the query, not through a sibling's `afterRead`, so an include-mode `select` naming `senderEmail` needs no `user` beside it. `session-reminders.int` pins it — the job still sends to the right address with that select unchanged. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjW1aDBUWoTktqTjaWh
It is a separate ticket's work. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Three findings built; one waits on you. Adopted
Asked
Also — Lean gate green. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
…stem, the delete guard in hooks/ - Field tables use `<Table appearance="condensed">`, Payload's own compact table and what its join fields render. CompactTable is gone; LogTable and ImportResultsTable are back to main, and SubmissionData's key column width is one rule on Payload's `.cell-field`. - FormStateOnly is gone. Type, Status, Submitted By, Form and Event sit in the System group beside Submitted Via, as ordinary read-only fields: the banner and the Context summary present them, and the list columns and form state are unchanged. - `refuseDeletingSender` moves to `Users/hooks/`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… into claude/feat-630-block-submitter
|
One answer, no code change. Settled
Body — refreshed against your Base — level with No threads are open. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Main (#1060) made `senderEmail` `virtual: 'user.email'`, resolved under the reader's access, so with the grant removed a contact recipient read every message with no sender address. Restored on both roles, as the PR thread decided (option A). The `Users.submissions` join is reachable again, so its spec asserts the join's own scope once more: a region manager and an event assignee each get exactly the rows the per-row scope admits, against an admin control. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Main (#1060) made `senderEmail` `virtual: 'user.email'`, resolved under the reader's access, so with the grant removed a contact recipient read every message with no sender address. Restored on both roles, as the PR thread decided (option A). The `Users.submissions` join is reachable again, so its spec asserts the join's own scope once more: a region manager and an event assignee each get exactly the rows the per-row scope admits, against an admin control. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reverts the restore. An Atlas manager reads their event's registrants on the Registrations view (#1073), and a contact's sender address arrives in its delivery mail; both read with `overrideAccess`, so neither needs the Registrants collection. The cost is deliberate and now pinned: a manager's read of a submission carries no `senderEmail`, since that is `virtual: 'user.email'` (#1060). Main's contact-scope cases identify rows by form instead, and the Registrant-block case asserts the manager can read no Registrant at all. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
senderEmailstops being a column and reads back off the Registrant, the submission edit view gets one status banner and a Context summary for all four intakes, anddocs/rules/admin-ui.mdnamedUsersas ahidden: truecollection, which this branch makes false.senderEmailcolumn was authoritative and ausersjoin would be derived. Dropping the column inverted that, so the comments now state what is true and why theselectneeds nouser.Change outline
Contract —
usersgains two columns and a route,user_submissionsloses oneblockedAtclosescreateandupdateto every caller, and no role grantsusersa write at all — so the endpoint'soverrideAccesswrite is the only writer, and a hand-set date cannot block without also refusing the sender's open submissions.Dropping the
hiddenkey rather than writing a predicate is the one deviation from the ticket's approach:createHidden('users')already answers what!isAdminManager(user)would. Why that is the better answer, and not merely the shorter one, now lives indocs/rules/admin-ui.md— the copy that outlives this diff.Contract —
POST /api/users/:id/blockA new collection endpoint, gated on
users: update, which no role grants — so only the admin bypass passes. Absent from the OpenAPI shim for the same reasonusersis: it sits in no project.Flow — screening reads the block first
The refusal is the existing
spampath, so the create still answers 201, nothing is delivered or emailed, and the row drops out of fullness, reminders and votes with every other refusal. The subscribe row a registration spawns carries the sameuserand is screened on its own, so it is refused too.Flow — what Block does, in one transaction
statusis the whole selection: the row the button sat on gets no exemption from it. Refusing that row at any status moved anacceptedregistration tospam, whichINACTIVE_STATUSESdrops out of fullness and reminders — against the modal's promise that delivered history is left alone.Behaviour — retention
One window loses a special case; the sweep gains one.
Asking for the unblocked rows rather than the blocked ones means "blocked" is spelled once, as a
where, and both branches read it — so the dry-run count stays a prediction of what the real sweep does.Components — one submission edit view for four intakes
Every table here is Payload's own
<Table appearance="condensed">— the same one its join fields render — with one width rule per consumer in that component'sstyles.css.LogTable,ImportResultsTable,SubmissionDataandSubmissionSummaryshare no wrapper of ours.Preview
Data: not seeded.The preview seed this branch carried was reverted in2f55cc8as a separate ticket's work, so these links open on an empty list until someone adds rows by hand. The flow was exercised on a local dev server instead, against a real Postgres: blocking[email protected]and submitting again gavestatus: spam,verdict: blocked_sender, the note "This sender is blocked, so nothing they send is delivered…", and an activity-log row readingScreening refused: blocked_sender.Contract impact
src/payload-types.tschanges, so both type-mirroring consumers re-sync after this merges (contractSyncinsydevs/claude-workflow):WeMeditateWeb/server/payload-types.tsandSahajAtlasWeb/src/types/payload/payload-types.ts. All three changes are additive or read-position-only —blockedAt/blockedReasononUser,blocked_senderwidening thescreeningResult.verdictunion, andsenderEmailonUserSubmissionkeeping its type while becoming virtual. The rest of the diff there is field order, which the System group moved. No client role grantsusers, soblockedReasonreaches no client, and a client's create response no longer echoessenderEmailbecause the virtual resolves under the reader's access. No consumer work needs an issue.Migration
Two migrations, and the second is not reversible without data loss.
src/migrations/20261101_202242_block_submitter.ts— two nullable columns onusers. No data transformed, no backfill. Reversible: yes,downdrops exactly the two columns it adds.src/migrations/20261103_215150_submitter_identity.ts— dropsuser_submissions.sender_emailand its index. Reversible: schema only.downre-adds the column and the index; it cannot re-add the addresses.Measured against production: 0 rows have
sender_emailset and nouser_id(reviewer, 2026-11-04). The drop therefore loses nothing, and it ships as it stands rather than behind a backfill.That matches the structural argument.
user_submissionswas created withuser_idand withprepareUserSubmissionin the same commit (6c1e9c2), and that hook has always writtenuserfrom the same postedsenderEmail, through the sameupsertUserByEmail— so the pair was written together or not at all, and no migration has ever inserted or updated a row in this table. The one residue the tree does not settle is ausersrow deleted while its submissions remained:ON DELETE SET NULLwould have nulleduser_idand leftsender_emailbehind. The count above says that never happened, andrefuseDeletingSender, which arrives in this branch, is what keeps it from happening again.Test results
block-user.int(8) andsession-reminders.int(7), plusscreen-submissions.int(24),retention-submissions.int(16),user-submissions-access.int(11) anduser-submissions-create.intfrom the earlier pushesEvery new assertion was watched failing against the real defect before it was kept: the window with its type exclusion restored, the sweep with the block clause removed, screening with the block read removed, the route with
hidden: trueback, Block on an accepted row with the pressed-on exemption restored, and the staleblockedReasonwith the conditional write back. The one exception is the refusal of a non-admin's write, which is an invariant rather than a reproduction — no role has ever helduserswrite — so it is asserted beside the read grant that makes it meaningful.Manual verification
/admin/collections/users404s. Asserted in the int spec against the composed config, but worth one look in a browser.accepted, and confirm that row stays Accepted and the toast reports no rows marked.Notes for reviewer
atlas-manager,web-translator, an inactive manager and both client kinds all stay hidden, andaccess.readis unchanged —atlas-manageralready readusersthrough the registrations join.senderEmailconsumer. Three things it checked and cleared, worth knowing: unhidingusersmoves no server-side gate (the REST surface was always registered, andcreateHiddenadmits only a write-holder, which is nobody but an admin); the endpoint'soverrideAccesswrites take no caller-derived field, collection orwherekey; andsenderEmailbecoming virtual is strictly narrower, since it now resolves under the reader's own access.if (senderEmail)block for. Running the block read and the MX lookup underPromise.allwould cut one serialized wait on the clean path, but makes a blocked sender pay for the DNS lookup this feature exists to avoid. CarryingblockedAtout ofupsertUserByEmailat create time would read it too early: an admin can block between the create and the screen, which is exactly the race the fresh read wins. Running the dry run's two counts concurrently shares onereq, whichsrc/collections/CLAUDE.mdwarns against.touchedUsersis unbounded, so the newid: { in: [...] }read is too, and this branch grows the set it reads — the first nightly run after deploy sweeps 90 days of backlog in one go. Postgres caps a statement at 65535 bind parameters, and this is the first read here whose bind-parameter count scales with that set;noteSendersis unbounded in rows, which is a different limit. What bounds the cost isCleanupCollections.ts:113— it catches the throw, the submission deletes stand, and the next night's set is small. So leaving it unchunked costs one logged sweep, not a stuck one, which is why no chunking is added against a harm nobody has measured.findByIDof the submission passesdepth: 0but noselect, so on a proposal both virtual-fieldafterReadhooks run — each loading the target event, its images and its manager — and thepayload.updateon the response pays them again. Aselectnaming the fields the handler reads would skip both. Out of scope here; say the word and I will file it.sender_emaildrop was the last one, and your count settled it.Detail
DURABLE_TYPESis gone. OncemachineSpamstopped composing it, nothing insrc/read it, and its docblock described a rule no window enforced. The rule now sits in the window that applies it; the two type names sit in the spec that asserts the invariant. The ticket said to rewrite the docblock — this goes further, because a production export whose only reader is the test that pins it is a layer that does not pay rent.The spec that pinned "no window may reach a durable type" now asserts both directions. A second window naming no type would delete a real attendance record; an exclusion back on
machineSpamwould keep refused sign-ups for ever. Only the first of those is a failure anything else would notice.The block endpoint writes as a system request, deliberately.
reviewMoverefuses any status move a manager makes on a non-proposal row, and it readsreq.userto decide. This endpoint is the decision, already gated on the admin bypass; a system request is how every other machine writer (screening, delivery) reachesspam, and sharing one transaction keeps the block and its refusals together.Rejected while building: an
admin.conditionhidingblockedReasonuntilblockedAtis set (nobody asked, and the field is one row); ablockedAmonghelper, folded into its one caller once inverting the query removed the set and the in-loop test; anisBlockedhelper around thefindByID, folded in for the same reason; arelationValuewalk inBlockUserButton, replaced byrelationId, which three other admin client components already import. A sharedBLOCKED_WHEREconstant plus anisBlockedpredicate would give the sweep'swhereand screening's value check one owner, but they are different kinds of expression and each would have exactly one consumer, whichtests/unit/lib-boundary.spec.tstreats as not-shared; the typedselect: { blockedAt: true }two lines above thewhereis what catches a rename.Known limit, marked
shortcut:inorphanedUsers.ts. Lifting a block leaves the Registrant row behind for good, becausetouchedUsersis only ever filled from submissions being deleted, so nothing revisits a sender who has none left. An admin deletes it by hand.Closes #630
🤖 Generated with Claude Code
https://claude.ai/code/session_01Mg9rjXHir3nSxpuvaZaLC3