diff options
author | Angelo Gallarello <angelo.gallarell@gmail.com> | 2018-08-16 16:54:29 +0200 |
---|---|---|
committer | Angelo Gallarello <angelo.gallarell@gmail.com> | 2018-08-16 16:54:29 +0200 |
commit | 9c6d374b950e8c4bd0c1c905cf36c953581a3156 (patch) | |
tree | ff2667017f5a30931bbef6807dfbff08ac5b2513 /models/cards.js | |
parent | 99e7c659072943b80b08564465ee8cb5c90d3905 (diff) | |
download | wekan-9c6d374b950e8c4bd0c1c905cf36c953581a3156.tar.gz wekan-9c6d374b950e8c4bd0c1c905cf36c953581a3156.tar.bz2 wekan-9c6d374b950e8c4bd0c1c905cf36c953581a3156.zip |
Labels activities
Diffstat (limited to 'models/cards.js')
-rw-r--r-- | models/cards.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/models/cards.js b/models/cards.js index 618c191e..364f5a39 100644 --- a/models/cards.js +++ b/models/cards.js @@ -624,6 +624,41 @@ function cardMembers(userId, doc, fieldNames, modifier) { } } +function cardLabels(userId, doc, fieldNames, modifier) { + if (!_.contains(fieldNames, 'labelIds')) + return; + let labelId; + // Say hello to the new label + if (modifier.$addToSet && modifier.$addToSet.labelIds) { + labelId = modifier.$addToSet.labelIds; + if (!_.contains(doc.labelIds, labelId)) { + const act = { + userId, + labelId, + activityType: 'addedLabel', + boardId: doc.boardId, + cardId: doc._id, + } + Activities.insert(act); + } + } + + // Say goodbye to the label + if (modifier.$pull && modifier.$pull.labelIds) { + labelId = modifier.$pull.labelIds; + // Check that the former member is member of the card + if (_.contains(doc.labelIds, labelId)) { + Activities.insert({ + userId, + labelId, + activityType: 'removedLabel', + boardId: doc.boardId, + cardId: doc._id, + }); + } + } +} + function cardCreation(userId, doc) { Activities.insert({ userId, @@ -680,6 +715,12 @@ if (Meteor.isServer) { cardMembers(userId, doc, fieldNames, modifier); }); + // Add a new activity if we add or remove a label to the card + Cards.before.update((userId, doc, fieldNames, modifier) => { + cardLabels(userId, doc, fieldNames, modifier); + }); + + // Remove all activities associated with a card if we remove the card // Remove also card_comments / checklists / attachments Cards.after.remove((userId, doc) => { |