Merge pull request #26918 from overleaf/em-transfer-to-reviewer

Support ownership transfer to reviewer

GitOrigin-RevId: 1e97439e720a2125028a1776525f5c3766a289ef
This commit is contained in:
Eric Mc Sween
2025-07-09 08:05:31 -04:00
committed by Copybot
parent f04c194d1e
commit ef6ec25e21
2 changed files with 40 additions and 0 deletions

View File

@@ -85,6 +85,7 @@ async function _getProject(projectId) {
owner_ref: 1,
collaberator_refs: 1,
readOnly_refs: 1,
reviewer_refs: 1,
name: 1,
})
if (project == null) {
@@ -104,8 +105,13 @@ async function _getUser(userId) {
function _getUserPermissions(user, project) {
const collaboratorIds = project.collaberator_refs || []
const readOnlyIds = project.readOnly_refs || []
const reviewerIds = project.reviewer_refs || []
if (collaboratorIds.some(collaboratorId => collaboratorId.equals(user._id))) {
return PrivilegeLevels.READ_AND_WRITE
} else if (
reviewerIds.some(collaboratorId => collaboratorId.equals(user._id))
) {
return PrivilegeLevels.REVIEW
} else if (
readOnlyIds.some(collaboratorId => collaboratorId.equals(user._id))
) {

View File

@@ -19,12 +19,17 @@ describe('OwnershipTransferHandler', function () {
_id: new ObjectId(),
email: 'readonly@example.com',
}
this.reviewer = {
_id: new ObjectId(),
email: 'reviewer@example.com',
}
this.project = {
_id: new ObjectId(),
name: 'project',
owner_ref: this.user._id,
collaberator_refs: [this.collaborator._id],
readOnly_refs: [this.readOnlyCollaborator._id],
reviewer_refs: [this.reviewer._id],
}
this.ProjectGetter = {
promises: {
@@ -97,6 +102,9 @@ describe('OwnershipTransferHandler', function () {
this.UserGetter.promises.getUser
.withArgs(this.readOnlyCollaborator._id)
.resolves(this.readOnlyCollaborator)
this.UserGetter.promises.getUser
.withArgs(this.reviewer._id)
.resolves(this.reviewer)
})
it("should return a not found error if the project can't be found", async function () {
@@ -200,6 +208,32 @@ describe('OwnershipTransferHandler', function () {
)
})
it('should transfer ownership of the project to a reviewer', async function () {
await this.handler.promises.transferOwnership(
this.project._id,
this.reviewer._id
)
expect(this.ProjectModel.updateOne).to.have.been.calledWith(
{ _id: this.project._id },
sinon.match({ $set: { owner_ref: this.reviewer._id } })
)
})
it('gives old owner reviewer permissions if new owner was previously a reviewer', async function () {
await this.handler.promises.transferOwnership(
this.project._id,
this.reviewer._id
)
expect(
this.CollaboratorsHandler.promises.addUserIdToProject
).to.have.been.calledWith(
this.project._id,
this.reviewer._id,
this.user._id,
PrivilegeLevels.REVIEW
)
})
it('should flush the project to tpds', async function () {
await this.handler.promises.transferOwnership(
this.project._id,