Skip to content

feat(memos): the participants write and the verified-email mapping - #1548

Merged
hrustalq merged 3 commits into
devfrom
feat/1414-memo-participants-write
Dec 3, 2026
Merged

hrustalq merged 3 commits into
devfrom
feat/1414-memo-participants-write

Conversation

@hrustalq

@hrustalq hrustalq commented Dec 3, 2026

Copy link
Copy Markdown
Owner

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 → userId mapping, 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" }] } — only name (1–200, trimmed) and email? (trimmed, blank = none, @IsEmail). userId, external, source and trackKey are server-owned; the global whitelist strips them.

Response: { "participants": MemoParticipant[] } — the same list the detail read returns, with external derived.

The route and its authorization

@Put(':id/participants') sits beside matchSpeaker and copies its shape: @Access('editor', 'memo') checks the workspace role and that the caller can reach this memo, then require matches created_by unless 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 one user.findMany for the whole list, with the three predicates the doc's § Participants fixes:

  • email: { in: foldedKeys } — keys are trimmed and lower-cased; every writer stores users.email that way (auth-flow.service.ts:88), so the match is exact and no mode: '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 fold speakers.ts already 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 is null, not a malformed value. @IsObject({ each: true }) keeps ['x'] out — @ValidateNested alone does not.

The answer is the read

saveParticipants returns readParticipants, not the request echoed: external is derived there, and a userId whose workspace membership is gone is dropped, so the write cannot make a stale link true. The stored JSON is the 1.1 shape without external — { 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)

criterion status evidence
A verified email becomes a workspace member id; an unverified or unknown email stays external. met participants.ts:61 one query with the three predicates; specs maps a verified member by address on the write…, leaves an unverified address external…, keeps a verified member of another workspace external
Another user cannot write the list; the uploader can. met route @Access('editor','memo') + require (createdBy unless admin); spec refuses another user and writes nothing; every write case drives saveParticipants(member, …) as the uploader (member is u1, the row's createdBy) and asserts memo.update
A member who left loses the link without losing the participant. met readParticipants re-checks membership on the PUT's own answer; spec drops a link the workspace lost from the PUT's own answer… (row keeps the id, answer reads external)
make verify passes. met exit 0: 350 API test files / 5372 tests, plus web 105 files/776 tests, admin 1/2, ui 4/10

#1402 rows advanced

row status evidence
Email mapping: verified member → userId, guest external, deleted member loses the link. met the three mapping specs and the lost-link spec above
PUT participants uploader-only; a participant grants no access. met @Access('editor','memo') + require; specs refuses another user and writes nothing, a participant never grants access…

Divergences

  • Extra files the issue's list omits. speakers.ts gains the foldName export (one implementation of the fold, per the brief's decision 5); CHANGELOG.md gets the new-route line; make api-client regenerated apps/api/openapi.json, apps/api/src/config/contract-schemas.json, apps/api/src/common/contract-responses.generated.ts, packages/api-client/src/schema.d.ts and the docs reference — the response type is on the wire, so the client follows.
  • The note half is not in this PR. The doc's § How phase 1 starts gives 1.2 "the note equivalent (owner-only)", but feat(memos): call participants 1.2 — manual participants and email mapping #1414's Files are memo-only and the note side needs its own write body (NoteParticipant is a read shape) and a membership re-check on the note read. Deferred to its own session; nothing under apps/api/src/notes is 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).

  • Fixed: the dedupe case proved one survivor only, leaving input order unpinned → a third survivor asserts order and count (3c9da63c).
  • Fixed: the DTO case accepted a blank address without asserting it becomes null → a plainToInstance assertion reads the transformed value (3c9da63c).
  • Fixed: a fixture comment said two user rows pass every predicate when one does → corrected (3c9da63c).
  • Fixed: no case showed that a participant cannot grant access → a participant never grants access… added (7d21a6a8).
  • Rejected: "no case proves the uploader can write" — every write case runs as the uploader (member is u1, the row's createdBy) and asserts memo.update with 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's ada@x is not a well-formed body under the shipped validator.

@hrustalq
hrustalq merged commit ed89296 into dev Dec 3, 2026
2 checks passed
@hrustalq
hrustalq deleted the feat/1414-memo-participants-write branch December 3, 2026 10:47
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant