summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxime Quandalle <maxime@quandalle.com>2016-09-02 16:17:08 +0200
committerGitHub <noreply@github.com>2016-09-02 16:17:08 +0200
commitb90d668fbc28f931bf8cdf536311ed1bf2d7d2a7 (patch)
treeac956cf03bbf2771685308513a3e62580a57bb87
parent301210c87bd50c8491844182e515c0ffd97c18f6 (diff)
parent4013184801fba254ff5e76d28a7b9293fd4ef14a (diff)
downloadwekan-b90d668fbc28f931bf8cdf536311ed1bf2d7d2a7.tar.gz
wekan-b90d668fbc28f931bf8cdf536311ed1bf2d7d2a7.tar.bz2
wekan-b90d668fbc28f931bf8cdf536311ed1bf2d7d2a7.zip
Merge pull request #669 from AlexanderS/fix/remove-user-on-leave
Fix remove user actions
-rw-r--r--models/boards.js82
1 files changed, 71 insertions, 11 deletions
diff --git a/models/boards.js b/models/boards.js
index 029ff7d1..3051ef1e 100644
--- a/models/boards.js
+++ b/models/boards.js
@@ -449,17 +449,76 @@ if (Meteor.isServer) {
);
});
+ const foreachRemovedMember = (doc, modifier, callback) => {
+ Object.keys(modifier).forEach((set) => {
+ if (modifier[set] !== false) {
+ return;
+ }
+
+ const parts = set.split('.');
+ if (parts.length === 3 && parts[0] === 'members' && parts[2] === 'isActive') {
+ callback(doc.members[parts[1]].userId);
+ }
+ });
+ };
+
+ // 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);
+
+ // Remove board from users starred list
+ if (!board.isPublic()) {
+ Users.update(
+ memberId,
+ {
+ $pull: {
+ 'profile.starredBoards': boardId,
+ },
+ }
+ );
+ }
+ });
+ }
+ });
+
// 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')) {
return;
}
- let memberId;
-
// Say hello to the new member
if (modifier.$push && modifier.$push.members) {
- memberId = modifier.$push.members.userId;
+ const memberId = modifier.$push.members.userId;
Activities.insert({
userId,
memberId,
@@ -470,14 +529,15 @@ if (Meteor.isServer) {
}
// Say goodbye to the former member
- if (modifier.$pull && modifier.$pull.members) {
- memberId = modifier.$pull.members.userId;
- Activities.insert({
- userId,
- memberId,
- type: 'member',
- activityType: 'removeBoardMember',
- boardId: doc._id,
+ if (modifier.$set) {
+ foreachRemovedMember(doc, modifier.$set, (memberId) => {
+ Activities.insert({
+ userId,
+ memberId,
+ type: 'member',
+ activityType: 'removeBoardMember',
+ boardId: doc._id,
+ });
});
}
});