From 2826832c5e1aefbe10e826573c4153af9d4011a3 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Wed, 8 Jan 2020 13:40:07 +0000 Subject: [PATCH] Merge pull request #2502 from overleaf/sk-fix-mongoose-push-all Tell mongoose to set `usePushEach` on all models GitOrigin-RevId: faea6653f272f74ea7274596bdc934ef93638d76 --- .../Collaborators/CollaboratorsHandler.js | 18 +++++++++++++-- .../web/app/src/infrastructure/Mongoose.js | 4 ++++ services/web/docker-compose.ci.yml | 2 +- services/web/docker-compose.yml | 2 +- .../CollaboratorsHandlerTests.js | 22 +++++++++++++++++-- 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/services/web/app/src/Features/Collaborators/CollaboratorsHandler.js b/services/web/app/src/Features/Collaborators/CollaboratorsHandler.js index 219b30a946..e4198bb653 100644 --- a/services/web/app/src/Features/Collaborators/CollaboratorsHandler.js +++ b/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 } diff --git a/services/web/app/src/infrastructure/Mongoose.js b/services/web/app/src/infrastructure/Mongoose.js index 734bb98346..4f49ad6576 100644 --- a/services/web/app/src/infrastructure/Mongoose.js +++ b/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 diff --git a/services/web/docker-compose.ci.yml b/services/web/docker-compose.ci.yml index 5b69444211..9c2f8f70b2 100644 --- a/services/web/docker-compose.ci.yml +++ b/services/web/docker-compose.ci.yml @@ -54,4 +54,4 @@ services: image: redis mongo: - image: mongo:3.4.6 + image: mongo:3.6.16 diff --git a/services/web/docker-compose.yml b/services/web/docker-compose.yml index 4ff69de673..eedb5b362b 100644 --- a/services/web/docker-compose.yml +++ b/services/web/docker-compose.yml @@ -49,4 +49,4 @@ services: image: redis mongo: - image: mongo:3.4.6 + image: mongo:3.6.16 diff --git a/services/web/test/unit/src/Collaborators/CollaboratorsHandlerTests.js b/services/web/test/unit/src/Collaborators/CollaboratorsHandlerTests.js index 9839416ebe..c869de8bf4 100644 --- a/services/web/test/unit/src/Collaborators/CollaboratorsHandlerTests.js +++ b/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 }