From 1e286f5406f4f91b6cf6ba28e5c8536f28d232e8 Mon Sep 17 00:00:00 2001 From: Domagoj Kriskovic Date: Wed, 18 Jun 2025 12:16:11 +0200 Subject: [PATCH] Check for existing reviewers when adding user to a project (#26463) GitOrigin-RevId: 935335345461133fb8b08fa95f960f801b8775a7 --- .../Collaborators/CollaboratorsHandler.js | 1 + .../CollaboratorsHandlerTests.js | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/services/web/app/src/Features/Collaborators/CollaboratorsHandler.js b/services/web/app/src/Features/Collaborators/CollaboratorsHandler.js index 96b4cd6e37..8b5b1bc3c2 100644 --- a/services/web/app/src/Features/Collaborators/CollaboratorsHandler.js +++ b/services/web/app/src/Features/Collaborators/CollaboratorsHandler.js @@ -161,6 +161,7 @@ async function addUserIdToProject( }) let level let existingUsers = project.collaberator_refs || [] + existingUsers = existingUsers.concat(project.reviewer_refs || []) existingUsers = existingUsers.concat(project.readOnly_refs || []) existingUsers = existingUsers.map(u => u.toString()) if (existingUsers.includes(userId.toString())) { diff --git a/services/web/test/unit/src/Collaborators/CollaboratorsHandlerTests.js b/services/web/test/unit/src/Collaborators/CollaboratorsHandlerTests.js index 8542bd8355..73fb699772 100644 --- a/services/web/test/unit/src/Collaborators/CollaboratorsHandlerTests.js +++ b/services/web/test/unit/src/Collaborators/CollaboratorsHandlerTests.js @@ -447,6 +447,40 @@ describe('CollaboratorsHandler', function () { }) }) + describe('when user already exists as a reviewer', function () { + beforeEach(function () { + this.project.collaberator_refs = [] + this.project.reviewer_refs = [this.userId] + this.project.readOnly_refs = [] + }) + + it('should not add the user again', async function () { + await this.CollaboratorsHandler.promises.addUserIdToProject( + this.project._id, + this.addingUserId, + this.userId, + 'readAndWrite' + ) + }) + }) + + describe('when user already exists as a read-only user', function () { + beforeEach(function () { + this.project.collaberator_refs = [] + this.project.reviewer_refs = [] + this.project.readOnly_refs = [this.userId] + }) + + it('should not add the user again', async function () { + await this.CollaboratorsHandler.promises.addUserIdToProject( + this.project._id, + this.addingUserId, + this.userId, + 'readAndWrite' + ) + }) + }) + describe('with null addingUserId', function () { beforeEach(async function () { this.project.collaberator_refs = []