Ensure track changes is enabled for reviewers when switching roles (#22645)

* Ensure track changes is enabled for reviewers when switching roles

* update track_changes.${userId} if track_changes is an object

GitOrigin-RevId: 3e803f4d475dbb67ff85b30095307ea58a07b2bc
This commit is contained in:
Domagoj Kriskovic
2025-01-10 09:04:51 +00:00
committed by Copybot
parent 61d300de6a
commit 2d57e347aa
2 changed files with 140 additions and 49 deletions
@@ -640,33 +640,86 @@ describe('CollaboratorsHandler', function () {
)
})
it('sets a collaborator to reviewer', async function () {
this.ProjectMock.expects('updateOne')
.withArgs(
{
_id: this.projectId,
$or: [
{ collaberator_refs: this.userId },
{ readOnly_refs: this.userId },
{ reviewer_refs: this.userId },
],
},
{
$addToSet: { reviewer_refs: this.userId },
$pull: {
readOnly_refs: this.userId,
collaberator_refs: this.userId,
pendingEditor_refs: this.userId,
describe('sets a collaborator to reviewer when track changes is enabled for everyone', function () {
beforeEach(function () {
this.ProjectGetter.promises.getProject = sinon.stub().resolves({
_id: new ObjectId(),
owner_ref: this.addingUserId,
name: 'Foo',
track_changes: true,
})
})
it('should correctly update the project', async function () {
this.ProjectMock.expects('updateOne')
.withArgs(
{
_id: this.projectId,
$or: [
{ collaberator_refs: this.userId },
{ readOnly_refs: this.userId },
{ reviewer_refs: this.userId },
],
},
}
{
$addToSet: { reviewer_refs: this.userId },
$set: { track_changes: { [this.userId]: true } },
$pull: {
readOnly_refs: this.userId,
collaberator_refs: this.userId,
pendingEditor_refs: this.userId,
},
}
)
.chain('exec')
.resolves({ matchedCount: 1 })
await this.CollaboratorsHandler.promises.setCollaboratorPrivilegeLevel(
this.projectId,
this.userId,
'review'
)
.chain('exec')
.resolves({ matchedCount: 1 })
await this.CollaboratorsHandler.promises.setCollaboratorPrivilegeLevel(
this.projectId,
this.userId,
'review'
)
})
})
describe('sets a collaborator to reviewer when track changes is not enabled for everyone', function () {
beforeEach(function () {
this.ProjectGetter.promises.getProject = sinon.stub().resolves({
_id: new ObjectId(),
owner_ref: this.addingUserId,
name: 'Foo',
track_changes: {
[this.userId]: true,
},
})
})
it('should correctly update the project', async function () {
this.ProjectMock.expects('updateOne')
.withArgs(
{
_id: this.projectId,
$or: [
{ collaberator_refs: this.userId },
{ readOnly_refs: this.userId },
{ reviewer_refs: this.userId },
],
},
{
$addToSet: { reviewer_refs: this.userId },
$set: { [`track_changes.${this.userId}`]: true },
$pull: {
readOnly_refs: this.userId,
collaberator_refs: this.userId,
pendingEditor_refs: this.userId,
},
}
)
.chain('exec')
.resolves({ matchedCount: 1 })
await this.CollaboratorsHandler.promises.setCollaboratorPrivilegeLevel(
this.projectId,
this.userId,
'review'
)
})
})
it('sets a collaborator to read-only as a pendingEditor', async function () {