mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-07 08:09:01 +02:00
pass user_id into EditorController.addDocWithoutLock
This commit is contained in:
@@ -24,15 +24,15 @@ module.exports = EditorController =
|
||||
if err?
|
||||
logger.err err:err, project_id:project_id, source:source, "could not get lock to addDoc"
|
||||
return callback(err)
|
||||
EditorController.addDocWithoutLock project_id, folder_id, docName, docLines, source, (error, doc)->
|
||||
EditorController.addDocWithoutLock project_id, folder_id, docName, docLines, source, null, (error, doc)->
|
||||
LockManager.releaseLock project_id, ->
|
||||
callback(error, doc)
|
||||
|
||||
addDocWithoutLock: (project_id, folder_id, docName, docLines, source, callback = (error, doc)->)->
|
||||
addDocWithoutLock: (project_id, folder_id, docName, docLines, 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"
|
||||
ProjectEntityHandler.addDoc project_id, folder_id, docName, docLines, null, (err, doc, folder_id)=>
|
||||
ProjectEntityHandler.addDoc project_id, folder_id, docName, docLines, 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)
|
||||
|
||||
@@ -28,9 +28,9 @@ module.exports = FileSystemImportManager =
|
||||
if existingDoc?
|
||||
EditorController.setDoc project_id, existingDoc._id, user_id, lines, "upload", callback
|
||||
else
|
||||
EditorController.addDocWithoutLock project_id, folder_id, name, lines, "upload", callback
|
||||
EditorController.addDocWithoutLock project_id, folder_id, name, lines, "upload", user_id, callback
|
||||
else
|
||||
EditorController.addDocWithoutLock project_id, folder_id, name, lines, "upload", callback
|
||||
EditorController.addDocWithoutLock project_id, folder_id, name, lines, "upload", user_id, callback
|
||||
|
||||
addFile: (user_id, project_id, folder_id, name, path, replace, callback = (error, file)-> )->
|
||||
FileSystemImportManager._isSafeOnFileSystem path, (err, isSafe)->
|
||||
|
||||
@@ -133,14 +133,14 @@ describe "EditorController", ->
|
||||
it 'should add the doc using the project entity handler', (done)->
|
||||
mock = sinon.mock(@ProjectEntityHandler).expects("addDoc").withArgs(@project_id, @folder_id, @docName, @docLines).callsArg(5)
|
||||
|
||||
@EditorController.addDocWithoutLock @project_id, @folder_id, @docName, @docLines, @source, ->
|
||||
@EditorController.addDocWithoutLock @project_id, @folder_id, @docName, @docLines, @source, @user_id, ->
|
||||
mock.verify()
|
||||
done()
|
||||
|
||||
it 'should send the update out to the users in the project', (done)->
|
||||
@ProjectEntityHandler.addDoc = sinon.stub().callsArgWith(5, null, @doc, @folder_id)
|
||||
|
||||
@EditorController.addDocWithoutLock @project_id, @folder_id, @docName, @docLines, @source, =>
|
||||
@EditorController.addDocWithoutLock @project_id, @folder_id, @docName, @docLines, @source, @user_id, =>
|
||||
@EditorRealTimeController.emitToRoom
|
||||
.calledWith(@project_id, "reciveNewDoc", @folder_id, @doc, @source)
|
||||
.should.equal true
|
||||
@@ -148,7 +148,7 @@ describe "EditorController", ->
|
||||
|
||||
it 'should return the doc to the callback', (done) ->
|
||||
@ProjectEntityHandler.addDoc = sinon.stub().callsArgWith(5, null, @doc, @folder_id)
|
||||
@EditorController.addDocWithoutLock @project_id, @folder_id, @docName, @docLines, @source, (error, doc) =>
|
||||
@EditorController.addDocWithoutLock @project_id, @folder_id, @docName, @docLines, @source, @user_id, (error, doc) =>
|
||||
doc.should.equal @doc
|
||||
done()
|
||||
|
||||
@@ -157,7 +157,7 @@ describe "EditorController", ->
|
||||
beforeEach ->
|
||||
@LockManager.getLock.callsArgWith(1)
|
||||
@LockManager.releaseLock.callsArgWith(1)
|
||||
@EditorController.addDocWithoutLock = sinon.stub().callsArgWith(5)
|
||||
@EditorController.addDocWithoutLock = sinon.stub().callsArgWith(6)
|
||||
|
||||
it "should call addDocWithoutLock", (done)->
|
||||
@EditorController.addDoc @project_id, @folder_id, @docName, @docLines, @source, =>
|
||||
|
||||
@@ -44,14 +44,14 @@ describe "FileSystemImportManager", ->
|
||||
|
||||
describe "with replace set to false", ->
|
||||
beforeEach ->
|
||||
@EditorController.addDocWithoutLock = sinon.stub().callsArg(5)
|
||||
@EditorController.addDocWithoutLock = sinon.stub().callsArg(6)
|
||||
@FileSystemImportManager.addDoc @user_id, @project_id, @folder_id, @name, @path_on_disk, false, @callback
|
||||
|
||||
it "should read the file from disk", ->
|
||||
@fs.readFile.calledWith(@path_on_disk, "utf8").should.equal true
|
||||
|
||||
it "should insert the doc", ->
|
||||
@EditorController.addDocWithoutLock.calledWith(@project_id, @folder_id, @name, @docLines, "upload")
|
||||
@EditorController.addDocWithoutLock.calledWith(@project_id, @folder_id, @name, @docLines, "upload", @user_id)
|
||||
.should.equal true
|
||||
|
||||
describe "with windows line ending", ->
|
||||
@@ -59,11 +59,11 @@ describe "FileSystemImportManager", ->
|
||||
@docContent = "one\r\ntwo\r\nthree"
|
||||
@docLines = ["one", "two", "three"]
|
||||
@fs.readFile = sinon.stub().callsArgWith(2, null, @docContent)
|
||||
@EditorController.addDocWithoutLock = sinon.stub().callsArg(5)
|
||||
@EditorController.addDocWithoutLock = sinon.stub().callsArg(6)
|
||||
@FileSystemImportManager.addDoc @user_id, @project_id, @folder_id, @name, @path_on_disk, false, @callback
|
||||
|
||||
it "should strip the \\r characters before adding", ->
|
||||
@EditorController.addDocWithoutLock.calledWith(@project_id, @folder_id, @name, @docLines, "upload")
|
||||
@EditorController.addDocWithoutLock.calledWith(@project_id, @folder_id, @name, @docLines, "upload", @user_id)
|
||||
.should.equal true
|
||||
|
||||
describe "with replace set to true", ->
|
||||
@@ -76,7 +76,7 @@ describe "FileSystemImportManager", ->
|
||||
}]
|
||||
}
|
||||
@ProjectLocator.findElement = sinon.stub().callsArgWith(1, null, @folder)
|
||||
@EditorController.addDocWithoutLock = sinon.stub().callsArg(5)
|
||||
@EditorController.addDocWithoutLock = sinon.stub().callsArg(6)
|
||||
@FileSystemImportManager.addDoc @user_id, @project_id, @folder_id, @name, @path_on_disk, true, @callback
|
||||
|
||||
it "should look up the folder", ->
|
||||
@@ -85,7 +85,7 @@ describe "FileSystemImportManager", ->
|
||||
.should.equal true
|
||||
|
||||
it "should insert the doc", ->
|
||||
@EditorController.addDocWithoutLock.calledWith(@project_id, @folder_id, @name, @docLines, "upload")
|
||||
@EditorController.addDocWithoutLock.calledWith(@project_id, @folder_id, @name, @docLines, "upload", @user_id)
|
||||
.should.equal true
|
||||
|
||||
describe "when the doc does exist", ->
|
||||
|
||||
Reference in New Issue
Block a user