fix: Complete customizable document retention

Follow-up fixes to the retention feature.

The superseded CleanupDeletedDocumentsTask was still registered and ran
hourly, hard deleting documents 30 days after `deletedAt` regardless of the
team's configured period. Any retention longer than 30 days — including
infinite — had no effect.

The `destroyedAt` column was declared with a bare `@Column`. Decorator
metadata is disabled in the server build, so sequelize-typescript could not
infer its type and threw while loading the Document model.

Documents pending permanent deletion stayed readable and restorable through
`documents.info`, `documents.restore` and the MCP restore tool. They are now
treated as if they no longer exist.

Also:

- Add trash and data retention controls to workspace security settings, the
  only way to configure either was to call the API directly.
- Derive the retention tranches to process from the periods teams actually
  use, so a team holding a period that is no longer offered is not skipped.
- Bound the trash expiry task by `limit`, it previously ran an unbounded
  UPDATE across the whole documents table every hour.
- Match team preferences on JSON text rather than casting to int, so one bad
  value cannot fail the query for every other team in the batch.
- Derive the API validation schema from the same presets the UI offers.
- Send `ASC` rather than `asc` from the trash list, the sort direction was
  silently coerced back to descending.
- Move the retention badge in with the other document badges, pluralize it,
  and never show a negative day count.
- Drop the unused `Template.destroyedAt` computed, which returned a future
  date under a name meaning the opposite on the sibling model.
- Rename the migration to match its position in the sequence and the column
  it adds.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U3kXbDxLMJesYLM5E4P6HQ
This commit is contained in:
Claude authored and Tom Moor committed 2026-08-16 14:36:32 -04:00
1 parent 750c30b470
commit 597acedf0b
25 files changed
+717 -177

No files matched your search

+12
View File
@@ -17,6 +17,18 @@ export const RetentionPeriodPresets: readonly RetentionPeriodPreset[] = [
0, 7, 14, 30, 90, 180, 365,
];
/**
* Whether the given value is a retention period that can be configured.
*
* @param value the value to check.
* @returns true if the value is a supported retention period.
*/
export function isRetentionPeriodPreset(
value: unknown
): value is RetentionPeriodPreset {
return RetentionPeriodPresets.some((days) => days === value);
}
export const MAX_AVATAR_DISPLAY = 6;
/** Height of the app's fixed header in pixels. */
+7 -2
View File
@@ -354,8 +354,8 @@
"New": "New",
"Only visible to you": "Only visible to you",
"Draft": "Draft",
"Permanently deletes in {{ days }} days": "Permanently deletes in {{ days }} days",
"{{ days }} days": "{{ days }} days",
"Will be permanently deleted in {{ count }} days unless restored": "Will be permanently deleted in {{ count }} day unless restored",
"Will be permanently deleted in {{ count }} days unless restored_plural": "Will be permanently deleted in {{ count }} days unless restored",
"You updated": "You updated",
"{{ userName }} updated": "{{ userName }} updated",
"You deleted": "You deleted",
@@ -1497,6 +1497,11 @@
"Allow editors to create new collections within the workspace": "Allow editors to create new collections within the workspace",
"Workspace creation": "Workspace creation",
"Allow editors to create new workspaces": "Allow editors to create new workspaces",
"Forever": "Forever",
"Trash retention": "Trash retention",
"How long deleted documents remain in the trash, where they can still be restored": "How long deleted documents remain in the trash, where they can still be restored",
"Data retention": "Data retention",
"How long documents are retained after leaving the trash, before they are permanently erased": "How long documents are retained after leaving the trash, before they are permanently erased",
"Could not load shares": "Could not load shares",
"Sharing is currently disabled.": "Sharing is currently disabled.",
"You can globally enable and disable public document sharing in the <em>security settings</em>.": "You can globally enable and disable public document sharing in the <em>security settings</em>.",