Merge pull request #2014 from overleaf/spd-deleted-project-collab-ids

Store and backfill collaborator and overleaf history IDs in deleted projects

GitOrigin-RevId: 34950e29d6910c22f1f6f153f8035a96a1ea8360
This commit is contained in:
Simon Detheridge 2019-07-26 15:26:25 +01:00 committed by sharelatex
parent 285edfff36
commit d7bee9a7d8
4 changed files with 71 additions and 51 deletions

View file

@ -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,

View file

@ -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(

View file

@ -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)
}
)
})

View file

@ -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
}