Просмотр исходного кода

Merge pull request #24618 from overleaf/rh-null-pending-reviewer

Handle null readOnly_refs in CollaboratorsHandler

GitOrigin-RevId: b718c4a1b5216a42920909615a0f3c2fe0a16bdb
roo hutton 1 год назад
Родитель
Сommit
0c6c61b654

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

@@ -39,6 +39,12 @@ async function removeUserFromProject(projectId, userId) {
       { $set: { pendingReviewer_refs: [] } }
     ).exec()
 
+    // Temporary workaround for the case where readOnly_refs is null
+    await Project.updateOne(
+      { _id: projectId, readOnly_refs: { $type: 'null' } },
+      { $set: { readOnly_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

@@ -112,6 +112,18 @@ describe('CollaboratorsHandler', function () {
           )
           .chain('exec')
           .resolves()
+        this.ProjectMock.expects('updateOne')
+          .withArgs(
+            {
+              _id: this.project._id,
+              readOnly_refs: { $type: 'null' },
+            },
+            {
+              $set: { readOnly_refs: [] },
+            }
+          )
+          .chain('exec')
+          .resolves()
         this.ProjectMock.expects('updateOne')
           .withArgs(
             {
@@ -166,6 +178,18 @@ describe('CollaboratorsHandler', function () {
           )
           .chain('exec')
           .resolves()
+        this.ProjectMock.expects('updateOne')
+          .withArgs(
+            {
+              _id: this.oldArchivedProject._id,
+              readOnly_refs: { $type: 'null' },
+            },
+            {
+              $set: { readOnly_refs: [] },
+            }
+          )
+          .chain('exec')
+          .resolves()
         this.ProjectMock.expects('updateOne')
           .withArgs(
             {
@@ -218,6 +242,18 @@ describe('CollaboratorsHandler', function () {
           )
           .chain('exec')
           .resolves()
+        this.ProjectMock.expects('updateOne')
+          .withArgs(
+            {
+              _id: this.archivedProject._id,
+              readOnly_refs: { $type: 'null' },
+            },
+            {
+              $set: { readOnly_refs: [] },
+            }
+          )
+          .chain('exec')
+          .resolves()
         this.ProjectMock.expects('updateOne')
           .withArgs(
             {
@@ -517,6 +553,18 @@ describe('CollaboratorsHandler', function () {
           )
           .chain('exec')
           .resolves()
+        this.ProjectMock.expects('updateOne')
+          .withArgs(
+            {
+              _id: projectId,
+              readOnly_refs: { $type: 'null' },
+            },
+            {
+              $set: { readOnly_refs: [] },
+            }
+          )
+          .chain('exec')
+          .resolves()
         this.ProjectMock.expects('updateOne')
           .withArgs(
             {