Files
wekan/server/lib/workloadAbsenceRetention.js
T
Lauri Ojansivu 176771109c Retention: the audit log, board activities and workload absences each have a limit an operator sets.
ADMIN_AUDIT_RETENTION_DAYS replaces the fixed year of the administrators'
audit log (365 by default, 0 keeps it, HIPAA sets 2190 or more).
ACTIVITIES_RETENTION_DAYS removes board activity rows older than that, and
WORKLOAD_ABSENCE_RETENTION_DAYS absences that ended that long ago, both off
by default; the change history of cards is never removed.
WORKLOAD_ABSENCE_TYPE_RECORDED=false stores every new absence as "other", so
no sick leave is recorded. Admin Panel / Settings / Legal pages shows every
personal-data collection with its retention and the value of its setting on
this server. Listed on every platform, the Helm chart included
(docs/Compliance/README.md WP-7, rows 2.5, 2.7 and 2.8).

Thanks to xet7 !
2026-11-24 02:59:10 +02:00

29 lines
1.6 KiB
JavaScript

// Once a day, when WORKLOAD_ABSENCE_RETENTION_DAYS is set (WP-7): workload
// absences that ENDED more than that many days ago are removed - absences can
// be health data ([GDPR] Art. 9). Off by default. An absence still running, or
// one in the future, is never touched.
import { Meteor } from 'meteor/meteor';
import { WorkloadAbsences } from '/models/workload';
const { retentionDays, cutoffDay } = require('/models/lib/retentionSettings');
export async function runWorkloadAbsenceRetention(now = Date.now()) {
const day = cutoffDay(retentionDays('WORKLOAD_ABSENCE_RETENTION_DAYS', { WORKLOAD_ABSENCE_RETENTION_DAYS: process.env.WORKLOAD_ABSENCE_RETENTION_DAYS }), now);
if (!day) return 0;
// The dates are YYYY-MM-DD strings, which compare as days.
return ((await WorkloadAbsences.rawCollection().deleteMany({ end: { $lt: day } })) || {}).deletedCount || 0;
}
if (Meteor.isServer) {
Meteor.startup(() => {
if (retentionDays('WORKLOAD_ABSENCE_RETENTION_DAYS', { WORKLOAD_ABSENCE_RETENTION_DAYS: process.env.WORKLOAD_ABSENCE_RETENTION_DAYS }) <= 0) return;
const runClaimed = async () => {
const { claimDailyJob } = require('/models/lib/dailyClaim');
if (!(await claimDailyJob(WorkloadAbsences.rawDatabase(), 'workload-absence-retention'))) return;
await runWorkloadAbsenceRetention();
};
Meteor.defer(() => { runClaimed().catch(error => console.error('Workload absence retention failed:', error)); });
Meteor.setInterval(() => { runClaimed().catch(error => console.error('Workload absence retention failed:', error)); }, 60 * 60 * 1000);
});
}