diff --git a/services/web/app/src/Features/Collaborators/CollaboratorsHandler.js b/services/web/app/src/Features/Collaborators/CollaboratorsHandler.js index 53d489d8a8..ab16929bf9 100644 --- a/services/web/app/src/Features/Collaborators/CollaboratorsHandler.js +++ b/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') { diff --git a/services/web/test/unit/src/Collaborators/CollaboratorsHandlerTests.js b/services/web/test/unit/src/Collaborators/CollaboratorsHandlerTests.js index a65643a37d..7cf9adbb8e 100644 --- a/services/web/test/unit/src/Collaborators/CollaboratorsHandlerTests.js +++ b/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( {