From 8ed501380962bb8201cd1d73ff6e6d4b888ca018 Mon Sep 17 00:00:00 2001 From: roo hutton Date: Mon, 31 Mar 2025 14:16:48 +0100 Subject: [PATCH] Merge pull request #24614 from overleaf/rh-pending-reviewer-pull Set null pendingReviewer_refs to empty array in removeUserFromProject GitOrigin-RevId: b21dd3f2febdb59dfafb45347960e375daeac463 --- .../Collaborators/CollaboratorsHandler.js | 6 +++ .../CollaboratorsHandlerTests.js | 48 +++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/services/web/app/src/Features/Collaborators/CollaboratorsHandler.js b/services/web/app/src/Features/Collaborators/CollaboratorsHandler.js index 752a87a580..53d489d8a8 100644 --- a/services/web/app/src/Features/Collaborators/CollaboratorsHandler.js +++ b/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') { diff --git a/services/web/test/unit/src/Collaborators/CollaboratorsHandlerTests.js b/services/web/test/unit/src/Collaborators/CollaboratorsHandlerTests.js index 734c474f86..a65643a37d 100644 --- a/services/web/test/unit/src/Collaborators/CollaboratorsHandlerTests.js +++ b/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( {