Revert "Revert "format fix""

This reverts commit 4617b9ec2ed63b14418a8510a214e58397314831.

GitOrigin-RevId: abb3f94c50b94cd87012d9e55c40afd9cbfe97e0
This commit is contained in:
Ersun Warncke
2020-02-05 08:53:31 -04:00
committed by Copybot
parent 93bf7cc4db
commit 7e200d2aea
3 changed files with 66 additions and 44 deletions

View File

@@ -44,7 +44,10 @@ module.exports = CompileController = {
if (req.body.rootDoc_id) {
options.rootDoc_id = req.body.rootDoc_id
} else if (req.body.settingsOverride && req.body.settingsOverride.rootDoc_id) {
} else if (
req.body.settingsOverride &&
req.body.settingsOverride.rootDoc_id
) {
// Can be removed after deploy
options.rootDoc_id = req.body.settingsOverride.rootDoc_id
}
@@ -54,35 +57,38 @@ module.exports = CompileController = {
if (req.body.draft) {
options.draft = req.body.draft
}
if (
['validate', 'error', 'silent'].includes(req.body.check)
) {
if (['validate', 'error', 'silent'].includes(req.body.check)) {
options.check = req.body.check
}
if (req.body.incrementalCompilesEnabled) {
options.incrementalCompilesEnabled = true
}
CompileManager.compile(project_id, user_id, options, (
error,
status,
outputFiles,
clsiServerId,
limits,
validationProblems
) => {
if (error) {
return next(error)
}
res.json({
CompileManager.compile(
project_id,
user_id,
options,
(
error,
status,
outputFiles,
compileGroup: limits != null ? limits.compileGroup : undefined,
clsiServerId,
validationProblems,
pdfDownloadDomain: Settings.pdfDownloadDomain
})
})
limits,
validationProblems
) => {
if (error) {
return next(error)
}
res.json({
status,
outputFiles,
compileGroup: limits != null ? limits.compileGroup : undefined,
clsiServerId,
validationProblems,
pdfDownloadDomain: Settings.pdfDownloadDomain
})
}
)
},
stopCompile(req, res, next) {

View File

@@ -316,7 +316,10 @@ async function deleteEntity(projectId, entityId, entityType, callback) {
projectId,
{ name: true, rootFolder: true, overleaf: true, rootDoc_id: true }
)
const deleteRootDoc = project.rootDoc_id && entityId && project.rootDoc_id.toString() === entityId.toString()
const deleteRootDoc =
project.rootDoc_id &&
entityId &&
project.rootDoc_id.toString() === entityId.toString()
const { element: entity, path } = await ProjectLocator.promises.findElement({
project,
element_id: entityId,
@@ -416,7 +419,13 @@ async function _insertDeletedFileReference(projectId, fileRef) {
).exec()
}
async function _removeElementFromMongoArray(model, modelId, path, elementId, deleteRootDoc=false) {
async function _removeElementFromMongoArray(
model,
modelId,
path,
elementId,
deleteRootDoc = false
) {
const nonArrayPath = path.slice(0, path.lastIndexOf('.'))
const options = { new: true }
const query = { _id: modelId }

View File

@@ -1113,48 +1113,55 @@ describe('ProjectStructureChanges', function() {
}
this.project0 = project
done()
})
}
)
})
})
})
})
describe('when rootDoc_id matches doc being deleted', () => {
describe('when rootDoc_id matches doc being deleted', function() {
beforeEach(function(done) {
Project.update({_id: this.exampleProjectId}, {$set: {rootDoc_id: this.exampleDocId}}, 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()
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', () => {
describe('when rootDoc_id does not match doc being deleted', function() {
beforeEach(function(done) {
this.exampleRootDocId = new ObjectId()
Project.update({_id: this.exampleProjectId}, {$set: {rootDoc_id: this.exampleRootDocId}}, done)
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()
ProjectGetter.getProject(this.exampleProjectId, (error, project) => {
if (error) {
throw error
}
expect(project.rootDoc_id.toString()).to.equal(
this.exampleRootDocId.toString()
)
done()
})
})
})