From b5dd96aa7110aceb2eed9f7a0a260ce5a7f4b9e8 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Mon, 29 Feb 2016 16:03:22 +0000 Subject: [PATCH] fixed some mongo calls in project entity handler need to specify fields you want to not get array back. --- .../Features/Project/ProjectEntityHandler.coffee | 9 +++++---- .../app/coffee/Features/Project/ProjectLocator.coffee | 10 +++++++--- .../Features/Uploads/FileSystemImportManager.coffee | 2 ++ .../Features/Uploads/ProjectUploadController.coffee | 1 + .../coffee/Project/ProjectEntityHandlerTests.coffee | 8 ++++---- .../coffee/Project/ProjectLocatorTests.coffee | 2 +- 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/services/web/app/coffee/Features/Project/ProjectEntityHandler.coffee b/services/web/app/coffee/Features/Project/ProjectEntityHandler.coffee index a4001f902a..e5bd3fe0fa 100644 --- a/services/web/app/coffee/Features/Project/ProjectEntityHandler.coffee +++ b/services/web/app/coffee/Features/Project/ProjectEntityHandler.coffee @@ -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 diff --git a/services/web/app/coffee/Features/Project/ProjectLocator.coffee b/services/web/app/coffee/Features/Project/ProjectLocator.coffee index f7b0fa2e0b..7d1eb8f749 100644 --- a/services/web/app/coffee/Features/Project/ProjectLocator.coffee +++ b/services/web/app/coffee/Features/Project/ProjectLocator.coffee @@ -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)->)-> diff --git a/services/web/app/coffee/Features/Uploads/FileSystemImportManager.coffee b/services/web/app/coffee/Features/Uploads/FileSystemImportManager.coffee index 4f0c4dcc0b..0c297147d1 100644 --- a/services/web/app/coffee/Features/Uploads/FileSystemImportManager.coffee +++ b/services/web/app/coffee/Features/Uploads/FileSystemImportManager.coffee @@ -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? diff --git a/services/web/app/coffee/Features/Uploads/ProjectUploadController.coffee b/services/web/app/coffee/Features/Uploads/ProjectUploadController.coffee index 83a8db5c2d..36fbde4ebe 100644 --- a/services/web/app/coffee/Features/Uploads/ProjectUploadController.coffee +++ b/services/web/app/coffee/Features/Uploads/ProjectUploadController.coffee @@ -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() diff --git a/services/web/test/UnitTests/coffee/Project/ProjectEntityHandlerTests.coffee b/services/web/test/UnitTests/coffee/Project/ProjectEntityHandlerTests.coffee index c22c45ac9b..39e7b5bcfc 100644 --- a/services/web/test/UnitTests/coffee/Project/ProjectEntityHandlerTests.coffee +++ b/services/web/test/UnitTests/coffee/Project/ProjectEntityHandlerTests.coffee @@ -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)-> diff --git a/services/web/test/UnitTests/coffee/Project/ProjectLocatorTests.coffee b/services/web/test/UnitTests/coffee/Project/ProjectLocatorTests.coffee index c7b4060a51..f43749a5ca 100644 --- a/services/web/test/UnitTests/coffee/Project/ProjectLocatorTests.coffee +++ b/services/web/test/UnitTests/coffee/Project/ProjectLocatorTests.coffee @@ -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}