Skip to content

feat(views): add a Note view type whose documents belong to the view - #796

Merged
pikann merged 4 commits into
Paca-AI:masterfrom
officialasishkumar:feature/note-view
Nov 20, 2026
Merged

pikann merged 4 commits into
Paca-AI:masterfrom
officialasishkumar:feature/note-view

Conversation

@officialasishkumar

Copy link
Copy Markdown
Contributor

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_type now allows note, following the 000006/000090 precedent.
  • documents.view_id references 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.
  • Deleting a view soft-deletes its live notes (deleted_at), as deleting a document does. A BEFORE DELETE trigger does this, so views removed with their sprint are covered too. The trigger takes the doc change counter before any document row, as migration 000088 requires. Creating a note takes the view row FOR KEY SHARE before 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 /docs with view_id creates one; the response is 400 DOC_NOTE_VIEW_INVALID unless view_id names a note view of the project. The other document routes (read, update, reorder by position, delete, snapshots, activity, comments, files) serve notes unchanged.
  • Notes stay out of everything that addresses the docs tree: tree listings, /docs/by-path, /docs/search (its hits are located by path) and the change feed. Moving a note into a folder returns 400 DOC_NOTE_IN_FOLDER.
  • Authorization stays in the router gates. Notes are documents, so docs:read/docs:write and the document scope apply as before. A new DocView gate also requires views:read on the view that a listing or create names. A Deny on the view, or a role limited to one sprint's views (view.sprint_id), therefore covers its notes too.
  • A note view keeps its type. Switching a view to or from note returns 400 VIEW_NOTE_TYPE_CHANGE, so notes are never left in a view that cannot show them.

Web

  • Note is added to ViewLayout, viewTypeToLayout/layoutToViewType and the new-view popover.
  • The view lists its notes on the left and opens the selected one on the right. New note creates "Untitled" and opens it for renaming. The ⋯ menu renames, moves a note up or down, and deletes it after a confirmation. All of these need docs:write; without docs:read the view shows a no-permission state.
  • To reuse the docs editor instead of building a second one, the body of docs/$docId.tsx moves unchanged into a DocumentPane component. Both the route and the note view render it.
  • No task query runs for a note view. Its task search and view settings are hidden.
  • Strings are added in en and translated for the other 8 locales.

MCP

  • create_view/update_view accept viewType: "note".
  • list_docs and write_doc take viewId: list a view's notes with their docId, or create/update a note by title.
  • delete_doc also takes docId, since notes have no path. read_doc and edit_doc already work by docId.
  • The changelog is updated. ALL_TOOLS.md and 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:

  • A reorder saves position, which records no activity entry, so other open clients see the new order on their next refetch, not live.
  • A project export still includes notes, written next to the root documents under docs/. Duplicate titles are numbered, as before.

Type of Change

  • Other (feature: Note view type)

Checklist

  • The change is focused and scoped.
  • Related documentation is updated.
  • New structure or direction is explained clearly.
  • I avoided unnecessary detail or premature abstraction.

Testing

  • Go:
    • Unit tests cover creating notes (view checks, no folder, no view lookup), refusing folder moves, the view type rule, the handler's view_id handling, the DocView gate (sprint-scoped role, unknown view, folded body keys, trailing JSON) and route coverage for the new gate.
    • Postgres tests cover listing by view and never in the tree, paths, search, the change feed, the schema CHECK, and soft-delete with the view or the sprint. They also cover a hard project delete with notes written in the same transaction, the case the project guard in the trigger is for. A view delete with no notes leaves the doc counter alone.
    • A new e2e test covers the HTTP flow (create, list, edit, refused folder moves, refused type changes, deletion with the view and the sprint) and checks that the migration can be re-run.
    • TestRealMigrations_ApplyCleanlyFromScratch passes, as do the doc by-path, change feed, search, Gantt and view e2e tests, go vet and golangci-lint (0 issues).
    • Two Postgres repository tests (TestWriteDocumentAtPath_DocDeletedBeforeRowLockIsPathChanged, TestGitStore_ChangeRequestsAndTaskLinks) fail on my machine with and without this change.
  • Web:
    • note-view.test.tsx covers 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 check and the vitest suite pass. GitSettings.test.tsx times out on my machine with and without this change.
  • MCP: lint, build and the full test suite pass. New tests cover list_docs/write_doc with viewId and delete_doc with docId.
  • Playwright: note-views.spec.ts passes 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 existing interaction-views and docs specs pass too. Two managed-copies scenarios fail on that stack with and without this change, because it runs no realtime service.

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]>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 — note joins the view_type CHECK; documents.view_id with an ON DELETE SET NULL FK, a view_id IS NULL OR folder_id IS NULL CHECK, a partial index, and a BEFORE DELETE trigger that soft-deletes a view's live notes (skipping hard project deletes).
  • Document repository — view_id in the column lists; notes listed only by view; tree listings, path lookup, search, feed and fingerprint all exclude notes; CreateDocument takes the view row FOR KEY SHARE before the change counter.
  • Document service — WithViews + checkNoteView (DOC_NOTE_VIEW_INVALID), folder moves of a note refused (DOC_NOTE_IN_FOLDER), and UpdateView refuses any type change to or from note (VIEW_NOTE_TYPE_CHANGE).
  • Authorization — new RequireDocView middleware and guards.DocView() on the /docs collection routes, authorizing views:read on the view named by view_id.
  • Web — NoteView (list, create, inline rename, reorder by position, confirmed delete, read-only and no-access states) beside a DocumentPane that is the former $docId route body moved verbatim; task queries and view settings are skipped for note views.
  • MCP — viewId on list_docs/write_doc, docId on delete_doc, and note accepted by create_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?

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

Comment on lines +894 to +895
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +25 to +29
-- 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 pikann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for the contribution! 🚀

@pikann
pikann merged commit 3071099 into Paca-AI:master Nov 20, 2026
9 checks passed
@pikann pikann mentioned this pull request Nov 20, 2026
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.

[Feature] Note view type: documents that belong to a view

2 participants