Repository navigation
feat(views): add a Note view type whose documents belong to the view - #796
Conversation
A view of type "note" holds free-form writing (sprint goals, meeting minutes, a release checklist) instead of tasks. Its notes are ordinary documents, so content, snapshots, activity, comments, file uploads and live collaboration all work as they do for the docs tree, but they belong to the view rather than to a folder. Data model (migration 000094): - sprint_views.view_type allows 'note'. - documents.view_id references the note view; a CHECK keeps a note out of folders (view_id IS NULL OR folder_id IS NULL). - A BEFORE DELETE trigger on sprint_views soft-deletes the view's live notes, which also covers views removed with their sprint. It takes the doc change counter before touching documents, and skips views removed with their project, whose documents go with the cascade. Creating a note takes the view row FOR KEY SHARE before the counter, so a concurrent view delete cannot deadlock with it. API: - GET /docs?view_id= lists a view's notes; POST /docs with view_id creates one (DOC_NOTE_VIEW_INVALID unless it names a note view of the project). Every other document route serves notes unchanged. - Notes stay out of everything that addresses the docs tree: tree listings, by-path lookups, search (hits are located by path) and the change feed. Moving a note into a folder is refused (DOC_NOTE_IN_FOLDER). - A new router gate (DocView) also requires views:read on the view a listing or create names, so a Deny on the view, or a role limited to one sprint's views, covers its notes too. - A note view keeps its type: switching a view to or from "note" is refused (VIEW_NOTE_TYPE_CHANGE) so notes are never stranded. Tests cover the service rules, the handler, the gate, route coverage, the repository against Postgres (listing, paths, search, change feed, cascades on view, sprint and project deletion) and the HTTP flow end to end. The database schema, HTTP design, change feed and interaction views docs describe the new type. Refs Paca-AI#772 Signed-off-by: Asish Kumar <[email protected]>
A "Note" layout joins Board, Table and Gantt in the Add view popover of the Sprint, Backlog and Timeline interactions. The view lists its notes on the left and opens the selected one on the right: - New note creates "Untitled" in the view and opens it for renaming. The ⋯ menu renames, moves a note up or down, and deletes it after a confirmation. All of it needs docs:write; without docs:read the view says the notes cannot be shown. - Reordering renumbers the notes 0..n-1 in their new order and saves only the positions that changed. The list shows the new order and positions at once, so a second move compares against them. - The editor, managed-copy banner, comments and activity pane are the docs route's own: its body moves into a DocumentPane component that the route and the note view both render. - No task query runs for a note view, and its task search and view settings are hidden. Strings are added for all nine locales, along with a "note" subject for the success toasts. Refs Paca-AI#772 Signed-off-by: Asish Kumar <[email protected]>
create_view and update_view accept viewType "note". list_docs takes a viewId to list a note view's notes with their docId, and write_doc takes a viewId to update the view's note with a given title or create it (recording the write's note and task). delete_doc accepts a docId as well as a path, since notes are not in the docs tree and have no path. read_doc and edit_doc already work on a note by docId. ALL_TOOLS.md and the README now list the document tools that exist (list_docs, read_doc, grep_docs, edit_doc, write_doc, delete_doc, move_doc, pull_docs/push_docs) instead of their old names. Refs Paca-AI#772 Signed-off-by: Asish Kumar <[email protected]>
Creates a note view from the Add view popover, writes and saves its first note, checks that notes stay out of the Docs sidebar, reorders a note and deletes one after the confirmation dialog. Refs Paca-AI#772 Signed-off-by: Asish Kumar <[email protected]>
There was a problem hiding this comment.
Important
Two guarantees the PR states do not hold as written: a view-level Deny (or a view.sprint_id-conditioned role) is only enforced when a view's notes are listed or created, not when one is read, edited, deleted or batch-fetched by docId; and the lock order documented in 000094 does not hold when a sprint delete cascades over several view rows. Both need a decision before merge.
Approach: sound — notes reuse the existing documents table and docs editor rather than introducing a parallel notes table and a second editor, and the "docs tree or one view, never both" invariant is enforced by a CHECK plus view_id IS NULL on every tree-facing query. The gaps are at the seams where documents are addressed by id instead of through the tree.
Reviewed changes
- Migration
000094—notejoins theview_typeCHECK;documents.view_idwith anON DELETE SET NULLFK, aview_id IS NULL OR folder_id IS NULLCHECK, a partial index, and aBEFORE DELETEtrigger that soft-deletes a view's live notes (skipping hard project deletes). - Document repository —
view_idin the column lists; notes listed only by view; tree listings, path lookup, search, feed and fingerprint all exclude notes;CreateDocumenttakes the view rowFOR KEY SHAREbefore the change counter. - Document service —
WithViews+checkNoteView(DOC_NOTE_VIEW_INVALID), folder moves of a note refused (DOC_NOTE_IN_FOLDER), andUpdateViewrefuses any type change to or fromnote(VIEW_NOTE_TYPE_CHANGE). - Authorization — new
RequireDocViewmiddleware andguards.DocView()on the/docscollection routes, authorizingviews:readon the view named byview_id. - Web —
NoteView(list, create, inline rename, reorder byposition, confirmed delete, read-only and no-access states) beside aDocumentPanethat is the former$docIdroute body moved verbatim; task queries and view settings are skipped for note views. - MCP —
viewIdonlist_docs/write_doc,docIdondelete_doc, andnoteaccepted bycreate_view/update_view. - Tests and docs — Postgres tests for the view/tree boundaries, soft delete with view/sprint/project, the middleware and route-coverage gates, an API e2e flow, a web component suite, a Playwright spec, and updates to the schema, HTTP, change-feed and interaction-view docs plus all nine locales.
ℹ️ Project export writes notes as root documents and outside the view's access
ListAllDocuments is the one listing the PR left unfiltered, so a note (folder NULL) is exported as docs/<title>.md next to genuine root documents, indistinguishable from them and sharing their numeric de-duplication. docs/api/http-design.md describes docs/**.md as a mirror of the docs tree, which a note is not, and the export routes are gated on project.export rather than the view's access, so a principal without views:read on the view still receives its notes. Since the PR deliberately keeps notes in the export, consider an explicit location such as views/<view name>/ and updating that contract, rather than leaving them indistinguishable from tree documents.
Technical details
# Notes in the project export
## Affected sites
- `services/api/internal/repository/postgres/document_repository.go:538-543` — `ListAllDocuments` selects every non-deleted document of the project with no `view_id` filter.
- `services/api/internal/service/export/docs.go:79-92` — `dirOf(d.FolderID)` maps a `NULL` folder to `docs/`, so notes land at the root of the docs folder.
- `docs/api/http-design.md` (export archive contract) — `docs/**.md` is described as the project's documents "in the same folder tree as in the app".
- `docs/architecture/interaction-views.md:163` — enumerates where notes do not appear; export is not mentioned.
## Required outcome
- Either notes are packaged in a location that identifies them as notes (and the archive contract is updated), or they are excluded from the export.
- The export docs state what a note view contributes, so the archive contract stays truthful.
## Open questions for the human
- Is exporting notes part of the intended product behavior at all, and should it follow the view's access rather than `project.export` alone?deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
| r.With(require.Project(iam.ActionDocsRead), require.DocView()).Get("/", deps.Document.ListDocuments) | ||
| r.With(require.Project(iam.ActionDocsWrite), require.DocCreate(), require.DocView()).Post("/", deps.Document.CreateDocument) |
There was a problem hiding this comment.
The view gate only runs here, so the guarantee in docs/architecture/interaction-views.md ("a Deny on the view or a role limited to the views of one sprint … also covers its notes") does not hold for the notes themselves: GET, PATCH, DELETE /docs/{docId}, /docs/batch-get, /snapshots, /activities, /comments and the doc-file routes authorize project/<p>/doc/<docId> and docs:read/docs:write only. A caller denied views:read on a view can still read, edit, delete and batch-fetch its notes by id, so the view's access controls listing and creation but not the content. Note creation is also gated on views:read rather than views:write, so a member denied writes to the view can still add notes to it.
Technical details
# Notes bypass their view's access on the item routes
## Affected sites
- `services/api/internal/transport/http/router/router.go:894-895` — `require.DocView()` is declared on the collection `GET`/`POST` only.
- `services/api/internal/transport/http/router/router.go:897-921` — every `/docs/{docId}` route (read, patch, delete, snapshots, activities, comments, doc files) uses `ProjectEntity("doc", "docId", resDoc, …)`.
- `services/api/internal/transport/http/router/router.go:890` — `POST /docs/batch-get` authorizes `docs:read` only and returns full bodies via `FindDocumentsByIDs`.
- `services/api/internal/platform/authz/iam/attributes.go:51-53` — the `doc` kind declares only `doc.folder_id` and `doc.ancestor_folder_ids`; there is no way for a document policy to express "this note's view".
- `services/api/internal/repository/postgres/iam_scope.go:56-65` — `docScopeColumns` has no `view_id`/sprint column, so a `view.sprint_id` condition cannot narrow a document query.
- `docs/architecture/interaction-views.md:165` — the claim that a view `Deny` or a sprint-scoped role "also covers its notes".
## Required outcome
- A principal denied a view must not be able to read or modify that view's notes through the document-by-id routes, ideally including batch-get and the collab/realtime authorization path.
- At minimum, the documentation and PR description must say that view access governs listing and creation only, so the limitation is not mistaken for a guarantee.
## Suggested approach (optional)
- Add `doc.view_id` (and the view's sprint) to the IAM attribute schema, the per-kind loaders and `docScopeColumns`, so the existing document scope can express note→view→sprint membership for every doc query and for the authorizer.
- Alternatively, resolve the document's `view_id` before authorizing the item routes and require `views:read` (and `views:write` for mutations) on `project/<p>/view/<view_id>`.
- Consider `views:write` for `POST /docs` with `view_id`, matching how a view mutation is gated elsewhere.| -- Lock order (see 000088): the doc change counter is taken before any | ||
| -- document row. A view delete reaches the counter while it holds the view | ||
| -- row, so a note insert takes the view row (FOR KEY SHARE, see | ||
| -- CreateDocument in internal/repository/postgres/document_repository.go) | ||
| -- before the counter too: view, then counter, then documents. |
There was a problem hiding this comment.
The documented lock order holds for a single DELETE FROM sprint_views, but not for the sprint cascade the comment above advertises: the cascade deletes the sprint's view rows one at a time inside one statement, and each row's trigger takes the change counter before the remaining view rows are locked. With a concurrent CreateDocument (which takes FOR KEY SHARE on the target view, then the counter), a sprint delete that takes the counter for an earlier note view and then waits on that key-share deadlocks against the insert waiting for the counter. Sprint deletes over two note views (goals + retro, the use case this PR adds) are enough to hit it, and one request then fails with a deadlock error.
Technical details
# Sprint-delete cascade inverts the view → counter → documents order
## Affected sites
- `services/api/migrations/000094_add_note_view_type.sql:25-29` — the lock-order comment claims coverage of the sprint cascade.
- `services/api/migrations/000094_add_note_view_type.sql:63-67` — the trigger takes `doc_sync_state` (counter) from inside the per-row `BEFORE DELETE`.
- `services/api/internal/repository/postgres/sprint_repository.go:222-232` — `DeleteSprint` is a single `DELETE FROM sprints WHERE id = $1` with no prior view-row locking.
- `services/api/internal/repository/postgres/document_repository.go:662-673` — `CreateDocument` takes `SELECT … FOR KEY SHARE` on the view, then `lockDocSeq`.
## Interleaving
1. TX2 `CreateDocument` into view B: `FOR KEY SHARE` on B granted, then blocks on the counter.
2. TX1 `DELETE FROM sprints`: the cascade deletes view A, whose trigger takes the counter.
3. TX1 reaches B's row lock (granted only to the row's exclusive lock) and blocks on TX2's key share.
## Required outcome
- A sprint delete of several views must acquire the view rows in a deterministic order before any trigger takes the counter, so a concurrent note insert either blocks before its key share or sees the view gone (`ErrNoteViewInvalid`).
- If that is not fixed here, the migration comment at lines 17-18 and 25-29 must not claim the cascade is covered.
## Suggested approach (optional)
- Wrap `DeleteSprint` in an explicit transaction that first locks the sprint's views (`SELECT id FROM sprint_views WHERE sprint_id = $1 ORDER BY id FOR NO KEY UPDATE`) and then deletes the sprint; the per-row trigger then sees all view rows already held.
- A concurrency test (two note views in one sprint, insert racing the sprint delete) would keep the claim honest.
pikann
left a comment
There was a problem hiding this comment.
LGTM! Thank you for the contribution! 🚀

Summary
Adds a Note view type (closes #772). A note view holds free-form writing that belongs to one view, such as sprint goals, planning notes, meeting minutes or a release checklist. You add it from Add view next to Board, Table and Gantt, in the Sprint, Backlog and Timeline interactions. Its notes are ordinary documents: they open in the docs editor and keep snapshots, activity, comments, file uploads and live collaboration. They belong to the view instead of a folder.
Data model (migration
000094)sprint_views.view_typenow allowsnote, following the000006/000090precedent.documents.view_idreferences the note view. A CHECK constraint (view_id IS NULL OR folder_id IS NULL) means a document is either in the docs tree or in one view, never both.deleted_at), as deleting a document does. ABEFORE DELETEtrigger does this, so views removed with their sprint are covered too. The trigger takes the doc change counter before any document row, as migration000088requires. Creating a note takes the view rowFOR KEY SHAREbefore the counter, so a concurrent view delete cannot deadlock with it. Views removed with their project are skipped, because the cascade deletes that project's documents anyway.API
GET /docs?view_id=lists a view's notes in manual order.POST /docswithview_idcreates one; the response is400 DOC_NOTE_VIEW_INVALIDunlessview_idnames a note view of the project. The other document routes (read, update, reorder byposition, delete, snapshots, activity, comments, files) serve notes unchanged./docs/by-path,/docs/search(its hits are located by path) and the change feed. Moving a note into a folder returns400 DOC_NOTE_IN_FOLDER.docs:read/docs:writeand the document scope apply as before. A newDocViewgate also requiresviews:readon the view that a listing or create names. ADenyon the view, or a role limited to one sprint's views (view.sprint_id), therefore covers its notes too.notereturns400 VIEW_NOTE_TYPE_CHANGE, so notes are never left in a view that cannot show them.Web
Noteis added toViewLayout,viewTypeToLayout/layoutToViewTypeand the new-view popover.docs:write; withoutdocs:readthe view shows a no-permission state.docs/$docId.tsxmoves unchanged into aDocumentPanecomponent. Both the route and the note view render it.MCP
create_view/update_viewacceptviewType: "note".list_docsandwrite_doctakeviewId: list a view's notes with theirdocId, or create/update a note by title.delete_docalso takesdocId, since notes have no path.read_docandedit_docalready work bydocId.ALL_TOOLS.mdand the README now list the document tools that actually exist, replacing outdated names.Out of scope, as in the issue: moving notes between a view and the docs tree, and folders inside a note view. Things a reviewer may want to know:
position, which records no activity entry, so other open clients see the new order on their next refetch, not live.docs/. Duplicate titles are numbered, as before.Type of Change
Checklist
Testing
view_idhandling, theDocViewgate (sprint-scoped role, unknown view, folded body keys, trailing JSON) and route coverage for the new gate.TestRealMigrations_ApplyCleanlyFromScratchpasses, as do the doc by-path, change feed, search, Gantt and view e2e tests,go vetandgolangci-lint(0 issues).TestWriteDocumentAtPath_DocDeletedBeforeRowLockIsPathChanged,TestGitStore_ChangeRequestsAndTaskLinks) fail on my machine with and without this change.note-view.test.tsxcovers listing and opening notes, creating and naming one, keeping the typed title when a rename is refused, reordering, a second move before the first is saved, deleting, read-only mode, no access and the empty state.tsc -b,biome checkand the vitest suite pass.GitSettings.test.tsxtimes out on my machine with and without this change.list_docs/write_docwithviewIdanddelete_docwithdocId.note-views.spec.tspasses on chromium and mobile-chrome against a local stack (API, Vite dev server, Postgres, Valkey, RustFS): create a note view, write and save a note, notes stay out of the Docs sidebar, reorder, delete. The existinginteraction-viewsanddocsspecs pass too. Twomanaged-copiesscenarios fail on that stack with and without this change, because it runs no realtime service.