fixed some mongo calls in project entity handler

need to specify fields you want to not get array back.
This commit is contained in:
Henry Oswald 2016-02-29 16:03:22 +00:00
parent 1e8523c227
commit b5dd96aa71
6 changed files with 20 additions and 12 deletions

View file

@ -76,7 +76,7 @@ module.exports = ProjectEntityHandler =
documentUpdaterHandler = require('../../Features/DocumentUpdater/DocumentUpdaterHandler')
documentUpdaterHandler.flushProjectToMongo project_id, (error) ->
return callback(error) if error?
ProjectGetter.getProject project_id, (error, project) ->
ProjectGetter.getProject project_id, {name:true}, (error, project) ->
return callback(error) if error?
requests = []
self.getAllDocs project_id, (error, docs) ->
@ -280,7 +280,7 @@ module.exports = ProjectEntityHandler =
logger.err err: "No entityType set", project_id: project_id, entity_id: entity_id
return callback("No entityType set")
entityType = entityType.toLowerCase()
ProjectGetter.getProject project_id, (err, project)=>
ProjectGetter.getProject project_id, {rootFolder:true}, (err, project)=>
return callback(err) if err?
projectLocator.findElement {project:project, element_id:entity_id, type:entityType}, (err, entity, path)->
return callback(err) if err?
@ -318,7 +318,8 @@ module.exports = ProjectEntityHandler =
logger.err err: "No entityType set", project_id: project_id, entity_id: entity_id
return callback("No entityType set")
entityType = entityType.toLowerCase()
ProjectGetter.getProject project_id, (err, project)=>
console.log "getting project"
ProjectGetter.getProject project_id, {name:true, rootFolder:true}, (err, project)=>
return callback(error) if error?
projectLocator.findElement {project: project, element_id: entity_id, type: entityType}, (error, entity, path)=>
return callback(error) if error?
@ -337,7 +338,7 @@ module.exports = ProjectEntityHandler =
logger.err err: "No entityType set", project_id: project_id, entity_id: entity_id
return callback("No entityType set")
entityType = entityType.toLowerCase()
ProjectGetter.getProject project_id, (err, project)=>
ProjectGetter.getProject project_id, {rootFolder:true, name:true}, (err, project)=>
projectLocator.findElement {project:project, element_id:entity_id, type:entityType}, (err, entity, path, folder)=>
if err?
return callback err

View file

@ -51,7 +51,7 @@ module.exports = ProjectLocator =
if project?
startSearch(project)
else
ProjectGetter.getProject project_id, (err, project)->
ProjectGetter.getProject project_id, {rootFolder:true, rootDoc_id:true}, (err, project)->
return callback(err) if err?
if !project?
return callback(new Errors.NotFoundError("project not found"))
@ -67,8 +67,12 @@ module.exports = ProjectLocator =
if project?
getRootDoc project
else
ProjectGetter.getProject project_id, (err, project)->
getRootDoc project
ProjectGetter.getProject project_id, {rootFolder:true, rootDoc_id:true}, (err, project)->
if err?
logger.err err:err, "error getting project"
return callback(err)
else
getRootDoc project
findElementByPath: (project_or_id, needlePath, callback = (err, foundEntity)->)->

View file

@ -4,6 +4,7 @@ _ = require "underscore"
FileTypeManager = require "./FileTypeManager"
EditorController = require "../Editor/EditorController"
ProjectLocator = require "../Project/ProjectLocator"
logger = require "logger-sharelatex"
module.exports = FileSystemImportManager =
addDoc: (project_id, folder_id, name, path, replace, callback = (error, doc)-> )->
@ -14,6 +15,7 @@ module.exports = FileSystemImportManager =
EditorController.addDocWithoutLock project_id, folder_id, name, lines, "upload", callback
addFile: (project_id, folder_id, name, path, replace, callback = (error, file)-> )->
logger.log project_id:project_id, folder_id:folder_id, name:name, path:path, replace:replace, "adding file from filesystem"
if replace
ProjectLocator.findElement project_id: project_id, element_id: folder_id, type: "folder", (error, folder) ->
return callback(error) if error?

View file

@ -34,6 +34,7 @@ module.exports = ProjectUploadController =
if !name? or name.length == 0 or name.length > 150
logger.err project_id:project_id, name:name, "bad name when trying to upload file"
return res.send success: false
logger.log folder_id:folder_id, project_id:project_id, "getting upload file request"
FileSystemImportManager.addEntity project_id, folder_id, name, path, true, (error, entity) ->
fs.unlink path, ->
timer.done()

View file

@ -144,7 +144,7 @@ describe 'ProjectEntityHandler', ->
describe 'deleteEntity', ->
entity_id = "4eecaffcbffa66588e000009"
beforeEach ->
@ProjectGetter.getProject.callsArgWith(1, null, @project)
@ProjectGetter.getProject.callsArgWith(2, null, @project)
@tpdsUpdateSender.deleteEntity = sinon.stub().callsArg(1)
@ProjectEntityHandler._removeElementFromMongoArray = sinon.stub().callsArg(3)
@ProjectEntityHandler._cleanUpEntity = sinon.stub().callsArg(3)
@ -232,7 +232,7 @@ describe 'ProjectEntityHandler', ->
}
@ProjectEntityHandler._removeElementFromMongoArray = sinon.stub().callsArg(3)
@ProjectEntityHandler._putElement = sinon.stub().callsArgWith(4, null, path: @pathAfterMove)
@ProjectGetter.getProject.callsArgWith(1, null, @project)
@ProjectGetter.getProject.callsArgWith(2, null, @project)
@tpdsUpdateSender.moveEntity = sinon.stub().callsArg(1)
describe "moving a doc", ->
@ -810,7 +810,7 @@ describe 'ProjectEntityHandler', ->
@ProjectEntityHandler.getAllDocs = sinon.stub().callsArgWith(1, null, @docs)
@ProjectEntityHandler.getAllFiles = sinon.stub().callsArgWith(1, null, @files)
@ProjectGetter.getProject.callsArgWith(1, null, @project)
@ProjectGetter.getProject.callsArgWith(2, null, @project)
@ProjectEntityHandler.flushProjectToThirdPartyDataStore project_id, () -> done()
@ -927,7 +927,7 @@ describe 'ProjectEntityHandler', ->
@projectLocator.findElement = sinon.stub().callsArgWith(1, null, @entity = { _id: @entity_id, name:"old.tex", rev:4 }, @path)
@ProjectModel.update = sinon.stub().callsArgWith(3)
@tpdsUpdateSender.moveEntity = sinon.stub()
@ProjectGetter.getProject.callsArgWith(1, null, @project)
@ProjectGetter.getProject.callsArgWith(2, null, @project)
it "should update the name in mongo", (done)->

View file

@ -39,7 +39,7 @@ describe 'ProjectLocatorTests', ->
Project.findById = (project_id, callback)=>
callback(null, project)
@ProjectGetter =
getProject: sinon.stub().callsArgWith(1, null, project)
getProject: sinon.stub().callsArgWith(2, null, project)
@locator = SandboxedModule.require modulePath, requires:
'../../models/Project':{Project:Project}
'../../models/User':{User:@User}