Files
wekan/models/lib/boardCopyDefaults.js
T
Lauri Ojansivu 25cdc4db0d Fix #4494: Creating a board from a template no longer breaks subtasks
Creating a board from a template copies the template board. The copy inherited
the template's subtasksDefaultBoardId / dateSettingsDefaultBoardId verbatim.
When those pointed at the template board itself, subtasks created on the NEW
board were dropped onto the TEMPLATE board, and the subtask card linked back
across boards to the parent.

Board.copy() now repoints any subtasks/date-settings default that referenced
the source board to the new copy, and clears the paired list id so it self-heals
to a list on the new board. Defaults that deliberately point at another (shared)
board are left untouched. The remap logic is a Meteor-free helper
models/lib/boardCopyDefaults.js, unit tested (positive + negative) in
tests/boardCopyDefaults.test.cjs.

Thanks to Xilef11 and xet7.
2026-07-09 09:45:53 +03:00

30 lines
1.3 KiB
JavaScript

'use strict';
// #4494 "Creating a board from a template breaks subtasks". Boards are created
// from a template by copying the template board. The copy inherited the
// template's subtasksDefaultBoardId / dateSettingsDefaultBoardId verbatim. When
// those pointed at the template board ITSELF (the common case — "subtasks live
// on this board"), subtasks created on the NEW board were dropped onto the
// TEMPLATE board, and the subtask card linked back across boards to the parent.
//
// remapCopiedBoardDefaults returns the $set patch that repoints any default
// board pointer referencing the source board to the copy instead. When a board
// pointer moves, its paired list pointer is cleared (null) because that list id
// belongs to the source board's lists; it self-heals to a list on the new
// board via Board.getDefaultSubtasksListId()/getDefaultDateSettingsListId().
// Meteor-free so it can be unit tested.
function remapCopiedBoardDefaults(board, oldId, newId) {
const patch = {};
if (board && board.subtasksDefaultBoardId === oldId) {
patch.subtasksDefaultBoardId = newId;
patch.subtasksDefaultListId = null;
}
if (board && board.dateSettingsDefaultBoardId === oldId) {
patch.dateSettingsDefaultBoardId = newId;
patch.dateSettingsDefaultListId = null;
}
return patch;
}
module.exports = { remapCopiedBoardDefaults };