mirror of
https://github.com/wekan/wekan.git
synced 2025-04-20 12:07:11 -04:00
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:
parent
ce4fcbfae4
commit
7b0e57380a
1 changed files with 36 additions and 0 deletions
|
@ -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')) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue