Repository navigation
feat(memos): the participants write and the verified-email mapping - #1548
Merged
Merged
Conversation
This was referenced Dec 3, 2026
hrustalq
added a commit
that referenced
this pull request
Dec 3, 2026
- PUT /v1/notes/:id/participants replaces a note's roster (cap 40, and [] clears it to SQL NULL) and answers the checked detail; a stranger, a platform admin and a pinned key outside the note get the same bare 404. - The note half of 1.2 that #1414/#1548 deferred: the verified-email -> userId mapping, dedupe by folded email then name, and the malformed-email refusal are the memo half's own rules, moved to common/participants.ts with foldName in common/text.ts. The memo files import from there; behaviour is unchanged (memos.spec.ts and memo-speakers.spec.ts are untouched). - NoteParticipant gains email, userId, external, source and trackKey additively; the create/ingest DTOs stay name-only, so a body carrying a server-owned field is stripped rather than trusted. - parseParticipants fills the stored shape and readParticipants re-checks every stored userId against the note's workspace; an unfiled note asks nothing and drops every link. detail(row) is the one async detail builder, replacing the ten sync toDetail call sites. - docs/features/89 § How phase 1 starts records 1.2 as the memo half and 1.5 as the note half.
hrustalq
added a commit
that referenced
this pull request
Dec 3, 2026
…1552) * feat(notes): the note participants write and the membership re-check - PUT /v1/notes/:id/participants replaces a note's roster (cap 40, and [] clears it to SQL NULL) and answers the checked detail; a stranger, a platform admin and a pinned key outside the note get the same bare 404. - The note half of 1.2 that #1414/#1548 deferred: the verified-email -> userId mapping, dedupe by folded email then name, and the malformed-email refusal are the memo half's own rules, moved to common/participants.ts with foldName in common/text.ts. The memo files import from there; behaviour is unchanged (memos.spec.ts and memo-speakers.spec.ts are untouched). - NoteParticipant gains email, userId, external, source and trackKey additively; the create/ingest DTOs stay name-only, so a body carrying a server-owned field is stripped rather than trusted. - parseParticipants fills the stored shape and readParticipants re-checks every stored userId against the note's workspace; an unfiled note asks nothing and drops every link. detail(row) is the one async detail builder, replacing the ten sync toDetail call sites. - docs/features/89 § How phase 1 starts records 1.2 as the memo half and 1.5 as the note half. * test(notes): pin the participant rows by value in the read cases Independent review of the #1551 diff found two weak assertions in the new spec: the member-left case compared the stored row against the very array handed to the read (an in-place mutation would still match through the shared reference), and the no-workspace case never asserted that the stored row keeps its `userId`. Both now assert a literal expected value, and the fakeUsers JSDoc names the right failure direction.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1414
Refs #1402
Refs #1400
What
PUT /v1/memos/:id/participants— the uploader states the memo's whole roster, and a verified address becomes a workspace member's id. 1.1 (#1413) shipped the column, the contract and the detail read; this adds the write: the route, the verified-email →userIdmapping, the two-pass dedupe, the 100-person cap and the malformed-address refusal. No schema change, no migration, no notes change, no tracks.Request:
{ "participants": [{ "name": "Ada", "email": "ada@example.com" }] }— onlyname(1–200, trimmed) andemail?(trimmed, blank = none,@IsEmail).userId,external,sourceandtrackKeyare server-owned; the global whitelist strips them.Response:
{ "participants": MemoParticipant[] }— the same list the detail read returns, withexternalderived.The route and its authorization
@Put(':id/participants')sits besidematchSpeakerand copies its shape:@Access('editor', 'memo')checks the workspace role and that the caller can reach this memo, thenrequirematchescreated_byunless the caller is a platform admin — so another user gets the same bare 404 as every memo write and nothing is written (spec:refuses another user and writes nothing). A participant is detail only: a roster that names someone gives them no access to the memo (spec:a participant never grants access…).Why PUT replaces
The body is the roster as the uploader states it now;
[]clears it. 1.2 is the only writer, so there is no metadata-sourced row to preserve — a future provider adapter merges by address/name in its own session instead of making this route read-modify-write.The mapping
storedParticipants(apps/api/src/memos/participants.ts) does oneuser.findManyfor the whole list, with the three predicates the doc's § Participants fixes:email: { in: foldedKeys }— keys are trimmed and lower-cased; every writer storesusers.emailthat way (auth-flow.service.ts:88), so the match is exact and nomode: 'insensitive'is needed;emailVerifiedAt: { not: null }— an unproven address never resolves (schema.prisma:822);memberships: { some: { workspaceId } }— a member of this memo's workspace, not merely of the instance.A name-only participant, an unknown address, an unverified address and a verified member of another workspace stay
userId: null/external: true. A guest is never auto-created.Dedupe, cap and refusal
Two passes over the list: by folded address, then by the folded name (
foldName, the foldspeakers.tsalready used, now exported and imported — one implementation, not a copy). The first occurrence wins and input order is kept. The DTO caps the list at 100 (@ArrayMaxSize) and refuses a malformed address (@IsEmail); a blank address isnull, not a malformed value.@IsObject({ each: true })keeps['x']out —@ValidateNestedalone does not.The answer is the read
saveParticipantsreturnsreadParticipants, not the request echoed:externalis derived there, and auserIdwhose workspace membership is gone is dropped, so the write cannot make a stale link true. The stored JSON is the 1.1 shape withoutexternal—{ name, email, userId, source: 'manual', trackKey: null }, every optional explicit, so a row this task writes and a row it reads agree.Per-criterion (#1414)
participants.ts:61one query with the three predicates; specsmaps a verified member by address on the write…,leaves an unverified address external…,keeps a verified member of another workspace external@Access('editor','memo')+require(createdBy unless admin); specrefuses another user and writes nothing; every write case drivessaveParticipants(member, …)as the uploader (memberisu1, the row'screatedBy) and assertsmemo.updatereadParticipantsre-checks membership on the PUT's own answer; specdrops a link the workspace lost from the PUT's own answer…(row keeps the id, answer reads external)make verifypasses.#1402 rows advanced
userId, guest external, deleted member loses the link.PUT participantsuploader-only; a participant grants no access.@Access('editor','memo')+require; specsrefuses another user and writes nothing,a participant never grants access…Divergences
speakers.tsgains thefoldNameexport (one implementation of the fold, per the brief's decision 5);CHANGELOG.mdgets the new-route line;make api-clientregeneratedapps/api/openapi.json,apps/api/src/config/contract-schemas.json,apps/api/src/common/contract-responses.generated.ts,packages/api-client/src/schema.d.tsand the docs reference — the response type is on the wire, so the client follows.NoteParticipantis a read shape) and a membership re-check on the note read. Deferred to its own session; nothing underapps/api/src/notesis touched.Review
Independent review before opening this PR (spec + work, fresh contexts; the first wave was interrupted and re-dispatched — a fail-closed block, not a pass).
3c9da63c).null→ aplainToInstanceassertion reads the transformed value (3c9da63c).3c9da63c).a participant never grants access…added (7d21a6a8).memberisu1, the row'screatedBy) and assertsmemo.updatewith the stored list; the positive half is those cases, the negative half is the refusal case.One technical note:
@IsEmail()requires a TLD, so the fixtures use@example.com— the brief'sada@xis not a well-formed body under the shipped validator.