Browse Source

Merge pull request #2502 from overleaf/sk-fix-mongoose-push-all

Tell mongoose to set `usePushEach` on all models

GitOrigin-RevId: faea6653f272f74ea7274596bdc934ef93638d76
Shane Kilkelly 6 years ago
parent
commit
2826832c5e

+ 16 - 2
services/web/app/src/Features/Collaborators/CollaboratorsHandler.js

@@ -126,18 +126,32 @@ async function transferProjects(fromUserId, toUserId) {
     { $set: { owner_ref: toUserId } },
     { multi: true }
   ).exec()
+
+  await Project.update(
+    { collaberator_refs: fromUserId },
+    {
+      $addToSet: { collaberator_refs: toUserId }
+    },
+    { multi: true }
+  ).exec()
   await Project.update(
     { collaberator_refs: fromUserId },
     {
-      $addToSet: { collaberator_refs: toUserId },
       $pull: { collaberator_refs: fromUserId }
     },
     { multi: true }
   ).exec()
+
+  await Project.update(
+    { readOnly_refs: fromUserId },
+    {
+      $addToSet: { readOnly_refs: toUserId }
+    },
+    { multi: true }
+  ).exec()
   await Project.update(
     { readOnly_refs: fromUserId },
     {
-      $addToSet: { readOnly_refs: toUserId },
       $pull: { readOnly_refs: fromUserId }
     },
     { multi: true }

+ 4 - 0
services/web/app/src/infrastructure/Mongoose.js

@@ -38,4 +38,8 @@ if (process.env.MONGOOSE_DEBUG) {
   )
 }
 
+mongoose.plugin(schema => {
+  schema.options.usePushEach = true
+})
+
 module.exports = mongoose

+ 1 - 1
services/web/docker-compose.ci.yml

@@ -54,4 +54,4 @@ services:
     image: redis
 
   mongo:
-    image: mongo:3.4.6
+    image: mongo:3.6.16

+ 1 - 1
services/web/docker-compose.yml

@@ -49,4 +49,4 @@ services:
     image: redis
 
   mongo:
-    image: mongo:3.4.6
+    image: mongo:3.6.16

+ 20 - 2
services/web/test/unit/src/Collaborators/CollaboratorsHandlerTests.js

@@ -297,7 +297,16 @@ describe('CollaboratorsHandler', function() {
         .withArgs(
           { collaberator_refs: this.fromUserId },
           {
-            $addToSet: { collaberator_refs: this.toUserId },
+            $addToSet: { collaberator_refs: this.toUserId }
+          },
+          { multi: true }
+        )
+        .chain('exec')
+        .resolves()
+      this.ProjectMock.expects('update')
+        .withArgs(
+          { collaberator_refs: this.fromUserId },
+          {
             $pull: { collaberator_refs: this.fromUserId }
           },
           { multi: true }
@@ -308,7 +317,16 @@ describe('CollaboratorsHandler', function() {
         .withArgs(
           { readOnly_refs: this.fromUserId },
           {
-            $addToSet: { readOnly_refs: this.toUserId },
+            $addToSet: { readOnly_refs: this.toUserId }
+          },
+          { multi: true }
+        )
+        .chain('exec')
+        .resolves()
+      this.ProjectMock.expects('update')
+        .withArgs(
+          { readOnly_refs: this.fromUserId },
+          {
             $pull: { readOnly_refs: this.fromUserId }
           },
           { multi: true }