Files
wekan/server/lib/ruleCardRelations.js
T
Lauri Ojansivu b5c15e95ed Include canonical and legacy Gantt relationships in rule emails
Group readable targets while retaining distinct relationship types and source-access checks. Cover malformed legacy arrays and real SMTP rendering.

Thanks to kabi178, bbyszio and xet7 !
2026-09-28 20:35:33 +03:00

27 lines
1.3 KiB
JavaScript

'use strict';
const { normalizeDependencies } = require('../../models/metadata/dependencies');
// DHTMLX defaults: https://docs.dhtmlx.com/gantt/api/config/links/
const ganttTypes = ['finish-to-start', 'start-to-start', 'finish-to-finish', 'start-to-finish'];
function ruleCardRelations(card) {
const targets = new Map();
const add = (id, label) => {
if (typeof id !== 'string' || !id) return;
if (!targets.has(id)) targets.set(id, new Set());
targets.get(id).add(label);
};
for (const entry of normalizeDependencies(Array.isArray(card.cardDependencies) ? card.cardDependencies : [])) {
add(entry.cardId, entry.type);
}
const ids = Array.isArray(card.targetId_gantt) ? card.targetId_gantt : [];
const types = Array.isArray(card.linkType_gantt) ? card.linkType_gantt : [];
// Legacy removal used independent $pull operations, which can unpair types
// and targets. Preserve readable targets without guessing the missing type.
const aligned = ids.length === types.length;
ids.forEach((id, index) => {
const type = aligned && Number.isInteger(types[index]) ? ganttTypes[types[index]] : null;
add(id, type ? `Gantt ${type}` : 'Gantt target');
});
return [...targets].map(([cardId, labels]) => ({ cardId, label: [...labels].join(' / ') }));
}
module.exports = { ruleCardRelations };