Repository navigation
feat(notes): the note participants write and the membership re-check - #1552
Merged
Merged
Conversation
- 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.
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 #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. ThisPR 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/participantsreplaces a note's whole roster (up to 40 people;[]clears it) and answers the note'sdetail. A verified member's address maps to a
userId; every detail answer re-checks the stored links, so a member wholeaves loses the link on the next read. The contract widens additively and there is no migration:
notes.participantsalready exists.
The contract, and why the fields are optional
NoteParticipantis 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 allfive; the create/ingest DTOs stay name-only (
NoteParticipantDto), so a body that carriesuserId/external/source/trackKeyis 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/participantsis not a workspace route: notes have no@Access, andAclGuardrefuses read/capturekeys on a non-GET route without one, so the route is a session or a write key.
NotesService.assertEnabledis askedfirst, then
NoteAccessService.require: a stranger, a platform admin and a note outside a pinned key's scope get thesame bare 404, and a pinned key cannot write an unfiled note. No new
@Returnsname — the answer isNoteDetailResponse, because the detail is the one read that fills the checked list.The write
foldName); first occurrence wins and input order is kept.userIdonly when the note has a workspace and the address is a verifiedusers.emailof aworkspace_membersrow 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 instoredParticipants.{ name, email, userId, source: 'manual', trackKey: null };externalis never stored.[]clears toPrisma.DbNull(SQL NULL;JsonNullwould store a JSON null), a second PUT replaces the whole list,and a guest is never created.
notes.speaker_matches, nospeakers, no transcript, nosource. Phase 3 owns thenote'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 stringname, defaults an absentemail/userId/trackKeyto null, and derives an absentsourcefrom the note's own(
manual→manual, anything else →metadata); an unknownsourcerefuses the list and an empty array reads null.readParticipants(row)re-checks every storeduserIdagainstworkspace_membersofrow.workspaceId(no workspace:every link drops, no query), derives
external, and returns the checked list.toDetail(row)is now the pure base mapping withoutparticipants; a privateasync 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
getmergesreadNoteReadingsafter the awaited detail. No synchronous caller setsparticipantsafterwards.Shared helpers, not copied
The note write is the second consumer of the memo half's rules, so
ParticipantInput,ParticipantRow,emailKey,dedupeParticipantsandstoredParticipantsmoved toapps/api/src/common/participants.ts, andfoldNametoapps/api/src/common/text.ts. The memo files import from there; the move is a pure refactor andmemos.spec.ts/memo-speakers.spec.tsare untouched.storedParticipants'workspaceIdisstring | nullnow; the memo path alwayspasses 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
participantsOfand “
{ name }only”, which this change disproves.make api-clientwas run from the final tree:apps/api/openapi.json,apps/api/src/config/contract-schemas.json,packages/api-client/src/schema.d.tsand the docsreference gained only
/v1/notes/{id}/participantsand the fiveNoteParticipantfields;contract-responses.generated.tsis unchanged because no@Returnsname was added.Acceptance — #1551
PUTwrites 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 changesnotes.spec.ts“the owner writes the list…” and the two 404 cases (fake holds the row;note.updatenot called; one identical body)userId; unverified, unknown, non-member or unfiled-note addresses stayuserId: null, external: true; a guest is never createduser.createnot calleduserIdon the next detail read while the stored row stays; a note with no workspace drops every link{ name }row readsemail: null,userId: null,external: true,sourcefrom the note's own; a malformed array reads null; an empty array reads null{ 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[]clears to SQL NULL…”, “the DTO caps the list at 40…”make verify; memo specs unchanged;make api-clientdiff only this featuremake verifyexit 0 (350 API spec files, 5424 tests);memos.spec.ts/memo-speakers.spec.tsuntouched; generated diff audited below#1402's rows this PR covers
PUT /v1/memos/:id/participants(uploader/editor) and the note equivalent set a manual list”NotesService.saveParticipants; the memo half landed in #1548PUT participantsis uploader-only (or the note owner), and a participant cannot be used to grant access”requireand the row readsparticipants, so a named member still gets the bare 404notes.participantsJSONB; the note read returns them”NoteDetail.participantsfilled by every detail answerDivergences named
create/ingest input, so optional fields keep the two doors' validation copy apart; a body carrying a server-owned
field is stripped.
NoteDetailResponse, not aNoteParticipant[]envelope — the detail is the only read thatfills
externaland the live membership check, and no new@Returnsname was added.dropped, and the table now says so.
apps/api/test/note-ingest.spec.tscarries 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 nowsees 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.mutation would still match through the shared reference — it now asserts a literal expected value (
f66c965c).userId—it now asserts the row too (
f66c965c).fakeUsersJSDoc stated the failure direction backwards; it now says what the fake applies(
f66c965c).