diff --git a/services/web/app/src/Features/Project/ProjectDeleter.js b/services/web/app/src/Features/Project/ProjectDeleter.js index 9e90852b7a..3f84c37289 100644 --- a/services/web/app/src/Features/Project/ProjectDeleter.js +++ b/services/web/app/src/Features/Project/ProjectDeleter.js @@ -180,6 +180,13 @@ async function deleteProject(project_id, options = {}) { deletedProjectReadOnlyIds: project.readOnly_refs, deletedProjectReadWriteTokenAccessIds: project.tokenAccessReadAndWrite_refs, + deletedProjectOverleafId: project.overleaf + ? project.overleaf.id + : undefined, + deletedProjectOverleafHistoryId: + project.overleaf && project.overleaf.history + ? project.overleaf.history.id + : undefined, deletedProjectReadOnlyTokenAccessIds: project.tokenAccessReadOnly_refs, deletedProjectReadWriteToken: project.tokens.readAndWrite, deletedProjectReadOnlyToken: project.tokens.readOnly, diff --git a/services/web/app/src/models/DeletedProject.js b/services/web/app/src/models/DeletedProject.js index ebb37a46ce..f961c69ebf 100644 --- a/services/web/app/src/models/DeletedProject.js +++ b/services/web/app/src/models/DeletedProject.js @@ -19,7 +19,9 @@ const DeleterDataSchema = new Schema({ deletedProjectReadOnlyTokenAccessIds: [{ type: ObjectId, ref: 'User' }], deletedProjectReadWriteToken: { type: String }, deletedProjectReadOnlyToken: { type: String }, - deletedProjectLastUpdatedAt: { type: Date } + deletedProjectLastUpdatedAt: { type: Date }, + deletedProjectOverleafId: { type: Number }, + deletedProjectOverleafHistoryId: { type: Number } }) const DeletedProjectSchema = new Schema( diff --git a/services/web/scripts/backfill_deleted_project_ids.js b/services/web/scripts/backfill_deleted_project_ids.js index b9f5fbb1c4..c36cf8a404 100644 --- a/services/web/scripts/backfill_deleted_project_ids.js +++ b/services/web/scripts/backfill_deleted_project_ids.js @@ -1,54 +1,57 @@ const { DeletedProject } = require('../app/src/models/DeletedProject') const Async = require('async') -DeletedProject.find( - {}, - { 'project._id': 1, 'project.owner_ref': 1 }, - (error, deletedProjects) => { - if (error) { - throw error - } - - Async.eachLimit( - deletedProjects, - 10, - (deletedProject, cb) => { - if (deletedProject.project) { - const src = deletedProject.project - DeletedProject.findOneAndUpdate( - { _id: deletedProject._id }, - { - $set: { - 'deleterData.deletedProjectId': src._id, - 'deleterData.deletedProjectOwnerId': src.owner_ref, - 'deleterData.deletedProjectCollaboratorIds': - src.collaberator_refs, - 'deleterData.deletedProjectReadOnlyIds': src.readOnly_refs, - 'deleterData.deletedProjectReadWriteToken': src.tokens - ? src.tokens.readAndWrite - : undefined, - 'deleterData.deletedProjectReadOnlyToken': src.tokens - ? src.tokens.readOnly - : undefined, - 'deleterData.deletedProjectReadWriteTokenAccessIds': - src.tokenAccessReadOnly_refs, - 'deleterData.deletedProjectReadOnlyTokenAccessIds': - src.tokenAccessReadAndWrite_refs, - 'deleterData.deletedProjectLastUpdatedAt': src.lastUpdated - } - }, - cb - ) - } else { - cb() - } - }, - err => { - if (err) { - throw err - } - process.exit(0) - } - ) +DeletedProject.find({}, (error, deletedProjects) => { + if (error) { + throw error } -) + + Async.eachLimit( + deletedProjects, + 10, + (deletedProject, cb) => { + if (deletedProject.project) { + const src = deletedProject.project + DeletedProject.findOneAndUpdate( + { _id: deletedProject._id }, + { + $set: { + 'deleterData.deletedProjectId': src._id, + 'deleterData.deletedProjectOwnerId': src.owner_ref, + 'deleterData.deletedProjectCollaboratorIds': + src.collaberator_refs, + 'deleterData.deletedProjectReadOnlyIds': src.readOnly_refs, + 'deleterData.deletedProjectReadWriteToken': src.tokens + ? src.tokens.readAndWrite + : undefined, + 'deleterData.deletedProjectOverleafId': src.overleaf + ? src.overleaf.id + : undefined, + 'deleterData.deletedProjectOverleafHistoryId': + src.overleaf && src.overleaf.history + ? src.overleaf.history.id + : undefined, + 'deleterData.deletedProjectReadOnlyToken': src.tokens + ? src.tokens.readOnly + : undefined, + 'deleterData.deletedProjectReadWriteTokenAccessIds': + src.tokenAccessReadOnly_refs, + 'deleterData.deletedProjectReadOnlyTokenAccessIds': + src.tokenAccessReadAndWrite_refs, + 'deleterData.deletedProjectLastUpdatedAt': src.lastUpdated + } + }, + cb + ) + } else { + cb() + } + }, + err => { + if (err) { + throw err + } + process.exit(0) + } + ) +}) diff --git a/services/web/test/unit/src/Project/ProjectDeleterTests.js b/services/web/test/unit/src/Project/ProjectDeleterTests.js index 030082478e..f7dab8324e 100644 --- a/services/web/test/unit/src/Project/ProjectDeleterTests.js +++ b/services/web/test/unit/src/Project/ProjectDeleterTests.js @@ -27,6 +27,12 @@ describe('ProjectDeleter', () => { readOnly: 'wombat', readAndWrite: 'potato' }, + overleaf: { + id: 1234, + history: { + id: 5678 + } + }, name: 'a very scientific analysis of spooky ghosts' } @@ -238,6 +244,8 @@ describe('ProjectDeleter', () => { .tokenAccessReadOnly_refs, deletedProjectReadWriteToken: this.project.tokens.readAndWrite, deletedProjectReadOnlyToken: this.project.tokens.readOnly, + deletedProjectOverleafId: this.project.overleaf.id, + deletedProjectOverleafHistoryId: this.project.overleaf.history.id, deletedProjectLastUpdatedAt: this.project.lastUpdated }