List projects where user is added as reviewer (#22347)

* Support for adding reviewer role

* added collaboratorsGetter tests

* emit toggle-track-changes when reviewer is added

* List projects where user is added as reviewer

GitOrigin-RevId: 8ec9e59e4c0b65167705b0a56be3e309ef6af3e7
This commit is contained in:
Domagoj Kriskovic
2024-12-10 11:52:49 +01:00
committed by Copybot
parent 53dc5fbafe
commit db9dba4b7a
7 changed files with 54 additions and 8 deletions

View File

@@ -224,9 +224,10 @@ async function getPublicShareTokens(userId, projectId) {
// token access has been disabled.
async function getProjectsUserIsMemberOf(userId, fields) {
const limit = pLimit(2)
const [readAndWrite, readOnly, tokenReadAndWrite, tokenReadOnly] =
const [readAndWrite, review, readOnly, tokenReadAndWrite, tokenReadOnly] =
await Promise.all([
limit(() => Project.find({ collaberator_refs: userId }, fields).exec()),
limit(() => Project.find({ reviewer_refs: userId }, fields).exec()),
limit(() => Project.find({ readOnly_refs: userId }, fields).exec()),
limit(() =>
Project.find(
@@ -247,7 +248,7 @@ async function getProjectsUserIsMemberOf(userId, fields) {
).exec()
),
])
return { readAndWrite, readOnly, tokenReadAndWrite, tokenReadOnly }
return { readAndWrite, review, readOnly, tokenReadAndWrite, tokenReadOnly }
}
// This function returns all the projects that a user is a member of, regardless of

View File

@@ -904,8 +904,14 @@ const _ProjectController = {
},
_buildProjectList(allProjects, userId) {
let project
const { owned, readAndWrite, readOnly, tokenReadAndWrite, tokenReadOnly } =
allProjects
const {
owned,
review,
readAndWrite,
readOnly,
tokenReadAndWrite,
tokenReadOnly,
} = allProjects
const projects = []
for (project of owned) {
projects.push(
@@ -928,6 +934,16 @@ const _ProjectController = {
)
)
}
for (project of review) {
projects.push(
ProjectController._buildProjectViewModel(
project,
'review',
Sources.INVITE,
userId
)
)
}
for (project of readOnly) {
projects.push(
ProjectController._buildProjectViewModel(

View File

@@ -102,6 +102,7 @@ const ProjectGetter = {
readOnly: projects.readOnly || [],
tokenReadAndWrite: projects.tokenReadAndWrite || [],
tokenReadOnly: projects.tokenReadOnly || [],
review: projects.review || [],
}
// Remove duplicate projects. The order of result values is determined by the order they occur.

View File

@@ -540,8 +540,14 @@ async function _getProjects(
* @private
*/
function _formatProjects(projects, userId) {
const { owned, readAndWrite, readOnly, tokenReadAndWrite, tokenReadOnly } =
projects
const {
owned,
review,
readAndWrite,
readOnly,
tokenReadAndWrite,
tokenReadOnly,
} = projects
const formattedProjects = /** @type {Project[]} **/ []
for (const project of owned) {
@@ -555,6 +561,11 @@ function _formatProjects(projects, userId) {
_formatProjectInfo(project, 'readWrite', Sources.INVITE, userId)
)
}
for (const project of review) {
formattedProjects.push(
_formatProjectInfo(project, 'review', Sources.INVITE, userId)
)
}
for (const project of readOnly) {
formattedProjects.push(
_formatProjectInfo(project, 'readOnly', Sources.INVITE, userId)

View File

@@ -319,6 +319,11 @@ describe('CollaboratorsGetter', function () {
.withArgs({ readOnly_refs: this.userId }, this.fields)
.chain('exec')
.resolves(['mock-read-only-project-1', 'mock-read-only-project-2'])
this.ProjectMock.expects('find')
.withArgs({ reviewer_refs: this.userId }, this.fields)
.chain('exec')
.resolves(['mock-review-project-1', 'mock-review-project-2'])
this.ProjectMock.expects('find')
.withArgs(
{
@@ -367,6 +372,7 @@ describe('CollaboratorsGetter', function () {
'mock-token-read-only-project-1',
'mock-token-read-only-project-2',
],
review: ['mock-review-project-1', 'mock-review-project-2'],
})
})
})

View File

@@ -275,6 +275,7 @@ describe('ProjectGetter', function () {
this.fields = { mock: 'fields' }
this.projectOwned = { _id: 'mock-owned-projects' }
this.projectRW = { _id: 'mock-rw-projects' }
this.projectReview = { _id: 'mock-review-projects' }
this.projectRO = { _id: 'mock-ro-projects' }
this.projectTokenRW = { _id: 'mock-token-rw-projects' }
this.projectTokenRO = { _id: 'mock-token-ro-projects' }
@@ -289,6 +290,7 @@ describe('ProjectGetter', function () {
readOnly: [this.projectRO],
tokenReadAndWrite: [this.projectTokenRW],
tokenReadOnly: [this.projectTokenRO],
review: [this.projectReview],
})
const projects = await this.ProjectGetter.promises.findAllUsersProjects(
this.userId,
@@ -301,6 +303,7 @@ describe('ProjectGetter', function () {
readOnly: [this.projectRO],
tokenReadAndWrite: [this.projectTokenRW],
tokenReadOnly: [this.projectTokenRO],
review: [this.projectReview],
})
})
@@ -314,6 +317,7 @@ describe('ProjectGetter', function () {
this.projectTokenRO,
this.projectRO,
],
review: [this.projectReview],
})
const projects = await this.ProjectGetter.promises.findAllUsersProjects(
this.userId,
@@ -326,6 +330,7 @@ describe('ProjectGetter', function () {
readOnly: [this.projectRO],
tokenReadAndWrite: [this.projectTokenRW],
tokenReadOnly: [this.projectTokenRO],
review: [this.projectReview],
})
})
})

View File

@@ -219,12 +219,14 @@ describe('ProjectListController', function () {
this.readOnly = [{ _id: 3, lastUpdated: 3, owner_ref: 'user-1' }]
this.tokenReadAndWrite = [{ _id: 6, lastUpdated: 5, owner_ref: 'user-4' }]
this.tokenReadOnly = [{ _id: 7, lastUpdated: 4, owner_ref: 'user-5' }]
this.review = [{ _id: 8, lastUpdated: 4, owner_ref: 'user-6' }]
this.allProjects = {
owned: this.projects,
readAndWrite: this.readAndWrite,
readOnly: this.readOnly,
tokenReadAndWrite: this.tokenReadAndWrite,
tokenReadOnly: this.tokenReadOnly,
review: this.review,
}
this.ProjectGetter.promises.findAllUsersProjects.resolves(
@@ -279,7 +281,8 @@ describe('ProjectListController', function () {
this.readAndWrite.length +
this.readOnly.length +
this.tokenReadAndWrite.length +
this.tokenReadOnly.length
this.tokenReadOnly.length +
this.review.length
)
done()
}
@@ -719,12 +722,14 @@ describe('ProjectListController', function () {
{ _id: 6, lastUpdated: 5, owner_ref: 'user-4' }, // Also in tokenReadAndWrite
{ _id: 7, lastUpdated: 4, owner_ref: 'user-5' },
]
this.review = [{ _id: 8, lastUpdated: 5, owner_ref: 'user-6' }]
this.allProjects = {
owned: this.projects,
readAndWrite: this.readAndWrite,
readOnly: this.readOnly,
tokenReadAndWrite: this.tokenReadAndWrite,
tokenReadOnly: this.tokenReadOnly,
review: this.review,
}
this.ProjectGetter.promises.findAllUsersProjects.resolves(
@@ -747,7 +752,8 @@ describe('ProjectListController', function () {
this.readAndWrite.length +
this.readOnly.length +
this.tokenReadAndWrite.length +
this.tokenReadOnly.length -
this.tokenReadOnly.length +
this.review.length -
1
)
done()