Check for existing reviewers when adding user to a project (#26463)

GitOrigin-RevId: 935335345461133fb8b08fa95f960f801b8775a7
This commit is contained in:
Domagoj Kriskovic
2025-06-18 12:16:11 +02:00
committed by Copybot
parent 5c46588968
commit 1e286f5406
2 changed files with 35 additions and 0 deletions

View File

@@ -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())) {

View File

@@ -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 = []