소스 검색

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.
Alexander Sulfrian 8 년 전
부모
커밋
7b0e57380a
1개의 변경된 파일36개의 추가작업 그리고 0개의 파일을 삭제
  1. 36 0
      models/boards.js

+ 36 - 0
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')) {