Files
wekan/models/lib/autoArchive.js
T
Lauri Ojansivu 22c62b7b39 Archive cards automatically after a chosen number of days without activity.
Board Settings gains Nextcloud Deck's auto-archive: a board admin sets a
number of days from 1 to 3650, and an hourly job archives the board's cards
whose last activity is older than that, with their subtasks and an
archivedCard activity attributed to the board creator, as scheduled rules
are. Empty means off, templates are never archived, and each run takes at
most 200 cards per board. The same date drives the card-aging fade, so a
card fades before it goes. New strings are English, pending Transifex.

Thanks to xet7 !
2026-09-29 16:40:48 +03:00

51 lines
1.7 KiB
JavaScript

'use strict';
// Nextcloud Deck-style auto-archive: a board setting that archives cards
// nobody has touched for N days. Off unless a board admin sets a number of
// days in Board Settings; the hourly job is server/autoArchiveCards.js.
//
// "Touched" is the card's dateLastActivity, which every change to the card
// refreshes (models/cards.js autoValue) - the same date the card-aging fade
// (#3984) reads, so a card fades before it is archived.
const AUTO_ARCHIVE_MAX_DAYS = 3650;
const DAY_MS = 24 * 60 * 60 * 1000;
// Archived per board per run, so one huge board cannot hold the job up.
const AUTO_ARCHIVE_BATCH = 200;
// A whole number of days from 1 to 3650, or null (off).
function normalizeAutoArchiveDays(value) {
if (value === null || value === undefined || value === '') return null;
const days = Number(value);
if (!Number.isInteger(days) || days < 1 || days > AUTO_ARCHIVE_MAX_DAYS) return null;
return days;
}
function autoArchiveCutoff(days, now = new Date()) {
return new Date(now.getTime() - days * DAY_MS);
}
// The cards of one board to archive now. Templates are never archived: they
// are not work that went stale.
function autoArchiveCardSelector(boardId, days, now = new Date()) {
return {
boardId,
archived: false,
type: { $ne: 'template-card' },
dateLastActivity: { $lt: autoArchiveCutoff(days, now) },
};
}
// Boards with the setting on. Template containers and archived boards are
// left alone.
const AUTO_ARCHIVE_BOARD_SELECTOR = {
autoArchiveInactiveDays: { $gte: 1 },
archived: false,
type: 'board',
};
module.exports = {
AUTO_ARCHIVE_MAX_DAYS, AUTO_ARCHIVE_BATCH, AUTO_ARCHIVE_BOARD_SELECTOR,
normalizeAutoArchiveDays, autoArchiveCutoff, autoArchiveCardSelector,
};