diff options
author | Alexander Sulfrian <alexander.sulfrian@fu-berlin.de> | 2016-08-16 17:29:01 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander.sulfrian@fu-berlin.de> | 2016-08-16 19:19:39 +0200 |
commit | 7b0e57380aee122f19aea64e09b63670a51662fb (patch) | |
tree | b06a79e4b4da56a58005303ddb5b3e49d6601659 | |
parent | ce4fcbfae4ce6dac340811d87c217dbdfae13288 (diff) | |
download | wekan-7b0e57380aee122f19aea64e09b63670a51662fb.tar.gz wekan-7b0e57380aee122f19aea64e09b63670a51662fb.tar.bz2 wekan-7b0e57380aee122f19aea64e09b63670a51662fb.zip |
Models: Remove user from all objects on board leave (Fixes: #667)
Remove the user as member and watcher of all lists, cards and the board itself
when leaving the board.
-rw-r--r-- | models/boards.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/models/boards.js b/models/boards.js index 9fef92a7..02f28b5a 100644 --- a/models/boards.js +++ b/models/boards.js @@ -462,6 +462,42 @@ if (Meteor.isServer) { }); }; + // Remove a member from all objects of the board before leaving the board + Boards.before.update((userId, doc, fieldNames, modifier) => { + if (!_.contains(fieldNames, 'members')) { + return; + } + + if (modifier.$set) { + const boardId = doc._id; + foreachRemovedMember(doc, modifier.$set, (memberId) => { + Cards.update( + { boardId }, + { + $pull: { + members: memberId, + watchers: memberId, + }, + }, + { multi: true } + ); + + Lists.update( + { boardId }, + { + $pull: { + watchers: memberId, + }, + }, + { multi: true } + ); + + const board = Boards._transform(doc); + board.setWatcher(memberId, false); + }); + } + }); + // Add a new activity if we add or remove a member to the board Boards.after.update((userId, doc, fieldNames, modifier) => { if (!_.contains(fieldNames, 'members')) { |