Merge pull request #24614 from overleaf/rh-pending-reviewer-pull

Set null pendingReviewer_refs to empty array in removeUserFromProject

GitOrigin-RevId: b21dd3f2febdb59dfafb45347960e375daeac463
This commit is contained in:
roo hutton
2025-03-31 14:16:48 +01:00
committed by Copybot
parent 5b6c53c0bd
commit 8ed5013809
2 changed files with 54 additions and 0 deletions

View File

@@ -33,6 +33,12 @@ async function removeUserFromProject(projectId, userId) {
try {
const project = await Project.findOne({ _id: projectId }).exec()
// Temporary workaround for the case where pendingReviewer_refs is null
await Project.updateOne(
{ _id: projectId, pendingReviewer_refs: { $type: 'null' } },
{ $set: { pendingReviewer_refs: [] } }
).exec()
// Deal with the old type of boolean value for archived
// In order to clear it
if (typeof project.archived === 'boolean') {

View File

@@ -100,6 +100,18 @@ describe('CollaboratorsHandler', function () {
})
it('should remove the user from mongo', async function () {
this.ProjectMock.expects('updateOne')
.withArgs(
{
_id: this.project._id,
pendingReviewer_refs: { $type: 'null' },
},
{
$set: { pendingReviewer_refs: [] },
}
)
.chain('exec')
.resolves()
this.ProjectMock.expects('updateOne')
.withArgs(
{
@@ -142,6 +154,18 @@ describe('CollaboratorsHandler', function () {
})
it('should remove the user from mongo', async function () {
this.ProjectMock.expects('updateOne')
.withArgs(
{
_id: this.oldArchivedProject._id,
pendingReviewer_refs: { $type: 'null' },
},
{
$set: { pendingReviewer_refs: [] },
}
)
.chain('exec')
.resolves()
this.ProjectMock.expects('updateOne')
.withArgs(
{
@@ -182,6 +206,18 @@ describe('CollaboratorsHandler', function () {
})
it('should remove the user from mongo', async function () {
this.ProjectMock.expects('updateOne')
.withArgs(
{
_id: this.archivedProject._id,
pendingReviewer_refs: { $type: 'null' },
},
{
$set: { pendingReviewer_refs: [] },
}
)
.chain('exec')
.resolves()
this.ProjectMock.expects('updateOne')
.withArgs(
{
@@ -469,6 +505,18 @@ describe('CollaboratorsHandler', function () {
.chain('exec')
.resolves({ _id: projectId })
this.ProjectMock.expects('updateOne')
.withArgs(
{
_id: projectId,
pendingReviewer_refs: { $type: 'null' },
},
{
$set: { pendingReviewer_refs: [] },
}
)
.chain('exec')
.resolves()
this.ProjectMock.expects('updateOne')
.withArgs(
{