diff options
author | Marc Hartmayer <hello@hartmayer.com> | 2020-06-05 08:29:46 +0200 |
---|---|---|
committer | Marc Hartmayer <hello@hartmayer.com> | 2020-06-05 08:54:10 +0200 |
commit | df9851e2b7a37138476fbd12d5ca209835047d97 (patch) | |
tree | 2d65682bd34286ce7c7d2927f178b139253c9408 /models | |
parent | 232bc746f4b2d09945fdfe68e3aa14ff6f4e79f6 (diff) | |
download | wekan-df9851e2b7a37138476fbd12d5ca209835047d97.tar.gz wekan-df9851e2b7a37138476fbd12d5ca209835047d97.tar.bz2 wekan-df9851e2b7a37138476fbd12d5ca209835047d97.zip |
Copy the labels only if the target board is different
This fixes the issues https://github.com/wekan/wekan/issues/2404 and
https://github.com/wekan/wekan/issues/2970 if the target board doesn't differ
from the source board.
Diffstat (limited to 'models')
-rw-r--r-- | models/cards.js | 111 |
1 files changed, 60 insertions, 51 deletions
diff --git a/models/cards.js b/models/cards.js index e1d48653..f78fb76c 100644 --- a/models/cards.js +++ b/models/cards.js @@ -368,30 +368,36 @@ Cards.allow({ Cards.helpers({ copy(boardId, swimlaneId, listId) { - const oldBoard = Boards.findOne(this.boardId); - const oldBoardLabels = oldBoard.labels; - // Get old label names - const oldCardLabels = _.pluck( - _.filter(oldBoardLabels, label => { - return _.contains(this.labelIds, label._id); - }), - 'name', - ); - - const newBoard = Boards.findOne(boardId); - const newBoardLabels = newBoard.labels; - const newCardLabels = _.pluck( - _.filter(newBoardLabels, label => { - return _.contains(oldCardLabels, label.name); - }), - '_id', - ); - const oldId = this._id; const oldCard = Cards.findOne(oldId); - // Copy Custom Fields - if (oldBoard._id !== boardId) { + // we must only copy the labels and custom fields if the target board + // differs from the source board + if (this.boardId !== boardId) { + const oldBoard = Boards.findOne(this.boardId); + const oldBoardLabels = oldBoard.labels; + + // Get old label names + const oldCardLabels = _.pluck( + _.filter(oldBoardLabels, label => { + return _.contains(this.labelIds, label._id); + }), + 'name', + ); + + const newBoard = Boards.findOne(boardId); + const newBoardLabels = newBoard.labels; + const newCardLabels = _.pluck( + _.filter(newBoardLabels, label => { + return _.contains(oldCardLabels, label.name); + }), + '_id', + ); + // now set the new label ids + delete this.labelIds; + this.labelIds = newCardLabels; + + // Copy Custom Fields CustomFields.find({ _id: { $in: oldCard.customFields.map(cf => { @@ -404,8 +410,6 @@ Cards.helpers({ } delete this._id; - delete this.labelIds; - this.labelIds = newCardLabels; this.boardId = boardId; this.swimlaneId = swimlaneId; this.listId = listId; @@ -1298,8 +1302,40 @@ Cards.mutations({ }, move(boardId, swimlaneId, listId, sort) { - // Copy Custom Fields + const mutatedFields = { + boardId, + swimlaneId, + listId, + sort, + }; + + // we must only copy the labels and custom fields if the target board + // differs from the source board if (this.boardId !== boardId) { + // Get label names + const oldBoard = Boards.findOne(this.boardId); + const oldBoardLabels = oldBoard.labels; + const oldCardLabels = _.pluck( + _.filter(oldBoardLabels, label => { + return _.contains(this.labelIds, label._id); + }), + 'name', + ); + + const newBoard = Boards.findOne(boardId); + const newBoardLabels = newBoard.labels; + const newCardLabelIds = _.pluck( + _.filter(newBoardLabels, label => { + return label.name && _.contains(oldCardLabels, label.name); + }), + '_id', + ); + + Object.assign(mutatedFields, { + labelIds: newCardLabelIds, + }); + + // Copy custom fields CustomFields.find({ _id: { $in: this.customFields.map(cf => { @@ -1311,33 +1347,6 @@ Cards.mutations({ }); } - // Get label names - const oldBoard = Boards.findOne(this.boardId); - const oldBoardLabels = oldBoard.labels; - const oldCardLabels = _.pluck( - _.filter(oldBoardLabels, label => { - return _.contains(this.labelIds, label._id); - }), - 'name', - ); - - const newBoard = Boards.findOne(boardId); - const newBoardLabels = newBoard.labels; - const newCardLabelIds = _.pluck( - _.filter(newBoardLabels, label => { - return label.name && _.contains(oldCardLabels, label.name); - }), - '_id', - ); - - const mutatedFields = { - boardId, - swimlaneId, - listId, - sort, - labelIds: newCardLabelIds, - }; - Cards.update(this._id, { $set: mutatedFields, }); |