Files
wekan/models/lib/softDelete.js
T
Lauri Ojansivu 7e1f9e89eb Docs: every feature topic in one folder under docs/Features, each with README.md as its main page.
- The General/ level is gone: its 109 files moved up into the folders of the
  same name, and its topic table is the "Shared topics" section of
  Features.md.
- Accessibility is one folder, docs/Features/Accessibility/, with the Admin
  Panel's accessibility page in it.
- Every folder's main page is README.md (110 X/X.md pages renamed with git mv,
  five merged with an existing README.md, 26 index pages added for folders
  that had none), so a folder opened on GitHub shows its page.
- The 73 "# Moved" forwarding pages are deleted, with the folders that held
  only them; every link that went to one goes to its final page.
- docs/Features/README.md has the website's "Features in WeKan" overview,
  each feature linking to its page here.

1,129 Markdown links in 262 files and 352 doc paths in code, tests, compose,
snap and release files follow. tests/docsFeaturesLayout.test.cjs fails when
General/ or a "# Moved" page comes back, a folder has no README.md, or a
relative link in the docs or README.md does not resolve.

Thanks to xet7 !
2026-11-24 20:02:06 +02:00

66 lines
2.6 KiB
JavaScript

'use strict';
// Soft-delete core (delete = mark, never destroy). Design: docs/Features/Undo/README.md.
//
// Kept Meteor-free and CommonJS so these decisions are unit-testable
// (tests/softDelete.test.cjs) AND importable from server model code (Meteor's
// module system reads the named exports off `module.exports`). Every user-facing
// delete routes through here so the "no permanent delete in ordinary use" rule is
// enforced in one place; physical removal is only ever done by the flag-gated
// admin purge or by GDPR/account erasure.
// Add the "not soft-deleted" constraint to a Mongo/Minimongo selector.
// `{ deletedAt: null }` matches BOTH documents whose field is null and whose field
// is ABSENT (all pre-feature rows), so no migration/backfill is needed. Merges into
// an existing `$and` when present so we never clobber a sibling constraint.
function notDeleted(selector) {
const sel = selector || {};
if (sel && typeof sel === 'object' && Array.isArray(sel.$and)) {
return { ...sel, $and: [...sel.$and, { deletedAt: null }] };
}
return { ...sel, deletedAt: null };
}
// The `$set` applied when soft-deleting a document. `at` is passed in (never
// generated here) so the same batch of cascaded deletes shares one timestamp and
// the function stays pure/deterministic. Falsy userId/batchId are OMITTED rather
// than set to null: `deletedBy`/`deleteBatchId` are String schema fields and
// collection2 would reject a null value on update.
function softDeleteSet(userId, batchId, at) {
const set = { deletedAt: at };
if (userId) set.deletedBy = userId;
if (batchId) set.deleteBatchId = batchId;
return set;
}
// The full modifier applied when RESTORING (undo of a delete): drop all three
// bookkeeping fields, so a restored doc is indistinguishable from one that was
// never deleted. Pure `$unset` (rather than `$set deletedAt: null`) because setting
// an optional Date field to null trips SimpleSchema type validation; an absent
// field reads as "live" via the `{ deletedAt: null }` filter.
function restoreModifier() {
return {
$unset: { deletedAt: '', deletedBy: '', deleteBatchId: '' },
};
}
// Is a document soft-deleted?
function isDeleted(doc) {
return !!(doc && doc.deletedAt);
}
// May this user PHYSICALLY purge user content? Only a global admin, and only when
// the Admin Panel / Features / Delete toggle ("Enable permanent delete for Global
// Admin") is on. GDPR/account erasure is a SEPARATE path and does not consult this.
function canPurge(user, enablePermanentDelete) {
return !!(user && user.isAdmin) && !!enablePermanentDelete;
}
module.exports = {
notDeleted,
softDeleteSet,
restoreModifier,
isDeleted,
canPurge,
};