diff --git a/services/web/app/coffee/Features/Editor/EditorController.coffee b/services/web/app/coffee/Features/Editor/EditorController.coffee index 438711105e..d2fa43ad62 100644 --- a/services/web/app/coffee/Features/Editor/EditorController.coffee +++ b/services/web/app/coffee/Features/Editor/EditorController.coffee @@ -39,20 +39,20 @@ module.exports = EditorController = EditorRealTimeController.emitToRoom(project_id, 'reciveNewDoc', folder_id, doc, source) callback(err, doc) - addFile: (project_id, folder_id, fileName, path, source, callback = (error, file)->)-> + addFile: (project_id, folder_id, fileName, path, source, user_id, callback = (error, file)->)-> LockManager.getLock project_id, (err)-> if err? logger.err err:err, project_id:project_id, source:source, "could not get lock to addFile" return callback(err) - EditorController.addFileWithoutLock project_id, folder_id, fileName, path, source, (error, file)-> + EditorController.addFileWithoutLock project_id, folder_id, fileName, path, source, user_id, (error, file)-> LockManager.releaseLock project_id, -> callback(error, file) - addFileWithoutLock: (project_id, folder_id, fileName, path, source, callback = (error, file)->)-> + addFileWithoutLock: (project_id, folder_id, fileName, path, source, user_id, callback = (error, file)->)-> fileName = fileName.trim() logger.log {project_id, folder_id, fileName, path}, "sending new file to project" Metrics.inc "editor.add-file" - ProjectEntityHandler.addFile project_id, folder_id, fileName, path, null, (err, fileRef, folder_id)=> + ProjectEntityHandler.addFile project_id, folder_id, fileName, path, user_id, (err, fileRef, folder_id)=> if err? logger.err err:err, project_id:project_id, folder_id:folder_id, fileName:fileName, "error adding file without lock" return callback(err) diff --git a/services/web/app/coffee/Features/ThirdPartyDataStore/UpdateMerger.coffee b/services/web/app/coffee/Features/ThirdPartyDataStore/UpdateMerger.coffee index bce0befe22..e78c1bd1e4 100644 --- a/services/web/app/coffee/Features/ThirdPartyDataStore/UpdateMerger.coffee +++ b/services/web/app/coffee/Features/ThirdPartyDataStore/UpdateMerger.coffee @@ -28,7 +28,7 @@ module.exports = FileTypeManager.isBinary path, fsPath, (err, isFile)-> return callback(err) if err? if isFile - self.p.processFile project_id, elementId, fsPath, path, source, callback + self.p.processFile project_id, elementId, fsPath, path, source, user_id, callback else self.p.processDoc project_id, elementId, user_id, fsPath, path, source, callback @@ -59,7 +59,7 @@ module.exports = return callback(err) editorController.addDoc project_id, folder._id, fileName, docLines, source, callback - processFile: (project_id, file_id, fsPath, path, source, callback)-> + processFile: (project_id, file_id, fsPath, path, source, user_id, callback)-> finish = (err)-> logger.log project_id:project_id, file_id:file_id, path:path, "completed processing file update from tpds" callback(err) @@ -71,7 +71,7 @@ module.exports = else if file_id? editorController.replaceFile project_id, file_id, fsPath, source, finish else - editorController.addFile project_id, folder?._id, fileName, fsPath, source, finish + editorController.addFile project_id, folder?._id, fileName, fsPath, source, user_id, finish writeStreamToDisk: (project_id, file_id, stream, callback = (err, fsPath)->)-> if !file_id? diff --git a/services/web/app/coffee/Features/Uploads/FileSystemImportManager.coffee b/services/web/app/coffee/Features/Uploads/FileSystemImportManager.coffee index f491807e9d..a1ddc2e59b 100644 --- a/services/web/app/coffee/Features/Uploads/FileSystemImportManager.coffee +++ b/services/web/app/coffee/Features/Uploads/FileSystemImportManager.coffee @@ -39,7 +39,7 @@ module.exports = FileSystemImportManager = return callback("path is symlink") if !replace - EditorController.addFileWithoutLock project_id, folder_id, name, path, "upload", callback + EditorController.addFileWithoutLock project_id, folder_id, name, path, "upload", user_id, callback else ProjectLocator.findElement project_id: project_id, element_id: folder_id, type: "folder", (error, folder) -> return callback(error) if error? @@ -52,7 +52,7 @@ module.exports = FileSystemImportManager = if existingFile? EditorController.replaceFile project_id, existingFile._id, path, "upload", callback else - EditorController.addFileWithoutLock project_id, folder_id, name, path, "upload", callback + EditorController.addFileWithoutLock project_id, folder_id, name, path, "upload", user_id, callback addFolder: (user_id, project_id, folder_id, name, path, replace, callback = (error)-> ) -> FileSystemImportManager._isSafeOnFileSystem path, (err, isSafe)-> diff --git a/services/web/test/unit/coffee/Editor/EditorControllerTests.coffee b/services/web/test/unit/coffee/Editor/EditorControllerTests.coffee index f84dc04c10..7738d11b3b 100644 --- a/services/web/test/unit/coffee/Editor/EditorControllerTests.coffee +++ b/services/web/test/unit/coffee/Editor/EditorControllerTests.coffee @@ -197,14 +197,14 @@ describe "EditorController", -> it 'should add the folder using the project entity handler', (done)-> @ProjectEntityHandler.addFile = sinon.stub().callsArgWith(5) - @EditorController.addFileWithoutLock @project_id, @folder_id, @fileName, @stream, @source, => - @ProjectEntityHandler.addFile.calledWith(@project_id, @folder_id).should.equal true + @EditorController.addFileWithoutLock @project_id, @folder_id, @fileName, @stream, @source, @user_id, => + @ProjectEntityHandler.addFile.calledWith(@project_id, @folder_id, @fileName, @stream, @user_id).should.equal true done() it 'should send the update of a new folder out to the users in the project', (done)-> @ProjectEntityHandler.addFile = sinon.stub().callsArgWith(5, null, @file, @folder_id) - @EditorController.addFileWithoutLock @project_id, @folder_id, @fileName, @stream, @source, => + @EditorController.addFileWithoutLock @project_id, @folder_id, @fileName, @stream, @source, @user_id, => @EditorRealTimeController.emitToRoom .calledWith(@project_id, "reciveNewFile", @folder_id, @file, @source) .should.equal true @@ -212,7 +212,7 @@ describe "EditorController", -> it "should return the file in the callback", (done) -> @ProjectEntityHandler.addFile = sinon.stub().callsArgWith(5, null, @file, @folder_id) - @EditorController.addFileWithoutLock @project_id, @folder_id, @fileName, @stream, @source, (error, file) => + @EditorController.addFileWithoutLock @project_id, @folder_id, @fileName, @stream, @source, @user_id, (error, file) => file.should.equal @file done() @@ -222,28 +222,28 @@ describe "EditorController", -> beforeEach -> @LockManager.getLock.callsArgWith(1) @LockManager.releaseLock.callsArgWith(1) - @EditorController.addFileWithoutLock = sinon.stub().callsArgWith(5) + @EditorController.addFileWithoutLock = sinon.stub().callsArgWith(6) it "should call addFileWithoutLock", (done)-> - @EditorController.addFile @project_id, @folder_id, @fileName, @stream, @source, (error, file) => - @EditorController.addFileWithoutLock.calledWith(@project_id, @folder_id, @fileName, @stream, @source).should.equal true + @EditorController.addFile @project_id, @folder_id, @fileName, @stream, @source, @user_id, (error, file) => + @EditorController.addFileWithoutLock.calledWith(@project_id, @folder_id, @fileName, @stream, @source, @user_id).should.equal true done() it "should take the lock", (done)-> - @EditorController.addFile @project_id, @folder_id, @fileName, @stream, @source, (error, file) => + @EditorController.addFile @project_id, @folder_id, @fileName, @stream, @source, @user_id, (error, file) => @LockManager.getLock.calledWith(@project_id).should.equal true done() it "should release the lock", (done)-> - @EditorController.addFile @project_id, @folder_id, @fileName, @stream, @source, (error, file) => + @EditorController.addFile @project_id, @folder_id, @fileName, @stream, @source, @user_id, (error, file) => @LockManager.releaseLock.calledWith(@project_id).should.equal true done() it "should error if it can't cat the lock", (done)-> @LockManager.getLock = sinon.stub().callsArgWith(1, "timed out") - @EditorController.addFile @project_id, @folder_id, @fileName, @stream, @source, (err, file) => - expect(err).to.exist - err.should.equal "timed out" + @EditorController.addFile @project_id, @folder_id, @fileName, @stream, @source, @user_id, (error, file) => + expect(error).to.exist + error.should.equal "timed out" done() diff --git a/services/web/test/unit/coffee/ThirdPartyDataStore/UpdateMergerTests.coffee b/services/web/test/unit/coffee/ThirdPartyDataStore/UpdateMergerTests.coffee index 1b00f20bde..c2d3816a5c 100644 --- a/services/web/test/unit/coffee/ThirdPartyDataStore/UpdateMergerTests.coffee +++ b/services/web/test/unit/coffee/ThirdPartyDataStore/UpdateMergerTests.coffee @@ -63,11 +63,11 @@ describe 'UpdateMerger :', -> file_id = "1231" @projectLocator.findElementByPath = (_, __, cb)->cb(null, {_id:file_id}) @FileTypeManager.isBinary.callsArgWith(2, null, true) - @updateMerger.p.processFile = sinon.stub().callsArgWith(5) + @updateMerger.p.processFile = sinon.stub().callsArgWith(6) filePath = "/folder/file1.png" @updateMerger.mergeUpdate @user_id, @project_id, filePath, @update, @source, => - @updateMerger.p.processFile.calledWith(@project_id, file_id, @fsPath, filePath, @source).should.equal true + @updateMerger.p.processFile.calledWith(@project_id, file_id, @fsPath, filePath, @source, @user_id).should.equal true @FileTypeManager.isBinary.calledWith(filePath, @fsPath).should.equal true @fs.unlink.calledWith(@fsPath).should.equal true done() @@ -114,22 +114,22 @@ describe 'UpdateMerger :', -> @folder = _id: @folder_id @fileName = "file.png" @fsPath = "fs/path.tex" - @editorController.addFile = sinon.stub().callsArg(5) + @editorController.addFile = sinon.stub().callsArg(6) @editorController.replaceFile = sinon.stub().callsArg(4) @editorController.deleteEntity = sinon.stub() @editorController.mkdirp = sinon.stub().withArgs(@project_id).callsArgWith(2, null, [@folder], @folder) @updateMerger.p.writeStreamToDisk = sinon.stub().withArgs(@project_id, @file_id, @update).callsArgWith(3, null, @fsPath) it 'should replace file if the file already exists', (done)-> - @updateMerger.p.processFile @project_id, @file_id, @fsPath, @path, @source, => + @updateMerger.p.processFile @project_id, @file_id, @fsPath, @path, @source, @user_id, => @editorController.addFile.called.should.equal false @editorController.replaceFile.calledWith(@project_id, @file_id, @fsPath, @source).should.equal true done() it 'should call add file if the file does not exist', (done)-> - @updateMerger.p.processFile @project_id, undefined, @fsPath, @path, @source, => + @updateMerger.p.processFile @project_id, undefined, @fsPath, @path, @source, @user_id, => @editorController.mkdirp.calledWith(@project_id, "folder/").should.equal true - @editorController.addFile.calledWith(@project_id, @folder_id, @fileName, @fsPath, @source).should.equal true + @editorController.addFile.calledWith(@project_id, @folder_id, @fileName, @fsPath, @source, @user_id).should.equal true @editorController.replaceFile.called.should.equal false done() diff --git a/services/web/test/unit/coffee/Uploads/FileSystemImportManagerTests.coffee b/services/web/test/unit/coffee/Uploads/FileSystemImportManagerTests.coffee index a33775446f..032b60b261 100644 --- a/services/web/test/unit/coffee/Uploads/FileSystemImportManagerTests.coffee +++ b/services/web/test/unit/coffee/Uploads/FileSystemImportManagerTests.coffee @@ -114,12 +114,12 @@ describe "FileSystemImportManager", -> describe "addFile with replace set to false", -> beforeEach -> - @EditorController.addFileWithoutLock = sinon.stub().callsArg(5) + @EditorController.addFileWithoutLock = sinon.stub().callsArg(6) @FileSystemImportManager._isSafeOnFileSystem = sinon.stub().callsArgWith(1, null, true) @FileSystemImportManager.addFile @user_id, @project_id, @folder_id, @name, @path_on_disk, false, @callback it "should add the file", -> - @EditorController.addFileWithoutLock.calledWith(@project_id, @folder_id, @name, @path_on_disk, "upload") + @EditorController.addFileWithoutLock.calledWith(@project_id, @folder_id, @name, @path_on_disk, "upload", @user_id) .should.equal true describe "addFile with symlink", -> @@ -144,7 +144,7 @@ describe "FileSystemImportManager", -> } @FileSystemImportManager._isSafeOnFileSystem = sinon.stub().callsArgWith(1, null, true) @ProjectLocator.findElement = sinon.stub().callsArgWith(1, null, @folder) - @EditorController.addFileWithoutLock = sinon.stub().callsArg(5) + @EditorController.addFileWithoutLock = sinon.stub().callsArg(6) @FileSystemImportManager.addFile @user_id, @project_id, @folder_id, @name, @path_on_disk, true, @callback it "should look up the folder", -> @@ -153,7 +153,7 @@ describe "FileSystemImportManager", -> .should.equal true it "should add the file", -> - @EditorController.addFileWithoutLock.calledWith(@project_id, @folder_id, @name, @path_on_disk, "upload") + @EditorController.addFileWithoutLock.calledWith(@project_id, @folder_id, @name, @path_on_disk, "upload", @user_id) .should.equal true describe "when the file does exist", ->