mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
add in the calls to block large projects
This commit is contained in:
parent
8aec86af4e
commit
8f0d1dc73e
9 changed files with 56 additions and 30 deletions
|
@ -70,8 +70,12 @@ module.exports = EditorHttpController =
|
|||
if !EditorHttpController._nameIsAcceptableLength(name)
|
||||
return res.sendStatus 400
|
||||
EditorController.addDoc project_id, parent_folder_id, name, [], "editor", (error, doc) ->
|
||||
return next(error) if error?
|
||||
res.json doc
|
||||
if error == "project_has_to_many_files"
|
||||
res.status(400).json(req.i18n.translate("project_has_to_many_files"))
|
||||
else if error?
|
||||
next(error)
|
||||
else
|
||||
res.json doc
|
||||
|
||||
addFolder: (req, res, next) ->
|
||||
project_id = req.params.Project_id
|
||||
|
@ -80,8 +84,12 @@ module.exports = EditorHttpController =
|
|||
if !EditorHttpController._nameIsAcceptableLength(name)
|
||||
return res.sendStatus 400
|
||||
EditorController.addFolder project_id, parent_folder_id, name, "editor", (error, doc) ->
|
||||
return next(error) if error?
|
||||
res.json doc
|
||||
if error == "project_has_to_many_files"
|
||||
res.status(400).json(req.i18n.translate("project_has_to_many_files"))
|
||||
else if error?
|
||||
next(error)
|
||||
else
|
||||
res.json doc
|
||||
|
||||
renameEntity: (req, res, next) ->
|
||||
project_id = req.params.Project_id
|
||||
|
|
|
@ -35,7 +35,9 @@ module.exports =
|
|||
self._buildTemplate "mainbasic.tex", owner_id, projectName, (error, docLines)->
|
||||
return callback(error) if error?
|
||||
ProjectEntityHandler.addDoc project._id, project.rootFolder[0]._id, "main.tex", docLines, (error, doc)->
|
||||
return callback(error) if error?
|
||||
if error?
|
||||
logger.err err:error, "error adding doc"
|
||||
return callback(error)
|
||||
ProjectEntityHandler.setRootDoc project._id, doc._id, (error) ->
|
||||
callback(error, project)
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ module.exports = ProjectDeleter =
|
|||
|
||||
archiveProject: (project_id, callback = (error) ->)->
|
||||
logger.log project_id:project_id, "deleting project"
|
||||
ProjectGetter.getProject project_id, {owner_ref:1, collaberator_refs:1, readOnly_refs:1}, (err, project)=>
|
||||
ProjectGetter.getProject project_id, {owner_ref:true, collaberator_refs:true, readOnly_refs:true}, (err, project)=>
|
||||
if err? or !project?
|
||||
logger.err err:err, project_id:project_id, "error getting project to delete it"
|
||||
callback(err)
|
||||
|
|
|
@ -8,7 +8,7 @@ _ = require("underscore")
|
|||
module.exports =
|
||||
|
||||
getDetails: (project_id, callback)->
|
||||
ProjectGetter.getProject project_id, {name:1, description:1, compiler:1, features:1, owner_ref:1}, (err, project)->
|
||||
ProjectGetter.getProject project_id, {name:true, description:true, compiler:true, features:true, owner_ref:true}, (err, project)->
|
||||
if err?
|
||||
logger.err err:err, project_id:project_id, "error getting project"
|
||||
return callback(err)
|
||||
|
@ -37,7 +37,7 @@ module.exports =
|
|||
|
||||
renameProject: (project_id, newName, callback = ->)->
|
||||
logger.log project_id: project_id, newName:newName, "renaming project"
|
||||
ProjectGetter.getProject project_id, {"name":1}, (err, project)->
|
||||
ProjectGetter.getProject project_id, {name:true}, (err, project)->
|
||||
if err? or !project?
|
||||
logger.err err:err, project_id:project_id, "error getting project or could not find it todo project rename"
|
||||
return callback(err)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
Project = require('../../models/Project').Project
|
||||
settings = require "settings-sharelatex"
|
||||
Doc = require('../../models/Doc').Doc
|
||||
Folder = require('../../models/Folder').Folder
|
||||
File = require('../../models/File').File
|
||||
|
@ -436,6 +437,8 @@ module.exports = ProjectEntityHandler =
|
|||
|
||||
if subfolderCounts?.length > 0
|
||||
total = _.reduce subfolderCounts, (a, b)-> return a + b
|
||||
if folder?.folders?.length?
|
||||
total += folder?.folders?.length
|
||||
if folder?.docs?.length?
|
||||
total += folder?.docs?.length
|
||||
if folder?.fileRefs?.length?
|
||||
|
@ -458,30 +461,34 @@ module.exports = ProjectEntityHandler =
|
|||
logger.err project_id:project_id, folder_id:folder_id, element:element, type:type, "failed trying to insert element as it was null"
|
||||
return callback(e)
|
||||
type = sanitizeTypeOfElement type
|
||||
ProjectGetter.getProject project_id, "rootFolder", (err, project)=>
|
||||
ProjectGetter.getProject project_id, {rootFolder:true}, (err, project)=>
|
||||
if err?
|
||||
return callback(err)
|
||||
if !folder_id?
|
||||
folder_id = project.rootFolder[0]._id
|
||||
projectLocator.findElement {project:project, element_id:folder_id, type:"folders"}, (err, folder, path)=>
|
||||
newPath =
|
||||
fileSystem: "#{path.fileSystem}/#{element.name}"
|
||||
mongo: path.mongo
|
||||
if err?
|
||||
logger.err err:err, project_id:project_id, folder_id:folder_id, type:type, element:element, "error finding folder for _putElement"
|
||||
return callback(err)
|
||||
logger.log project_id: project_id, element_id: element._id, fileType: type, folder_id: folder_id, "adding element to project"
|
||||
id = element._id+''
|
||||
element._id = require('mongoose').Types.ObjectId(id)
|
||||
conditions = _id:project_id
|
||||
mongopath = "#{path.mongo}.#{type}"
|
||||
update = "$push":{}
|
||||
update["$push"][mongopath] = element
|
||||
Project.update conditions, update, {}, (err)->
|
||||
ProjectEntityHandler._countElements project, (err, count)->
|
||||
if count > settings.maxFilesPerProject
|
||||
logger.warn project_id:project_id, "project too big, stopping insertions"
|
||||
return callback("project_has_to_many_files")
|
||||
projectLocator.findElement {project:project, element_id:folder_id, type:"folders"}, (err, folder, path)=>
|
||||
newPath =
|
||||
fileSystem: "#{path.fileSystem}/#{element.name}"
|
||||
mongo: path.mongo
|
||||
if err?
|
||||
logger.err err: err, project_id: project_id, 'error saving in putElement project'
|
||||
logger.err err:err, project_id:project_id, folder_id:folder_id, type:type, element:element, "error finding folder for _putElement"
|
||||
return callback(err)
|
||||
callback(err, {path:newPath})
|
||||
logger.log project_id: project_id, element_id: element._id, fileType: type, folder_id: folder_id, "adding element to project"
|
||||
id = element._id+''
|
||||
element._id = require('mongoose').Types.ObjectId(id)
|
||||
conditions = _id:project_id
|
||||
mongopath = "#{path.mongo}.#{type}"
|
||||
update = "$push":{}
|
||||
update["$push"][mongopath] = element
|
||||
Project.update conditions, update, {}, (err)->
|
||||
if err?
|
||||
logger.err err: err, project_id: project_id, 'error saving in putElement project'
|
||||
return callback(err)
|
||||
callback(err, {path:newPath})
|
||||
|
||||
confirmFolder = (project, folder_id, callback)->
|
||||
logger.log folder_id:folder_id, project_id:project._id, "confirming folder in project"
|
||||
|
|
|
@ -311,6 +311,7 @@ script(type='text/ng-template', id='newDocModalTemplate')
|
|||
h3 #{translate("new_file")}
|
||||
.modal-body
|
||||
form(novalidate, name="newDocForm")
|
||||
div.alert.alert-danger(ng-if="error") {{error}}
|
||||
input.form-control(
|
||||
type="text",
|
||||
placeholder="File Name",
|
||||
|
@ -335,6 +336,7 @@ script(type='text/ng-template', id='newFolderModalTemplate')
|
|||
.modal-header
|
||||
h3 #{translate("new_folder")}
|
||||
.modal-body
|
||||
div.alert.alert-danger(ng-if="error") {{error}}
|
||||
form(novalidate, name="newFolderForm")
|
||||
input.form-control(
|
||||
type="text",
|
||||
|
|
|
@ -129,6 +129,9 @@ module.exports =
|
|||
# Same, but with http auth credentials.
|
||||
httpAuthSiteUrl: 'http://#{httpAuthUser}:#{httpAuthPass}@localhost:3000'
|
||||
|
||||
|
||||
maxFilesPerProject: 200
|
||||
|
||||
# Security
|
||||
# --------
|
||||
security:
|
||||
|
|
|
@ -61,6 +61,8 @@ define [
|
|||
$scope.state.inflight = true
|
||||
ide.fileTreeManager
|
||||
.createDoc(name, parent_folder)
|
||||
.error (e)->
|
||||
$scope.error = e
|
||||
.success () ->
|
||||
$scope.state.inflight = false
|
||||
$modalInstance.close()
|
||||
|
@ -90,6 +92,8 @@ define [
|
|||
$scope.state.inflight = true
|
||||
ide.fileTreeManager
|
||||
.createFolder(name, parent_folder)
|
||||
.error (e)->
|
||||
$scope.error = e
|
||||
.success () ->
|
||||
$scope.state.inflight = false
|
||||
$modalInstance.close()
|
||||
|
|
|
@ -1101,25 +1101,25 @@ describe 'ProjectEntityHandler', ->
|
|||
|
||||
it "should return the correct number", (done)->
|
||||
@ProjectEntityHandler._countElements @project, (err, count)->
|
||||
count.should.equal 21
|
||||
count.should.equal 26
|
||||
done()
|
||||
|
||||
it "should deal with null folders", (done)->
|
||||
@project.rootFolder[0].folders[0].folders = undefined
|
||||
@ProjectEntityHandler._countElements @project, (err, count)->
|
||||
count.should.equal 14
|
||||
count.should.equal 17
|
||||
done()
|
||||
|
||||
it "should deal with null docs", (done)->
|
||||
@project.rootFolder[0].folders[0].docs = undefined
|
||||
@ProjectEntityHandler._countElements @project, (err, count)->
|
||||
count.should.equal 18
|
||||
count.should.equal 23
|
||||
done()
|
||||
|
||||
it "should deal with null fileRefs", (done)->
|
||||
@project.rootFolder[0].folders[0].folders[0].fileRefs = undefined
|
||||
@ProjectEntityHandler._countElements @project, (err, count)->
|
||||
count.should.equal 18
|
||||
count.should.equal 23
|
||||
done()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue