mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Moving a list to another swimlane on the same board did nothing: the list kept
its empty swimlaneId, so it went on rendering under every swimlane, and
deleting "the one in the second swimlane" deleted the only list document there
was. Backups showed the empty swimlaneId the report describes.
List.move(boardId, swimlaneId) asked "does the target board already have a list
with this name?" without first asking whether the target board IS this list's
board:
const boardList = await ReactiveCache.getList({
boardId, title: this.title, archived: false });
if (boardList) { ...merge, never writes a swimlaneId... }
else { ...insert a new list WITH the swimlaneId... }
On a same-board move that search finds THIS LIST, so the merge branch ran - and
the merge branch is the one branch that never writes a swimlaneId. The chosen
swimlane was discarded every time, which is why the binding could not be
restored by hand either.
Merging is only meaningful across boards. On the same board a move is a
re-bind, so that is what it does now. The decision lives in
models/lib/listMovePlan.js, where it can be unit-tested, and models/lists.js
applies it: same board -> rebind this list, other board with the name taken ->
merge the cards into that list, other board -> create it there, bound. An empty
swimlaneId stays a deliberate un-bind back to board-wide, which is still a
legitimate layout. moveList now also refuses a swimlane that is not on the
board the list is moving to.
The same branch called `card.move(boardId, this._id, boardList._id)`, and
Card.move's second argument is a swimlaneId - so it set every card's swimlaneId
to a LIST id, i.e. to a swimlane that does not exist, and those cards became
the orphaned cards the board-open repair then has to rescue. The cards were
also selected as `this.cards(swimlaneId)`, filtering the SOURCE list's cards by
a swimlaneId belonging to the TARGET board, which on a cross-board move matches
nothing and left every card behind. Both are gone: the list's own cards travel
with it, into the chosen swimlane.
A negative test scans models/lists.js for any card.move() whose second argument
is not a swimlane, so this cannot come back at another call site - it found the
argument order was wrong in only this one place, and the scan now ignores
comments so the explanation of the fix does not trip it.
This does not restore bindings already lost. Boards opened under the versions
before #6515 had every list un-bound automatically, and which swimlane each
list belonged to is not recoverable from the data; with this fix that binding
can at least be set again from Move List.
Thanks to TawsTm and xet7 !
Fixes #6670,
62 lines
2.4 KiB
JavaScript
62 lines
2.4 KiB
JavaScript
'use strict';
|
|
|
|
// Pure decision for List.move(boardId, swimlaneId) — no DB access, so it is
|
|
// unit-testable (tests/listMoveSwimlane.test.cjs). models/lists.js applies it.
|
|
//
|
|
// #6670 "Lists lose swimlane ID". Moving a list to another swimlane ON THE SAME
|
|
// BOARD did not bind it to that swimlane, so the list stayed board-wide and
|
|
// rendered under every swimlane — and deleting it from one swimlane deleted the
|
|
// one and only list document, i.e. it vanished from all of them.
|
|
//
|
|
// The cause was that move() looked for "a list with this title on the target
|
|
// board" to merge into, without first asking whether the target board IS this
|
|
// list's board. On a same-board move that search finds THIS LIST, so the merge
|
|
// branch was taken, and the merge branch is the one branch that never writes a
|
|
// swimlaneId — only the create-on-another-board branch did. The user's chosen
|
|
// swimlane was therefore discarded every time.
|
|
//
|
|
// Merging is only meaningful across boards, where a list of the same name may
|
|
// already exist. On the same board a move is a re-bind (and a reposition), so
|
|
// that is what this plans:
|
|
//
|
|
// same board -> 'rebind' (this list, set its swimlaneId)
|
|
// other board, name exists -> 'merge' (move the cards into that list)
|
|
// other board, name is new -> 'create' (make the list there, bound)
|
|
//
|
|
// An empty targetSwimlaneId is a deliberate un-bind: the list becomes
|
|
// board-wide again, which is what shared lists were before per-swimlane lists
|
|
// and is still a legitimate layout.
|
|
|
|
function planListMove({
|
|
listId,
|
|
listBoardId,
|
|
listSwimlaneId,
|
|
targetBoardId,
|
|
targetSwimlaneId,
|
|
existingListId,
|
|
} = {}) {
|
|
const swimlaneId = typeof targetSwimlaneId === 'string' ? targetSwimlaneId : '';
|
|
const current = typeof listSwimlaneId === 'string' ? listSwimlaneId : '';
|
|
|
|
if (listBoardId === targetBoardId) {
|
|
return {
|
|
action: 'rebind',
|
|
listId,
|
|
swimlaneId,
|
|
// Writing the same value again would be a pointless update, and the
|
|
// before/after hooks it triggers are not free on a large board.
|
|
rebind: current !== swimlaneId,
|
|
};
|
|
}
|
|
|
|
if (existingListId) {
|
|
// The destination board's own list keeps its own swimlane binding; only the
|
|
// cards travel.
|
|
return { action: 'merge', listId: existingListId, swimlaneId, rebind: false };
|
|
}
|
|
|
|
return { action: 'create', listId: null, swimlaneId, rebind: false };
|
|
}
|
|
|
|
module.exports = { planListMove };
|