mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Revert "Revert "Revert "clear rootDoc_id when deleting doc, reset on compiles if invalid"""
This reverts commit 034ae6fa4d8515944683395ef14d99801829cb6a. GitOrigin-RevId: 16801e6f35e1ee879d36ca46e262f8bb6e506a54
This commit is contained in:
parent
b4cdfc43cf
commit
ba253bee12
5 changed files with 21 additions and 83 deletions
|
@ -62,7 +62,7 @@ module.exports = CompileManager = {
|
||||||
return callback(null, 'autocompile-backoff', [])
|
return callback(null, 'autocompile-backoff', [])
|
||||||
}
|
}
|
||||||
|
|
||||||
return ProjectRootDocManager.ensureRootDocumentIsValid(
|
return ProjectRootDocManager.ensureRootDocumentIsSet(
|
||||||
project_id,
|
project_id,
|
||||||
function(error) {
|
function(error) {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
|
|
|
@ -314,9 +314,8 @@ async function moveEntity(projectId, entityId, destFolderId, entityType) {
|
||||||
async function deleteEntity(projectId, entityId, entityType, callback) {
|
async function deleteEntity(projectId, entityId, entityType, callback) {
|
||||||
const project = await ProjectGetter.promises.getProjectWithoutLock(
|
const project = await ProjectGetter.promises.getProjectWithoutLock(
|
||||||
projectId,
|
projectId,
|
||||||
{ name: true, rootFolder: true, overleaf: true, rootDoc_id: true }
|
{ name: true, rootFolder: true, overleaf: true }
|
||||||
)
|
)
|
||||||
const deleteRootDoc = project.rootDoc_id && entityId && project.rootDoc_id.toString() === entityId.toString()
|
|
||||||
const { element: entity, path } = await ProjectLocator.promises.findElement({
|
const { element: entity, path } = await ProjectLocator.promises.findElement({
|
||||||
project,
|
project,
|
||||||
element_id: entityId,
|
element_id: entityId,
|
||||||
|
@ -326,8 +325,7 @@ async function deleteEntity(projectId, entityId, entityType, callback) {
|
||||||
Project,
|
Project,
|
||||||
projectId,
|
projectId,
|
||||||
path.mongo,
|
path.mongo,
|
||||||
entityId,
|
entityId
|
||||||
deleteRootDoc
|
|
||||||
)
|
)
|
||||||
return { entity, path, projectBeforeDeletion: project, newProject }
|
return { entity, path, projectBeforeDeletion: project, newProject }
|
||||||
}
|
}
|
||||||
|
@ -416,18 +414,19 @@ async function _insertDeletedFileReference(projectId, fileRef) {
|
||||||
).exec()
|
).exec()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function _removeElementFromMongoArray(model, modelId, path, elementId, deleteRootDoc=false) {
|
async function _removeElementFromMongoArray(model, modelId, path, elementId) {
|
||||||
const nonArrayPath = path.slice(0, path.lastIndexOf('.'))
|
const nonArrayPath = path.slice(0, path.lastIndexOf('.'))
|
||||||
const options = { new: true }
|
const newDoc = model
|
||||||
const query = { _id: modelId }
|
.findOneAndUpdate(
|
||||||
const update = {
|
{ _id: modelId },
|
||||||
$pull: { [nonArrayPath]: { _id: elementId } },
|
{
|
||||||
$inc: { version: 1 }
|
$pull: { [nonArrayPath]: { _id: elementId } },
|
||||||
}
|
$inc: { version: 1 }
|
||||||
if (deleteRootDoc) {
|
},
|
||||||
update.$unset = { rootDoc_id: 1 }
|
{ new: true }
|
||||||
}
|
)
|
||||||
return model.findOneAndUpdate(query, update, options).exec()
|
.exec()
|
||||||
|
return newDoc
|
||||||
}
|
}
|
||||||
|
|
||||||
function _countElements(project) {
|
function _countElements(project) {
|
||||||
|
|
|
@ -6,7 +6,6 @@ const fs = require('fs')
|
||||||
const Settings = require('settings-sharelatex')
|
const Settings = require('settings-sharelatex')
|
||||||
const _ = require('underscore')
|
const _ = require('underscore')
|
||||||
|
|
||||||
const { Project } = require('../../../app/src/models/Project')
|
|
||||||
const ProjectGetter = require('../../../app/src/Features/Project/ProjectGetter.js')
|
const ProjectGetter = require('../../../app/src/Features/Project/ProjectGetter.js')
|
||||||
|
|
||||||
const MockDocUpdaterApi = require('./helpers/MockDocUpdaterApi')
|
const MockDocUpdaterApi = require('./helpers/MockDocUpdaterApi')
|
||||||
|
@ -1099,68 +1098,6 @@ describe('ProjectStructureChanges', function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('deleting docs', function() {
|
|
||||||
beforeEach(function(done) {
|
|
||||||
createExampleProject(this, () => {
|
|
||||||
createExampleFolder(this, () => {
|
|
||||||
createExampleDoc(this, () => {
|
|
||||||
MockDocUpdaterApi.clearProjectStructureUpdates()
|
|
||||||
ProjectGetter.getProject(
|
|
||||||
this.exampleProjectId,
|
|
||||||
(error, project) => {
|
|
||||||
if (error) {
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
this.project0 = project
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('when rootDoc_id matches doc being deleted', () => {
|
|
||||||
beforeEach(function(done) {
|
|
||||||
Project.update({_id: this.exampleProjectId}, {$set: {rootDoc_id: this.exampleDocId}}, done)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should clear rootDoc_id', function(done) {
|
|
||||||
deleteItem(this, 'doc', this.exampleDocId, () => {
|
|
||||||
ProjectGetter.getProject(
|
|
||||||
this.exampleProjectId,
|
|
||||||
(error, project) => {
|
|
||||||
if (error) {
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
expect(project.rootDoc_id).to.be.undefined
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('when rootDoc_id does not match doc being deleted', () => {
|
|
||||||
beforeEach(function(done) {
|
|
||||||
this.exampleRootDocId = new ObjectId()
|
|
||||||
Project.update({_id: this.exampleProjectId}, {$set: {rootDoc_id: this.exampleRootDocId}}, done)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should not clear rootDoc_id', function(done) {
|
|
||||||
deleteItem(this, 'doc', this.exampleDocId, () => {
|
|
||||||
ProjectGetter.getProject(
|
|
||||||
this.exampleProjectId,
|
|
||||||
(error, project) => {
|
|
||||||
if (error) {
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
expect(project.rootDoc_id.toString()).to.equal(this.exampleRootDocId.toString())
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('tpds', function() {
|
describe('tpds', function() {
|
||||||
let projectName, exampleProjectId, oldVersion, rootFolderId
|
let projectName, exampleProjectId, oldVersion, rootFolderId
|
||||||
|
|
||||||
|
|
|
@ -120,12 +120,14 @@ describe('CompileController', function() {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should set the content-type of the response to application/json', function() {
|
it('should set the content-type of the response to application/json', function() {
|
||||||
this.res.type.should.equal('application/json')
|
return this.res.contentType
|
||||||
|
.calledWith('application/json')
|
||||||
|
.should.equal(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should send a successful response reporting the status and files', function() {
|
it('should send a successful response reporting the status and files', function() {
|
||||||
this.res.statusCode.should.equal(200)
|
this.res.statusCode.should.equal(200)
|
||||||
this.res.body.should.equal(
|
return this.res.body.should.equal(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
status: this.status,
|
status: this.status,
|
||||||
outputFiles: this.outputFiles
|
outputFiles: this.outputFiles
|
||||||
|
|
|
@ -76,7 +76,7 @@ describe('CompileManager', function() {
|
||||||
this.CompileManager._checkIfRecentlyCompiled = sinon
|
this.CompileManager._checkIfRecentlyCompiled = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.callsArgWith(2, null, false)
|
.callsArgWith(2, null, false)
|
||||||
this.ProjectRootDocManager.ensureRootDocumentIsValid = sinon
|
this.ProjectRootDocManager.ensureRootDocumentIsSet = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.callsArgWith(1, null)
|
.callsArgWith(1, null)
|
||||||
this.CompileManager.getProjectCompileLimits = sinon
|
this.CompileManager.getProjectCompileLimits = sinon
|
||||||
|
@ -115,7 +115,7 @@ describe('CompileManager', function() {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should ensure that the root document is set', function() {
|
it('should ensure that the root document is set', function() {
|
||||||
return this.ProjectRootDocManager.ensureRootDocumentIsValid
|
return this.ProjectRootDocManager.ensureRootDocumentIsSet
|
||||||
.calledWith(this.project_id)
|
.calledWith(this.project_id)
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue