pass user_id into ProjectEntityHandler.addDoc / addDocWithProject

This commit is contained in:
Hayden Faulds 2017-11-23 15:18:43 +00:00
parent bfd22899a0
commit 300f76bc5c
8 changed files with 21 additions and 21 deletions

View file

@ -32,7 +32,7 @@ module.exports = EditorController =
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, (err, doc, folder_id)=>
ProjectEntityHandler.addDoc project_id, folder_id, docName, docLines, null, (err, doc, folder_id)=>
if err?
logger.err err:err, project_id:project_id, docName:docName, "error adding doc without lock"
return callback(err)

View file

@ -52,7 +52,7 @@ module.exports = ProjectCreationHandler =
return callback(error) if error?
self._buildTemplate "mainbasic.tex", owner_id, projectName, (error, docLines)->
return callback(error) if error?
ProjectEntityHandler.addDoc project._id, project.rootFolder[0]._id, "main.tex", docLines, (error, doc)->
ProjectEntityHandler.addDoc project._id, project.rootFolder[0]._id, "main.tex", docLines, owner_id, (error, doc)->
if error?
logger.err err:error, "error adding doc when creating basic project"
return callback(error)
@ -67,13 +67,13 @@ module.exports = ProjectCreationHandler =
(callback) ->
self._buildTemplate "main.tex", owner_id, projectName, (error, docLines)->
return callback(error) if error?
ProjectEntityHandler.addDoc project._id, project.rootFolder[0]._id, "main.tex", docLines, (error, doc)->
ProjectEntityHandler.addDoc project._id, project.rootFolder[0]._id, "main.tex", docLines, owner_id, (error, doc)->
return callback(error) if error?
ProjectEntityHandler.setRootDoc project._id, doc._id, callback
(callback) ->
self._buildTemplate "references.bib", owner_id, projectName, (error, docLines)->
return callback(error) if error?
ProjectEntityHandler.addDoc project._id, project.rootFolder[0]._id, "references.bib", docLines, (error, doc)->
ProjectEntityHandler.addDoc project._id, project.rootFolder[0]._id, "references.bib", docLines, owner_id, (error, doc)->
callback(error)
(callback) ->
universePath = Path.resolve(__dirname + "/../../../templates/project_files/universe.jpg")

View file

@ -21,7 +21,7 @@ module.exports = ProjectDuplicator =
if !doc?._id?
return callback()
content = docContents[doc._id.toString()]
projectEntityHandler.addDocWithProject newProject, desFolder._id, doc.name, content.lines, (err, newDoc)->
projectEntityHandler.addDocWithProject newProject, desFolder._id, doc.name, content.lines, null, (err, newDoc)->
if err?
logger.err err:err, "error copying doc"
return callback(err)

View file

@ -149,14 +149,14 @@ module.exports = ProjectEntityHandler =
else
DocstoreManager.getDoc project_id, doc_id, options, callback
addDoc: (project_id, folder_id, docName, docLines, callback = (error, doc, folder_id) ->)=>
addDoc: (project_id, folder_id, docName, docLines, userId, callback = (error, doc, folder_id) ->)=>
ProjectGetter.getProjectWithOnlyFolders project_id, (err, project) ->
if err?
logger.err project_id:project_id, err:err, "error getting project for add doc"
return callback(err)
ProjectEntityHandler.addDocWithProject project, folder_id, docName, docLines, callback
ProjectEntityHandler.addDocWithProject project, folder_id, docName, docLines, userId, callback
addDocWithProject: (project, folder_id, docName, docLines, callback = (error, doc, folder_id) ->)=>
addDocWithProject: (project, folder_id, docName, docLines, userId, callback = (error, doc, folder_id) ->)=>
project_id = project._id
logger.log project_id: project_id, folder_id: folder_id, doc_name: docName, "adding doc to project with project"
confirmFolder project, folder_id, (folder_id)=>
@ -180,7 +180,7 @@ module.exports = ProjectEntityHandler =
doc: doc
path: result?.path?.fileSystem
docLines: docLines.join('\n')
DocumentUpdaterHandler.updateProjectStructure project_id, null, [], [newDoc], [], [], (error) ->
DocumentUpdaterHandler.updateProjectStructure project_id, userId, [], [newDoc], [], [], (error) ->
return callback(error) if error?
callback null, doc, folder_id

View file

@ -131,14 +131,14 @@ describe "EditorController", ->
@docLines = ["1234","dskl"]
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(4)
mock = sinon.mock(@ProjectEntityHandler).expects("addDoc").withArgs(@project_id, @folder_id, @docName, @docLines).callsArg(5)
@EditorController.addDocWithoutLock @project_id, @folder_id, @docName, @docLines, @source, ->
mock.verify()
done()
it 'should send the update out to the users in the project', (done)->
@ProjectEntityHandler.addDoc = sinon.stub().callsArgWith(4, null, @doc, @folder_id)
@ProjectEntityHandler.addDoc = sinon.stub().callsArgWith(5, null, @doc, @folder_id)
@EditorController.addDocWithoutLock @project_id, @folder_id, @docName, @docLines, @source, =>
@EditorRealTimeController.emitToRoom
@ -147,7 +147,7 @@ describe "EditorController", ->
done()
it 'should return the doc to the callback', (done) ->
@ProjectEntityHandler.addDoc = sinon.stub().callsArgWith(4, null, @doc, @folder_id)
@ProjectEntityHandler.addDoc = sinon.stub().callsArgWith(5, null, @doc, @folder_id)
@EditorController.addDocWithoutLock @project_id, @folder_id, @docName, @docLines, @source, (error, doc) =>
doc.should.equal @doc
done()

View file

@ -33,7 +33,7 @@ describe 'ProjectCreationHandler', ->
constructor:(options)->
{@name} = options
@ProjectEntityHandler =
addDoc: sinon.stub().callsArgWith(4, null, {_id: docId})
addDoc: sinon.stub().callsArgWith(5, null, {_id: docId})
addFile: sinon.stub().callsArg(5)
setRootDoc: sinon.stub().callsArg(2)
@ProjectDetailsHandler =
@ -149,7 +149,7 @@ describe 'ProjectCreationHandler', ->
.should.equal true
it 'should insert main.tex', ->
@ProjectEntityHandler.addDoc.calledWith(project_id, rootFolderId, "main.tex", ["mainbasic.tex", "lines"])
@ProjectEntityHandler.addDoc.calledWith(project_id, rootFolderId, "main.tex", ["mainbasic.tex", "lines"], ownerId)
.should.equal true
it 'should set the main doc id', ->
@ -180,12 +180,12 @@ describe 'ProjectCreationHandler', ->
it 'should insert main.tex', ->
@ProjectEntityHandler.addDoc
.calledWith(project_id, rootFolderId, "main.tex", ["main.tex", "lines"])
.calledWith(project_id, rootFolderId, "main.tex", ["main.tex", "lines"], ownerId)
.should.equal true
it 'should insert references.bib', ->
@ProjectEntityHandler.addDoc
.calledWith(project_id, rootFolderId, "references.bib", ["references.bib", "lines"])
.calledWith(project_id, rootFolderId, "references.bib", ["references.bib", "lines"], ownerId)
.should.equal true
it 'should insert universe.jpg', ->

View file

@ -64,7 +64,7 @@ describe 'ProjectDuplicator', ->
@projectOptionsHandler =
setCompiler : sinon.stub()
@entityHandler =
addDocWithProject: sinon.stub().callsArgWith(4, null, {name:"somDoc"})
addDocWithProject: sinon.stub().callsArgWith(5, null, {name:"somDoc"})
copyFileFromExistingProjectWithProject: sinon.stub().callsArgWith(4)
setRootDoc: sinon.stub()
addFolderWithProject: sinon.stub().callsArgWith(3, null, @newFolder)
@ -112,13 +112,13 @@ describe 'ProjectDuplicator', ->
done()
it 'should use the same compiler', (done)->
@entityHandler.addDocWithProject.callsArgWith(4, null, @rootFolder.docs[0])
@entityHandler.addDocWithProject.callsArgWith(5, null, @rootFolder.docs[0])
@duplicator.duplicate @owner, @old_project_id, "", (err, newProject)=>
@projectOptionsHandler.setCompiler.calledWith(@stubbedNewProject._id, @project.compiler).should.equal true
done()
it 'should use the same root doc', (done)->
@entityHandler.addDocWithProject.callsArgWith(4, null, @rootFolder.docs[0])
@entityHandler.addDocWithProject.callsArgWith(5, null, @rootFolder.docs[0])
@duplicator.duplicate @owner, @old_project_id, "", (err, newProject)=>
@entityHandler.setRootDoc.calledWith(@stubbedNewProject._id, @rootFolder.docs[0]._id).should.equal true
done()

View file

@ -457,7 +457,7 @@ describe 'ProjectEntityHandler', ->
@tpdsUpdateSender.addDoc = sinon.stub().callsArg(1)
@DocstoreManager.updateDoc = sinon.stub().yields(null, true, 0)
@ProjectEntityHandler.addDoc project_id, folder_id, @name, @lines, @callback
@ProjectEntityHandler.addDoc project_id, folder_id, @name, @lines, userId, @callback
# Created doc
@doc = @ProjectEntityHandler._putElement.args[0][2]
@ -492,7 +492,7 @@ describe 'ProjectEntityHandler', ->
path: @path
docLines: @lines.join('\n')
@documentUpdaterHandler.updateProjectStructure
.calledWith(project_id, null, [], [newDoc], [], [])
.calledWith(project_id, userId, [], [newDoc], [], [])
.should.equal true
describe "restoreDoc", ->