mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-08 23:20:46 +00:00
Merge pull request #3562 from overleaf/em-delete-project-history
Delete expired projects in v1 history GitOrigin-RevId: ad29c02a78803a6ff1ccde7b9ec00c3f1c664a1c
This commit is contained in:
parent
ebca82fad0
commit
4a83631388
5 changed files with 76 additions and 14 deletions
|
@ -61,17 +61,34 @@ async function resyncProject(projectId) {
|
|||
url: `${settings.apis.project_history.url}/project/${projectId}/resync`
|
||||
})
|
||||
} catch (err) {
|
||||
throw new OError('failed to resync project history', { projectId })
|
||||
throw OError.tag(err, 'failed to resync project history', { projectId })
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteProject(projectId) {
|
||||
async function deleteProject(projectId, historyId) {
|
||||
try {
|
||||
await request.delete(
|
||||
`${settings.apis.project_history.url}/project/${projectId}`
|
||||
)
|
||||
const tasks = [
|
||||
request.delete(
|
||||
`${settings.apis.project_history.url}/project/${projectId}`
|
||||
)
|
||||
]
|
||||
if (historyId != null) {
|
||||
tasks.push(
|
||||
request.delete({
|
||||
url: `${settings.apis.v1_history.url}/projects/${historyId}`,
|
||||
auth: {
|
||||
user: settings.apis.v1_history.user,
|
||||
pass: settings.apis.v1_history.pass
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
await Promise.all(tasks)
|
||||
} catch (err) {
|
||||
throw new OError('failed to clear project history', { projectId })
|
||||
throw OError.tag(err, 'failed to clear project history', {
|
||||
projectId,
|
||||
historyId
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -327,9 +327,19 @@ async function expireDeletedProject(projectId) {
|
|||
return
|
||||
}
|
||||
|
||||
await DocstoreManager.promises.destroyProject(deletedProject.project._id)
|
||||
await HistoryManager.promises.deleteProject(deletedProject.project._id)
|
||||
await FilestoreHandler.promises.deleteProject(deletedProject.project._id)
|
||||
const historyId =
|
||||
deletedProject.project.overleaf &&
|
||||
deletedProject.project.overleaf.history &&
|
||||
deletedProject.project.overleaf.history.id
|
||||
|
||||
await Promise.all([
|
||||
DocstoreManager.promises.destroyProject(deletedProject.project._id),
|
||||
HistoryManager.promises.deleteProject(
|
||||
deletedProject.project._id,
|
||||
historyId
|
||||
),
|
||||
FilestoreHandler.promises.deleteProject(deletedProject.project._id)
|
||||
])
|
||||
|
||||
await DeletedProject.updateOne(
|
||||
{
|
||||
|
|
|
@ -87,6 +87,10 @@ module.exports = MockV1HistoryApi = {
|
|||
}
|
||||
)
|
||||
|
||||
app.delete('/api/projects/:project_id', (req, res, next) => {
|
||||
res.sendStatus(204)
|
||||
})
|
||||
|
||||
return app
|
||||
.listen(3100, error => {
|
||||
if (error != null) {
|
||||
|
|
|
@ -16,6 +16,9 @@ describe('HistoryManager', function() {
|
|||
delete: sinon.stub().resolves()
|
||||
}
|
||||
this.projectHistoryUrl = 'http://project_history.example.com'
|
||||
this.v1HistoryUrl = 'http://v1_history.example.com'
|
||||
this.v1HistoryUser = 'system'
|
||||
this.v1HistoryPassword = 'verysecret'
|
||||
this.settings = {
|
||||
apis: {
|
||||
trackchanges: {
|
||||
|
@ -24,6 +27,11 @@ describe('HistoryManager', function() {
|
|||
},
|
||||
project_history: {
|
||||
url: this.projectHistoryUrl
|
||||
},
|
||||
v1_history: {
|
||||
url: this.v1HistoryUrl,
|
||||
user: this.v1HistoryUser,
|
||||
pass: this.v1HistoryPassword
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -254,12 +262,27 @@ describe('HistoryManager', function() {
|
|||
})
|
||||
|
||||
describe('deleteProject', function() {
|
||||
const projectId = new ObjectId()
|
||||
const historyId = new ObjectId()
|
||||
|
||||
beforeEach(async function() {
|
||||
await this.HistoryManager.promises.deleteProject(projectId, historyId)
|
||||
})
|
||||
|
||||
it('should call the project-history service', async function() {
|
||||
const projectId = new ObjectId()
|
||||
await this.HistoryManager.promises.deleteProject(projectId)
|
||||
expect(this.request.delete).to.have.been.calledWith(
|
||||
`${this.projectHistoryUrl}/project/${projectId}`
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the v1-history service', async function() {
|
||||
expect(this.request.delete).to.have.been.calledWith({
|
||||
url: `${this.v1HistoryUrl}/projects/${historyId}`,
|
||||
auth: {
|
||||
user: this.v1HistoryUser,
|
||||
pass: this.v1HistoryPassword
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -41,7 +41,12 @@ describe('ProjectDeleter', function() {
|
|||
deletedProjectId: '5cf9270b4eff6e186cf8b05e'
|
||||
},
|
||||
project: {
|
||||
_id: '5cf9270b4eff6e186cf8b05e'
|
||||
_id: '5cf9270b4eff6e186cf8b05e',
|
||||
overleaf: {
|
||||
history: {
|
||||
id: new ObjectId()
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -461,10 +466,13 @@ describe('ProjectDeleter', function() {
|
|||
).to.have.been.calledWith(this.deletedProjects[0].project._id)
|
||||
})
|
||||
|
||||
it('should delete the project in project-history', function() {
|
||||
it('should delete the project in history', function() {
|
||||
expect(
|
||||
this.HistoryManager.promises.deleteProject
|
||||
).to.have.been.calledWith(this.deletedProjects[0].project._id)
|
||||
).to.have.been.calledWith(
|
||||
this.deletedProjects[0].project._id,
|
||||
this.deletedProjects[0].project.overleaf.history.id
|
||||
)
|
||||
})
|
||||
|
||||
it('should destroy the files in filestore', function() {
|
||||
|
|
Loading…
Add table
Reference in a new issue