mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
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:
committed by
sharelatex
parent
6737637b39
commit
ea0270dbdd
@@ -20,6 +20,7 @@ let ProjectEntityUpdateHandler, self
|
||||
const _ = require('lodash')
|
||||
const async = require('async')
|
||||
const logger = require('logger-sharelatex')
|
||||
const Settings = require('settings-sharelatex')
|
||||
const path = require('path')
|
||||
const { Doc } = require('../../models/Doc')
|
||||
const DocstoreManager = require('../Docstore/DocstoreManager')
|
||||
@@ -39,6 +40,12 @@ const TpdsUpdateSender = require('../ThirdPartyDataStore/TpdsUpdateSender')
|
||||
|
||||
const LOCK_NAMESPACE = 'sequentialProjectStructureUpdateLock'
|
||||
|
||||
const validRootDocExtensions = Settings.validRootDocExtensions
|
||||
const validRootDocRegExp = new RegExp(
|
||||
`^\\.(${validRootDocExtensions.join('|')})$`,
|
||||
'i'
|
||||
)
|
||||
|
||||
const wrapWithLock = function(methodWithoutLock) {
|
||||
// This lock is used to make sure that the project structure updates are made
|
||||
// sequentially. In particular the updates must be made in mongo and sent to
|
||||
@@ -348,11 +355,33 @@ module.exports = ProjectEntityUpdateHandler = self = {
|
||||
callback = function(error) {}
|
||||
}
|
||||
logger.log({ project_id, rootDocId: newRootDocID }, 'setting root doc')
|
||||
return Project.update(
|
||||
{ _id: project_id },
|
||||
{ rootDoc_id: newRootDocID },
|
||||
{},
|
||||
callback
|
||||
if (project_id == null || newRootDocID == null) {
|
||||
return callback(
|
||||
new Errors.InvalidError('missing arguments (project or doc)')
|
||||
)
|
||||
}
|
||||
ProjectEntityHandler.getDocPathByProjectIdAndDocId(
|
||||
project_id,
|
||||
newRootDocID,
|
||||
function(err, docPath) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
if (ProjectEntityUpdateHandler.isPathValidForRootDoc(docPath)) {
|
||||
return Project.update(
|
||||
{ _id: project_id },
|
||||
{ rootDoc_id: newRootDocID },
|
||||
{},
|
||||
callback
|
||||
)
|
||||
} else {
|
||||
return callback(
|
||||
new Errors.UnsupportedFileTypeError(
|
||||
'invalid file extension for root doc'
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
|
||||
@@ -1401,6 +1430,11 @@ module.exports = ProjectEntityUpdateHandler = self = {
|
||||
)
|
||||
),
|
||||
|
||||
isPathValidForRootDoc(docPath) {
|
||||
let docExtension = path.extname(docPath)
|
||||
return validRootDocRegExp.test(docExtension)
|
||||
},
|
||||
|
||||
_cleanUpEntity(
|
||||
project,
|
||||
newProject,
|
||||
|
||||
Reference in New Issue
Block a user