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.
This commit is contained in:
Alexander Sulfrian 2016-08-16 17:29:01 +02:00
parent ce4fcbfae4
commit 7b0e57380a

View file

@ -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')) {