From 7b0e57380aee122f19aea64e09b63670a51662fb Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Tue, 16 Aug 2016 17:29:01 +0200 Subject: 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. --- models/boards.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'models') 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')) { -- cgit v1.2.3-1-g7c22