summaryrefslogtreecommitdiffstats
path: root/client/components/lists/listHeader.js
diff options
context:
space:
mode:
authorMarc Hartmayer <hello@hartmayer.com>2020-04-30 01:03:37 +0200
committerMarc Hartmayer <hello@hartmayer.com>2020-04-30 01:59:44 +0200
commitb740381a7248e1e059cecedcf6cd6824abb792b3 (patch)
tree8076a31bee3e2d84e078f78016ba7fc6247a9a75 /client/components/lists/listHeader.js
parent2691f033cbd072864cf79e95d131a93449d3c84d (diff)
downloadwekan-b740381a7248e1e059cecedcf6cd6824abb792b3.tar.gz
wekan-b740381a7248e1e059cecedcf6cd6824abb792b3.tar.bz2
wekan-b740381a7248e1e059cecedcf6cd6824abb792b3.zip
Refuse to delete a card as long as there is link to it
This fixes https://github.com/wekan/wekan/issues/2785.
Diffstat (limited to 'client/components/lists/listHeader.js')
-rw-r--r--client/components/lists/listHeader.js21
1 files changed, 19 insertions, 2 deletions
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);
}),
});