diff --git a/services/web/app/coffee/Features/Editor/EditorController.coffee b/services/web/app/coffee/Features/Editor/EditorController.coffee index 7dad02bde9..701ea0085b 100644 --- a/services/web/app/coffee/Features/Editor/EditorController.coffee +++ b/services/web/app/coffee/Features/Editor/EditorController.coffee @@ -13,10 +13,13 @@ _ = require('underscore') module.exports = EditorController = addDoc: (project_id, folder_id, docName, docLines, source, user_id, callback = (error, doc)->)-> + EditorController.addDocWithRanges(project_id, folder_id, docName, docLines, {}, source, user_id, callback) + + addDocWithRanges: (project_id, folder_id, docName, docLines, docRanges, source, user_id, callback = (error, doc)->)-> docName = docName.trim() logger.log {project_id, folder_id, docName, source}, "sending new doc to project" Metrics.inc "editor.add-doc" - ProjectEntityUpdateHandler.addDoc project_id, folder_id, docName, docLines, user_id, (err, doc, folder_id)=> + ProjectEntityUpdateHandler.addDocWithRanges project_id, folder_id, docName, docLines, docRanges, user_id, (err, doc, folder_id)=> if err? logger.err err:err, project_id:project_id, docName:docName, "error adding doc without lock" return callback(err) diff --git a/services/web/app/coffee/Features/Project/ProjectEntityUpdateHandler.coffee b/services/web/app/coffee/Features/Project/ProjectEntityUpdateHandler.coffee index f2b5df32ac..9bdfa0e18d 100644 --- a/services/web/app/coffee/Features/Project/ProjectEntityUpdateHandler.coffee +++ b/services/web/app/coffee/Features/Project/ProjectEntityUpdateHandler.coffee @@ -141,18 +141,21 @@ module.exports = ProjectEntityUpdateHandler = self = return callback(err) if err? callback(null, result, project) - addDoc: wrapWithLock + addDoc: (project_id, folder_id, docName, docLines, userId, callback) -> + self.addDocWithRanges(project_id, folder_id, docName, docLines, {}, userId, callback) + + addDocWithRanges: wrapWithLock beforeLock: (next) -> - (project_id, folder_id, docName, docLines, userId, callback = (error, doc, folder_id) ->) -> + (project_id, folder_id, docName, docLines, ranges, userId, callback = (error, doc, folder_id) ->) -> if not SafePath.isCleanFilename docName return callback new Errors.InvalidNameError("invalid element name") # Put doc in docstore first, so that if it errors, we don't have a doc_id in the project # which hasn't been created in docstore. doc = new Doc name: docName - DocstoreManager.updateDoc project_id.toString(), doc._id.toString(), docLines, 0, {}, (err, modified, rev) -> + DocstoreManager.updateDoc project_id.toString(), doc._id.toString(), docLines, 0, ranges, (err, modified, rev) -> return callback(err) if err? - next(project_id, folder_id, doc, docName, docLines, userId, callback) - withLock: (project_id, folder_id, doc, docName, docLines, userId, callback = (error, doc, folder_id) ->) -> + next(project_id, folder_id, doc, docName, docLines, ranges, userId, callback) + withLock: (project_id, folder_id, doc, docName, docLines, ranges, userId, callback = (error, doc, folder_id) ->) -> ProjectEntityUpdateHandler._addDocAndSendToTpds project_id, folder_id, doc, (err, result, project) -> return callback(err) if err? docPath = result?.path?.fileSystem @@ -261,7 +264,7 @@ module.exports = ProjectEntityUpdateHandler = self = return callback(err) if err? callback null, existingDoc, !existingDoc? else - self.addDoc.withoutLock project_id, folder_id, docName, docLines, userId, (err, doc) -> + self.addDocWithRanges.withoutLock project_id, folder_id, docName, docLines, {}, userId, (err, doc) -> return callback(err) if err? callback null, doc, !existingDoc? diff --git a/services/web/app/coffee/infrastructure/mongojs.coffee b/services/web/app/coffee/infrastructure/mongojs.coffee index 8492b9023c..6e9432d339 100644 --- a/services/web/app/coffee/infrastructure/mongojs.coffee +++ b/services/web/app/coffee/infrastructure/mongojs.coffee @@ -1,6 +1,6 @@ Settings = require "settings-sharelatex" mongojs = require "mongojs" -db = mongojs(Settings.mongo.url, ["projects", "users", "userstubs", "tokens"]) +db = mongojs(Settings.mongo.url, ["projects", "users", "userstubs", "tokens", "docSnapshots"]) module.exports = db: db ObjectId: mongojs.ObjectId diff --git a/services/web/test/unit/coffee/Editor/EditorControllerTests.coffee b/services/web/test/unit/coffee/Editor/EditorControllerTests.coffee index f1bf3792a2..c9cad856e6 100644 --- a/services/web/test/unit/coffee/Editor/EditorControllerTests.coffee +++ b/services/web/test/unit/coffee/Editor/EditorControllerTests.coffee @@ -51,12 +51,12 @@ describe "EditorController", -> describe 'addDoc', -> beforeEach -> - @ProjectEntityUpdateHandler.addDoc = sinon.stub().yields(null, @doc, @folder_id) + @ProjectEntityUpdateHandler.addDocWithRanges = sinon.stub().yields(null, @doc, @folder_id) @EditorController.addDoc @project_id, @folder_id, @docName, @docLines, @source, @user_id, @callback it 'should add the doc using the project entity handler', -> - @ProjectEntityUpdateHandler.addDoc - .calledWith(@project_id, @folder_id, @docName, @docLines) + @ProjectEntityUpdateHandler.addDocWithRanges + .calledWith(@project_id, @folder_id, @docName, @docLines, {}) .should.equal true it 'should send the update out to the users in the project', -> diff --git a/services/web/test/unit/coffee/Project/ProjectEntityUpdateHandlerTests.coffee b/services/web/test/unit/coffee/Project/ProjectEntityUpdateHandlerTests.coffee index 29e5d3593a..7accaa13e6 100644 --- a/services/web/test/unit/coffee/Project/ProjectEntityUpdateHandlerTests.coffee +++ b/services/web/test/unit/coffee/Project/ProjectEntityUpdateHandlerTests.coffee @@ -477,7 +477,7 @@ describe 'ProjectEntityUpdateHandler', -> @folder = _id: folder_id, docs: [] @newDoc = _id: doc_id @ProjectLocator.findElement = sinon.stub().yields(null, @folder) - @ProjectEntityUpdateHandler.addDoc = withoutLock: sinon.stub().yields(null, @newDoc) + @ProjectEntityUpdateHandler.addDocWithRanges = withoutLock: sinon.stub().yields(null, @newDoc) @ProjectEntityUpdateHandler.upsertDoc project_id, folder_id, @docName, @docLines, @source, userId, @callback @@ -487,8 +487,8 @@ describe 'ProjectEntityUpdateHandler', -> .should.equal true it 'adds the doc', -> - @ProjectEntityUpdateHandler.addDoc.withoutLock - .calledWith(project_id, folder_id, @docName, @docLines, userId) + @ProjectEntityUpdateHandler.addDocWithRanges.withoutLock + .calledWith(project_id, folder_id, @docName, @docLines, {}, userId) .should.equal true it 'returns the doc', -> @@ -499,7 +499,7 @@ describe 'ProjectEntityUpdateHandler', -> @folder = _id: folder_id, docs: [] @newDoc = _id: doc_id @ProjectLocator.findElement = sinon.stub().yields(null, @folder) - @ProjectEntityUpdateHandler.addDoc = withoutLock: sinon.stub().yields(null, @newDoc) + @ProjectEntityUpdateHandler.addDocWithRanges = withoutLock: sinon.stub().yields(null, @newDoc) @ProjectEntityUpdateHandler.upsertDoc project_id, folder_id, "*" + @docName, @docLines, @source, userId, @callback