Merge pull request #2168 from overleaf/pr-restrict-main-file-options

Restrict main file options based on extension.

GitOrigin-RevId: f7d7a61c0454621dd8bc6ab5edce8a89721018ea
This commit is contained in:
Jessica Lawshe
2019-10-03 09:10:00 -05:00
committed by sharelatex
parent 6737637b39
commit ea0270dbdd
13 changed files with 253 additions and 65 deletions
@@ -278,6 +278,51 @@ const ProjectEntityHandler = {
return DocstoreManager.getDoc(project_id, doc_id, options, callback)
},
getDocPathByProjectIdAndDocId(project_id, doc_id, callback) {
logger.log({ project_id, doc_id }, 'getting path for doc and project')
return ProjectGetter.getProjectWithoutDocLines(project_id, function(
err,
project
) {
if (err != null) {
return callback(err)
}
if (project == null) {
return callback(new Errors.NotFoundError('no project'))
}
function recursivelyFindDocInFolder(basePath, doc_id, folder) {
let docInCurrentFolder = Array.from(folder.docs || []).find(
currentDoc => currentDoc._id.toString() === doc_id.toString()
)
if (docInCurrentFolder != null) {
return path.join(basePath, docInCurrentFolder.name)
} else {
let docPath, childFolder
for (childFolder of Array.from(folder.folders || [])) {
docPath = recursivelyFindDocInFolder(
path.join(basePath, childFolder.name),
doc_id,
childFolder
)
if (docPath != null) {
return docPath
}
}
return null
}
}
const docPath = recursivelyFindDocInFolder(
'/',
doc_id,
project.rootFolder[0]
)
if (docPath == null) {
return callback(new Errors.NotFoundError('no doc'))
}
return callback(null, docPath)
})
},
_getAllFolders(project_id, callback) {
logger.log({ project_id }, 'getting all folders for project')
return ProjectGetter.getProjectWithoutDocLines(project_id, function(