Skip to content

feat(notes): the note participants write and the membership re-check - #1552

Merged
hrustalq merged 2 commits into
devfrom
feat/1551-note-participants
Dec 3, 2026
Merged

hrustalq merged 2 commits into
devfrom
feat/1551-note-participants

Conversation

@hrustalq

@hrustalq hrustalq commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Closes #1551
Refs #1402
Refs #1400

What this is

The note half of 1.2, which #1414 (PR #1548) deferred. #1414's files were memo-only, so
docs/features/89-call-participants.md § How phase 1 starts still promised “the note equivalent (owner-only)” under 1.2. This
PR lands that half as 1.5 and corrects the table: 1.2 is the memo half, 1.5 the note half.

PUT /v1/notes/:id/participants replaces a note's whole roster (up to 40 people; [] clears it) and answers the note's
detail. A verified member's address maps to a userId; every detail answer re-checks the stored links, so a member who
leaves loses the link on the next read. The contract widens additively and there is no migration: notes.participants
already exists.

The contract, and why the fields are optional

NoteParticipant is both the detail's response element and the create/ingest body's element, so the five new fields —
email, userId, external, source, trackKey — are optional on the interface. Every detail-shaped answer fills all
five; the create/ingest DTOs stay name-only (NoteParticipantDto), so a body that carries userId/external/source/
trackKey is stripped by the whitelist rather than trusted. The alternative — required fields plus a second input type —
would move a contract no route needs; the doc already calls the widening additive.

The route and the 404

PUT /v1/notes/:id/participants is not a workspace route: notes have no @Access, and AclGuard refuses read/capture
keys on a non-GET route without one, so the route is a session or a write key. NotesService.assertEnabled is asked
first, then NoteAccessService.require: a stranger, a platform admin and a note outside a pinned key's scope get the
same bare 404, and a pinned key cannot write an unfiled note. No new @Returns name — the answer is
NoteDetailResponse, because the detail is the one read that fills the checked list.

The write

  • Dedupe by folded email, then by folded name (foldName); first occurrence wins and input order is kept.
  • An address maps to userId only when the note has a workspace and the address is a verified users.email of a
    workspace_members row of that workspace. An unfiled note maps nobody and runs no query — memberships: { some: { workspaceId: undefined } } would match every membership, so the null case short-circuits in storedParticipants.
  • Stored rows are { name, email, userId, source: 'manual', trackKey: null }; external is never stored.
  • [] clears to Prisma.DbNull (SQL NULL; JsonNull would store a JSON null), a second PUT replaces the whole list,
    and a guest is never created.
  • Nothing else is written: no notes.speaker_matches, no speakers, no transcript, no source. Phase 3 owns the
    note's voice rung.

The read and the async detail refactor

parseParticipants(value, noteSource) refuses a malformed array — never a partial list — requires a non-empty string
name, defaults an absent email/userId/trackKey to null, and derives an absent source from the note's own
(manual → manual, anything else → metadata); an unknown source refuses the list and an empty array reads null.
readParticipants(row) re-checks every stored userId against workspace_members of row.workspaceId (no workspace:
every link drops, no query), derives external, and returns the checked list.

toDetail(row) is now the pure base mapping without participants; a private async detail(row) adds the checked list.
All ten toDetail(...) call sites were replaced (create's three branches, reserve, finalize, retry, re-audit, get,
patch's two paths), and get merges readNoteReadings after the awaited detail. No synchronous caller sets
participants afterwards.

Shared helpers, not copied

The note write is the second consumer of the memo half's rules, so ParticipantInput, ParticipantRow, emailKey,
dedupeParticipants and storedParticipants moved to apps/api/src/common/participants.ts, and foldName to
apps/api/src/common/text.ts. The memo files import from there; the move is a pure refactor and memos.spec.ts /
memo-speakers.spec.ts are untouched. storedParticipants' workspaceId is string | null now; the memo path always
passes a string, so its behaviour is byte-identical. The item DTOs stay per module (the memo JSDoc and the 100/40 caps
are each route's own).

Doc and generated artefacts

docs/features/89-call-participants.md § How phase 1 starts now lists 1.2 as the memo half and 1.5 as the note half
(#1551); the § Participants stored-shape sentence was corrected in the same pass because it named participantsOf
and “{ name } only”, which this change disproves. make api-client was run from the final tree:
apps/api/openapi.json, apps/api/src/config/contract-schemas.json, packages/api-client/src/schema.d.ts and the docs
reference gained only /v1/notes/{id}/participants and the five NoteParticipant fields;
contract-responses.generated.ts is unchanged because no @Returns name was added.

Acceptance — #1551

criterion status evidence
the PUT writes as the owner and the detail reads it back; a stranger, a platform admin and a pinned key on an unfiled/other-workspace note get the bare 404, and no row changes met notes.spec.ts “the owner writes the list…” and the two 404 cases (fake holds the row; note.update not called; one identical body)
a verified member gets userId; unverified, unknown, non-member or unfiled-note addresses stay userId: null, external: true; a guest is never created met “maps only a verified member…”, “an unfiled note maps nobody…”, user.create not called
a member who left loses userId on the next detail read while the stored row stays; a note with no workspace drops every link met “a member who left…” and “a note with no workspace…”
an old { name } row reads email: null, userId: null, external: true, source from the note's own; a malformed array reads null; an empty array reads null met “an old { name } row reads the memo shape…” (manual/zoom/audio plus nine malformed shapes)
[] clears to SQL NULL; a second PUT replaces; cap 40 and a malformed email are 400s met “[] clears to SQL NULL…”, “the DTO caps the list at 40…”
dedupe by email then folded name, first occurrence wins met “dedupes by address, then folded name…”
make verify; memo specs unchanged; make api-client diff only this feature met make verify exit 0 (350 API spec files, 5424 tests); memos.spec.ts / memo-speakers.spec.ts untouched; generated diff audited below

#1402's rows this PR covers

#1402 criterion status evidence
“PUT /v1/memos/:id/participants (uploader/editor) and the note equivalent set a manual list” met (note half) the route and NotesService.saveParticipants; the memo half landed in #1548
“PUT participants is uploader-only (or the note owner), and a participant cannot be used to grant access” met owner-only route; nothing between require and the row reads participants, so a named member still gets the bare 404
“notes.participants JSONB; the note read returns them” met NoteDetail.participants filled by every detail answer

Divergences named

  • The contract is additive, not a required-field widening. The brief's decision 2: the interface is also the
    create/ingest input, so optional fields keep the two doors' validation copy apart; a body carrying a server-owned
    field is stripped.
  • The route answers NoteDetailResponse, not a NoteParticipant[] envelope — the detail is the only read that
    fills external and the live membership check, and no new @Returns name was added.
  • The doc table changed 1.2's row and added 1.5, rather than reopening feat(memos): call participants 1.2 — manual participants and email mapping #1414: the note half was deferred, not
    dropped, and the table now says so.
  • apps/api/test/note-ingest.spec.ts carries one assertion update (not in feat(notes): call participants 1.5 — note participants write and the membership re-check #1551's file list): its detail read now
    sees the five-field shape. The stored create payload assertion is unchanged; no behaviour changed for the ingest.

Review

Independent review before opening this PR (spec + work, fresh context), sliced by area: contract/DTO/controller, the
service write, the service read + parse + detail refactor, the shared helpers, the memo move, docs, the generated
artefacts, the spec harness, and the three groups of new spec cases. Every slice passed; the only findings were two
weak assertions and one misleading JSDoc in the new spec, fixed in f66c965c.

  • Fixed: the member-left case asserted the stored row against the same array it handed the read, so an in-place
    mutation would still match through the shared reference — it now asserts a literal expected value (f66c965c).
  • Fixed: the no-workspace case proved the answer dropped the link but not that the stored row kept its userId —
    it now asserts the row too (f66c965c).
  • Fixed: the fakeUsers JSDoc stated the failure direction backwards; it now says what the fake applies
    (f66c965c).
  • Rejected: none.
  • Deferred: none.

- 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.
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.
@hrustalq
hrustalq merged commit 607d66c into dev Dec 3, 2026
2 checks passed
@hrustalq
hrustalq deleted the feat/1551-note-participants branch December 3, 2026 14:40
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