From 2691f033cbd072864cf79e95d131a93449d3c84d Mon Sep 17 00:00:00 2001 From: Marc Hartmayer Date: Wed, 29 Apr 2020 22:38:50 +0200 Subject: Fix creation of card links Without this fix, orphaned card links are created and therefore this leads to problems as described in https://github.com/wekan/wekan/issues/2785. --- client/components/lists/listBody.js | 5 +---- models/cards.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/client/components/lists/listBody.js b/client/components/lists/listBody.js index 88f88db0..1bcd41c4 100644 --- a/client/components/lists/listBody.js +++ b/client/components/lists/listBody.js @@ -658,10 +658,7 @@ BlazeComponent.extendComponent({ _id = element.copy(this.boardId, this.swimlaneId, this.listId); // 1.B Linked card } else { - delete element._id; - element.type = 'cardType-linkedCard'; - element.linkedId = element.linkedId || element._id; - _id = Cards.insert(element); + _id = element.link(this.boardId, this.swimlaneId, this.listId); } Filter.addException(_id); // List insertion diff --git a/models/cards.js b/models/cards.js index 4197f7ab..498140b9 100644 --- a/models/cards.js +++ b/models/cards.js @@ -428,6 +428,21 @@ Cards.helpers({ return _id; }, + link(boardId, swimlaneId, listId) { + // TODO is there a better method to create a deepcopy? + linkCard = JSON.parse(JSON.stringify(this)); + // TODO is this how it is meant to be? + linkCard.linkedId = linkCard.linkedId || linkCard._id; + linkCard.boardId = boardId; + linkCard.swimlaneId = swimlaneId; + linkCard.listId = listId; + linkCard.type = 'cardType-linkedCard'; + delete linkCard._id; + // TODO shall we copy the labels for a linked card?! + delete linkCard.labelIds; + return Cards.insert(linkCard); + }, + list() { return Lists.findOne(this.listId); }, -- cgit v1.2.3-1-g7c22 From b740381a7248e1e059cecedcf6cd6824abb792b3 Mon Sep 17 00:00:00 2001 From: Marc Hartmayer Date: Thu, 30 Apr 2020 01:03:37 +0200 Subject: Refuse to delete a card as long as there is link to it This fixes https://github.com/wekan/wekan/issues/2785. --- client/components/cards/cardDetails.js | 7 ++++++- client/components/lists/listHeader.js | 21 +++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/client/components/cards/cardDetails.js b/client/components/cards/cardDetails.js index 271fbe2f..e8e36178 100644 --- a/client/components/cards/cardDetails.js +++ b/client/components/cards/cardDetails.js @@ -967,7 +967,12 @@ BlazeComponent.extendComponent({ }, 'click .js-delete': Popup.afterConfirm('cardDelete', function() { Popup.close(); - Cards.remove(this._id); + // verify that there are no linked cards + if (Cards.find({ linkedId: this._id }).count() === 0) { + Cards.remove(this._id); + } else { + // TODO popup... + } Utils.goBoardId(this.boardId); }), 'change .js-field-parent-board'(event) { diff --git a/client/components/lists/listHeader.js b/client/components/lists/listHeader.js index 46dbd748..a839bb72 100644 --- a/client/components/lists/listHeader.js +++ b/client/components/lists/listHeader.js @@ -223,8 +223,25 @@ BlazeComponent.extendComponent({ Template.listMorePopup.events({ 'click .js-delete': Popup.afterConfirm('listDelete', function() { Popup.close(); - this.allCards().map(card => Cards.remove(card._id)); - Lists.remove(this._id); + // TODO how can we avoid the fetch call? + const allCards = this.allCards().fetch(); + const allCardIds = _.pluck(allCards, '_id'); + // it's okay if the linked cards are on the same list + if ( + Cards.find({ + $and: [ + { listId: { $ne: this._id } }, + { linkedId: { $in: allCardIds } }, + ], + }).count() === 0 + ) { + allCardIds.map(_id => Cards.remove(_id)); + Lists.remove(this._id); + } else { + // TODO popup with a hint that the list cannot be deleted as there are + // linked cards. We can adapt the query above so we can list the linked + // cards. + } Utils.goBoardId(this.boardId); }), }); -- cgit v1.2.3-1-g7c22 From 9cba640120940eec45397d2daf8de573dbedf2b1 Mon Sep 17 00:00:00 2001 From: Marc Hartmayer Date: Thu, 30 Apr 2020 01:51:54 +0200 Subject: Fix typo --- client/components/lists/listBody.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/components/lists/listBody.js b/client/components/lists/listBody.js index 1bcd41c4..246e0156 100644 --- a/client/components/lists/listBody.js +++ b/client/components/lists/listBody.js @@ -672,7 +672,7 @@ BlazeComponent.extendComponent({ element.sort = Boards.findOne(this.boardId) .swimlanes() .count(); - element.type = 'swimlalne'; + element.type = 'swimlane'; _id = element.copy(this.boardId); } else if (this.isBoardTemplateSearch) { board = Boards.findOne(element.linkedId); -- cgit v1.2.3-1-g7c22