* feat: Add reasons for archived and deleted documents
* feat: Add deprecation reasons to archived collections
* fix: Refine deprecation reason display for readers
* feat: Accept reasons when archiving or deleting
* Support reasons in archive and delete MCP tools
* Fix placeholder after clearing content editable text
* Keep the caret before content editable placeholders
* Remove test
* feat: Add archive reasons to the confirmation dialog
* feat: Record who deleted a document
The trash inferred the deleting user from lastModifiedById, so a nested page
kept whoever last edited it and deleting a document rewrote its edit history.
Add a dedicated deletedById column and set it from the base model.
- Migration adds the column, backfills from lastModifiedById, and validates the
foreign key without holding an exclusive lock. The backfill runs in batches
against a temporary index covering only the rows still to write, so it stays
linear on a large table, and every statement is idempotent because the
migration cannot run in a transaction.
- ParanoidModel records the acting user on destroy and clears it on restore,
for any model that has the column. Sequelize soft deletes with the same UPDATE
that stamps deletedAt, so the value costs no extra query.
- Deleting a document no longer touches lastModifiedById on its descendants.
- Present the deleting user, batched in presentDocuments, and use it for the
trash notice and the document meta line rather than the last editor.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* fix: Do not overwrite an eager loaded deleting user when batching
The batch lookup in presentDocuments skipped documents that already carried the
association, but the assignment loop ran for all of them, so a document that
arrived with deletedBy loaded was reset to null and fell back to a per-document
query. Assign only where the association is missing, and deduplicate the ids so
a page deleted by one person asks for one row rather than one per document.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Viewing the trash showed everything the whole workspace had deleted, which
is noisy for anyone looking for their own document. Default the view to the
items the current user deleted, and add user and date filters — matching the
shape of the search filters — to widen it again.
- Attribute a deleted subtree to the acting user. Deleting a document only
recorded the actor against the document itself, so nested pages kept
whoever last edited them and would have been hidden from their deleter.
- Move documents.deleted onto the filter DSL, exposing deletedById and
deletedAt. deletedById is mapped to the column that currently records the
deleting user, so adding a dedicated column later leaves the API unchanged.
- Lift the date filter duration map into shared, where search and the trash
both read it rather than keeping a copy each.
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Deleting a document walked its subtree with one query per document and
destroyed each in a serial post-order recursion, so large subtrees could
exceed the request statement_timeout.
Resolve the subtree with the existing recursive CTE helper and load the
children in a single query instead. Documents are still destroyed one at
a time so model hooks run for each, and deepest-first ordering is kept.
The subtree lookup also dropped the options it was passed, so it ran
outside the request transaction.
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
* wip
* Remove obsolete snapshots
* simplify
* chore(test): Convert mocks to TypeScript and tighten fetch mock types
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* Remove unneccessary patches
* Migrate to msw instead of custom fetch mock
* Address PR review comments
- Split chained vi.useFakeTimers().setSystemTime() into separate calls.
- Switch test setup to dynamic imports so EventEmitter.defaultMaxListeners
assignment runs before module init (static imports were hoisted above it).
- Drop redundant NODE_ENV guard in monkeyPatchSequelizeErrorsForJest; its
sole caller already gates on env.isTest.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
* feat: Add delete_document and delete_collection MCP tools
Adds MCP tools for deleting (or archiving) documents and collections.
Refactors Document#delete into destroyWithCtx and extracts collection
archive logic into Collection#archiveWithCtx so the same code paths can
be shared between the REST API and MCP entry points.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix: Wrap MCP delete tools in DB transaction
Ensures delete/archive of documents and collections via MCP is atomic
and that row locks (transaction.LOCK.UPDATE) inside *WithCtx methods
actually apply, matching the pattern used by move_document.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* docs: Clarify delete_collection MCP tool description
Reflects that collection deletion only soft-deletes non-archived
documents via the BeforeDestroy hook.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Capture jest mock references in local variables instead of asserting
against unbound method references on mocked classes/instances.
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
* Allow Document to be fetched without Slug
Fixes#3423
This PR refactors the `Document.findByPk` method to not require the
`slug` portion of the urlID.
Before this function accepted two different 'formats' for the ID.
- The `uuid` ID of the Document
- The full `urlID` which looked something like
`some-document-1234567890`
However the `some-document` slug portion of this identifier wasn't
actually used when looking for a document.
We now allow searching by JUST the postfix of the `urlID`, in the above
example that is `1234567890`.
We do this via a new Regex pattern to match on that just looks for the
right looking id alone, without the prefix.
This codepath looks the same as when we find it by the full `urlID`
besides the different regex that we match on.
The issue #3423 mentions that this should apply to all the API
endpoints. I believe that this `findByPk` method is all that should be
needed for that change. But if this is incorrect, OR you would like more
test coverage on the API endpoints as a more 'end to end test' please
let me know!
* Change original regex to make the slug optional
This has the, I believe to be good, side-effect of making the same logic
apply to `Collection` as well. Since `Collection` was always doing the
same stripping of the slug before the lookup I believe it should be just
as safe to do there.
We don't have to touch the code in Collections but we add a test of this
behavior there as well.
* No reason to rename this now that we aren't doing two matches
This PR moves the entire project to Typescript. Due to the ~1000 ignores this will lead to a messy codebase for a while, but the churn is worth it – all of those ignore comments are places that were never type-safe previously.
closes#1282