Browse Source

Merge pull request #24614 from overleaf/rh-pending-reviewer-pull

Set null pendingReviewer_refs to empty array in removeUserFromProject

GitOrigin-RevId: b21dd3f2febdb59dfafb45347960e375daeac463
roo hutton 1 year ago
parent
commit
c52b23af57

+ 6 - 0
services/web/app/src/Features/Collaborators/CollaboratorsHandler.js

@@ -33,6 +33,12 @@ async function removeUserFromProject(projectId, userId) {
   try {
     const project = await Project.findOne({ _id: projectId }).exec()
 
+    // Temporary workaround for the case where pendingReviewer_refs is null
+    await Project.updateOne(
+      { _id: projectId, pendingReviewer_refs: { $type: 'null' } },
+      { $set: { pendingReviewer_refs: [] } }
+    ).exec()
+
     // Deal with the old type of boolean value for archived
     // In order to clear it
     if (typeof project.archived === 'boolean') {

+ 48 - 0
services/web/test/unit/src/Collaborators/CollaboratorsHandlerTests.js

@@ -100,6 +100,18 @@ describe('CollaboratorsHandler', function () {
       })
 
       it('should remove the user from mongo', async function () {
+        this.ProjectMock.expects('updateOne')
+          .withArgs(
+            {
+              _id: this.project._id,
+              pendingReviewer_refs: { $type: 'null' },
+            },
+            {
+              $set: { pendingReviewer_refs: [] },
+            }
+          )
+          .chain('exec')
+          .resolves()
         this.ProjectMock.expects('updateOne')
           .withArgs(
             {
@@ -142,6 +154,18 @@ describe('CollaboratorsHandler', function () {
       })
 
       it('should remove the user from mongo', async function () {
+        this.ProjectMock.expects('updateOne')
+          .withArgs(
+            {
+              _id: this.oldArchivedProject._id,
+              pendingReviewer_refs: { $type: 'null' },
+            },
+            {
+              $set: { pendingReviewer_refs: [] },
+            }
+          )
+          .chain('exec')
+          .resolves()
         this.ProjectMock.expects('updateOne')
           .withArgs(
             {
@@ -182,6 +206,18 @@ describe('CollaboratorsHandler', function () {
       })
 
       it('should remove the user from mongo', async function () {
+        this.ProjectMock.expects('updateOne')
+          .withArgs(
+            {
+              _id: this.archivedProject._id,
+              pendingReviewer_refs: { $type: 'null' },
+            },
+            {
+              $set: { pendingReviewer_refs: [] },
+            }
+          )
+          .chain('exec')
+          .resolves()
         this.ProjectMock.expects('updateOne')
           .withArgs(
             {
@@ -469,6 +505,18 @@ describe('CollaboratorsHandler', function () {
           .chain('exec')
           .resolves({ _id: projectId })
 
+        this.ProjectMock.expects('updateOne')
+          .withArgs(
+            {
+              _id: projectId,
+              pendingReviewer_refs: { $type: 'null' },
+            },
+            {
+              $set: { pendingReviewer_refs: [] },
+            }
+          )
+          .chain('exec')
+          .resolves()
         this.ProjectMock.expects('updateOne')
           .withArgs(
             {