Merge pull request #3154 from marc1006/issue_2970

Copy the labels only if the target board is different
This commit is contained in:
Lauri Ojansivu 2020-06-08 21:34:56 +03:00 committed by GitHub
commit 39a8524354
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -368,8 +368,15 @@ Cards.allow({
Cards.helpers({ Cards.helpers({
copy(boardId, swimlaneId, listId) { copy(boardId, swimlaneId, listId) {
const oldId = this._id;
const oldCard = Cards.findOne(oldId);
// 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 oldBoard = Boards.findOne(this.boardId);
const oldBoardLabels = oldBoard.labels; const oldBoardLabels = oldBoard.labels;
// Get old label names // Get old label names
const oldCardLabels = _.pluck( const oldCardLabels = _.pluck(
_.filter(oldBoardLabels, label => { _.filter(oldBoardLabels, label => {
@ -386,12 +393,11 @@ Cards.helpers({
}), }),
'_id', '_id',
); );
// now set the new label ids
const oldId = this._id; delete this.labelIds;
const oldCard = Cards.findOne(oldId); this.labelIds = newCardLabels;
// Copy Custom Fields // Copy Custom Fields
if (oldBoard._id !== boardId) {
CustomFields.find({ CustomFields.find({
_id: { _id: {
$in: oldCard.customFields.map(cf => { $in: oldCard.customFields.map(cf => {
@ -404,8 +410,6 @@ Cards.helpers({
} }
delete this._id; delete this._id;
delete this.labelIds;
this.labelIds = newCardLabels;
this.boardId = boardId; this.boardId = boardId;
this.swimlaneId = swimlaneId; this.swimlaneId = swimlaneId;
this.listId = listId; this.listId = listId;
@ -1298,19 +1302,16 @@ Cards.mutations({
}, },
move(boardId, swimlaneId, listId, sort) { move(boardId, swimlaneId, listId, sort) {
// Copy Custom Fields const mutatedFields = {
if (this.boardId !== boardId) { boardId,
CustomFields.find({ swimlaneId,
_id: { listId,
$in: this.customFields.map(cf => { sort,
return cf._id; };
}),
},
}).forEach(cf => {
if (!_.contains(cf.boardIds, boardId)) cf.addBoard(boardId);
});
}
// 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 // Get label names
const oldBoard = Boards.findOne(this.boardId); const oldBoard = Boards.findOne(this.boardId);
const oldBoardLabels = oldBoard.labels; const oldBoardLabels = oldBoard.labels;
@ -1330,13 +1331,21 @@ Cards.mutations({
'_id', '_id',
); );
const mutatedFields = { Object.assign(mutatedFields, {
boardId,
swimlaneId,
listId,
sort,
labelIds: newCardLabelIds, labelIds: newCardLabelIds,
}; });
// Copy custom fields
CustomFields.find({
_id: {
$in: this.customFields.map(cf => {
return cf._id;
}),
},
}).forEach(cf => {
if (!_.contains(cf.boardIds, boardId)) cf.addBoard(boardId);
});
}
Cards.update(this._id, { Cards.update(this._id, {
$set: mutatedFields, $set: mutatedFields,