mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
call DocumentUpdaterHandle.updateProjectStructure from ProjectEntityHandler.addDoc and addFile
pass in user_id as null
This commit is contained in:
parent
6e84c635cf
commit
c1481d596f
2 changed files with 49 additions and 12 deletions
|
@ -177,7 +177,14 @@ module.exports = ProjectEntityHandler =
|
|||
rev: 0
|
||||
}, (err) ->
|
||||
return callback(err) if err?
|
||||
callback(null, doc, folder_id)
|
||||
newDoc =
|
||||
doc: doc
|
||||
path: result?.path?.fileSystem
|
||||
docLines: docLines.join('\n')
|
||||
documentUpdaterHandler = require('../../Features/DocumentUpdater/DocumentUpdaterHandler')
|
||||
documentUpdaterHandler.updateProjectStructure project_id, null, [], [newDoc], [], [], (error) ->
|
||||
return callback(error) if error?
|
||||
callback null, doc, folder_id
|
||||
|
||||
restoreDoc: (project_id, doc_id, name, callback = (error, doc, folder_id) ->) ->
|
||||
# getDoc will return the deleted doc's lines, but we don't actually remove
|
||||
|
@ -191,15 +198,15 @@ module.exports = ProjectEntityHandler =
|
|||
if err?
|
||||
logger.err project_id:project_id, err:err, "error getting project for add file"
|
||||
return callback(err)
|
||||
ProjectEntityHandler.addFileWithProject project, folder_id, fileName, path, callback
|
||||
ProjectEntityHandler.addFileWithProject project, folder_id, fileName, path, null, callback
|
||||
|
||||
addFileWithProject: (project, folder_id, fileName, path, callback = (error, fileRef, folder_id) ->)->
|
||||
addFileWithProject: (project, folder_id, fileName, path, userId, callback = (error, fileRef, folder_id) ->)->
|
||||
project_id = project._id
|
||||
logger.log project_id: project._id, folder_id: folder_id, file_name: fileName, path:path, "adding file"
|
||||
return callback(err) if err?
|
||||
confirmFolder project, folder_id, (folder_id)->
|
||||
fileRef = new File name : fileName
|
||||
FileStoreHandler.uploadFileFromDisk project._id, fileRef._id, path, (err)->
|
||||
FileStoreHandler.uploadFileFromDisk project._id, fileRef._id, path, (err, fileStoreUrl)->
|
||||
if err?
|
||||
logger.err err:err, project_id: project._id, folder_id: folder_id, file_name: fileName, fileRef:fileRef, "error uploading image to s3"
|
||||
return callback(err)
|
||||
|
@ -209,7 +216,14 @@ module.exports = ProjectEntityHandler =
|
|||
return callback(err)
|
||||
tpdsUpdateSender.addFile {project_id:project._id, file_id:fileRef._id, path:result?.path?.fileSystem, project_name:project.name, rev:fileRef.rev}, (err) ->
|
||||
return callback(err) if err?
|
||||
callback(null, fileRef, folder_id)
|
||||
newFile =
|
||||
file: fileRef
|
||||
path: result?.path?.fileSystem
|
||||
url: fileStoreUrl
|
||||
documentUpdaterHandler = require('../../Features/DocumentUpdater/DocumentUpdaterHandler')
|
||||
documentUpdaterHandler.updateProjectStructure project_id, userId, [], [], [], [newFile], (error) ->
|
||||
return callback(error) if error?
|
||||
callback null, fileRef, folder_id
|
||||
|
||||
replaceFile: (project_id, file_id, fsPath, callback)->
|
||||
ProjectGetter.getProject project_id, {name:true}, (err, project) ->
|
||||
|
|
|
@ -17,8 +17,9 @@ describe 'ProjectEntityHandler', ->
|
|||
userId = 1234
|
||||
|
||||
beforeEach ->
|
||||
@fileUrl = 'filestore.example.com/file'
|
||||
@FileStoreHandler =
|
||||
uploadFileFromDisk:(project_id, fileRef, localImagePath, callback)->callback()
|
||||
uploadFileFromDisk: sinon.stub().callsArgWith(3, null, @fileUrl)
|
||||
copyFile: sinon.stub().callsArgWith(4, null)
|
||||
@tpdsUpdateSender =
|
||||
addDoc:sinon.stub().callsArg(1)
|
||||
|
@ -67,6 +68,9 @@ describe 'ProjectEntityHandler', ->
|
|||
findElement : sinon.stub()
|
||||
@settings =
|
||||
maxEntitiesPerProject:200
|
||||
@documentUpdaterHandler =
|
||||
updateProjectStructure: sinon.stub().callsArg(6)
|
||||
deleteDoc: sinon.stub().callsArg(2)
|
||||
@ProjectEntityHandler = SandboxedModule.require modulePath, requires:
|
||||
'../../models/Project': Project:@ProjectModel
|
||||
'../../models/Doc': Doc:@DocModel
|
||||
|
@ -75,7 +79,7 @@ describe 'ProjectEntityHandler', ->
|
|||
'../FileStore/FileStoreHandler':@FileStoreHandler
|
||||
'../ThirdPartyDataStore/TpdsUpdateSender':@tpdsUpdateSender
|
||||
'./ProjectLocator': @projectLocator
|
||||
'../../Features/DocumentUpdater/DocumentUpdaterHandler':@documentUpdaterHandler = {}
|
||||
'../../Features/DocumentUpdater/DocumentUpdaterHandler':@documentUpdaterHandler
|
||||
'../Docstore/DocstoreManager': @DocstoreManager = {}
|
||||
'logger-sharelatex': @logger = {log:sinon.stub(), error: sinon.stub(), err:->}
|
||||
'./ProjectUpdateHandler': @projectUpdater
|
||||
|
@ -184,7 +188,6 @@ describe 'ProjectEntityHandler', ->
|
|||
describe "_cleanUpEntity", ->
|
||||
beforeEach ->
|
||||
@entity_id = "4eecaffcbffa66588e000009"
|
||||
@documentUpdaterHandler.deleteDoc = sinon.stub().callsArg(2)
|
||||
@FileStoreHandler.deleteFile = sinon.stub().callsArg(2)
|
||||
@ProjectEntityHandler.unsetRootDoc = sinon.stub().callsArg(1)
|
||||
|
||||
|
@ -240,7 +243,6 @@ describe 'ProjectEntityHandler', ->
|
|||
@ProjectEntityHandler._putElement = sinon.stub().callsArgWith(4, null, path: @pathAfterMove)
|
||||
@ProjectGetter.getProject.callsArgWith(2, null, @project)
|
||||
@tpdsUpdateSender.moveEntity = sinon.stub()
|
||||
@documentUpdaterHandler.updateProjectStructure = sinon.stub().callsArg(6)
|
||||
@ProjectEntityHandler.getAllEntitiesFromProject = sinon.stub()
|
||||
@ProjectEntityHandler.getAllEntitiesFromProject
|
||||
.onFirstCall()
|
||||
|
@ -484,6 +486,15 @@ describe 'ProjectEntityHandler', ->
|
|||
.calledWith(project_id, @doc._id.toString(), @lines)
|
||||
.should.equal true
|
||||
|
||||
it "should should send the change in project structure to the doc updater", () ->
|
||||
newDoc =
|
||||
doc: @doc
|
||||
path: @path
|
||||
docLines: @lines.join('\n')
|
||||
@documentUpdaterHandler.updateProjectStructure
|
||||
.calledWith(project_id, null, [], [newDoc], [], [])
|
||||
.should.equal true
|
||||
|
||||
describe "restoreDoc", ->
|
||||
beforeEach ->
|
||||
@name = "doc-name"
|
||||
|
@ -512,7 +523,10 @@ describe 'ProjectEntityHandler', ->
|
|||
describe 'addFile', ->
|
||||
fileName = "something.jpg"
|
||||
beforeEach ->
|
||||
@fileSystemPath = "somehintg"
|
||||
@ProjectEntityHandler._putElement = sinon.stub().callsArgWith(4, null, {path:{fileSystem: @fileSystemPath}})
|
||||
@filePath = "somewhere"
|
||||
|
||||
it 'should upload it via the FileStoreHandler', (done)->
|
||||
@FileStoreHandler.uploadFileFromDisk = (passedProject_id, file_id, filePath, callback)=>
|
||||
file_id.should.equal "file_id"
|
||||
|
@ -533,7 +547,6 @@ describe 'ProjectEntityHandler', ->
|
|||
@ProjectEntityHandler.addFile project_id, folder_id, fileName, {}, (err, fileRef, parentFolder)->
|
||||
|
||||
it 'should return doc and parent folder', (done)->
|
||||
@ProjectEntityHandler._putElement = sinon.stub().callsArgWith(4, null, {path:{fileSystem:"somehintg"}})
|
||||
@ProjectEntityHandler.addFile project_id, folder_id, fileName, {}, (err, fileRef, parentFolder)->
|
||||
parentFolder.should.equal folder_id
|
||||
fileRef.name.should.equal fileName
|
||||
|
@ -556,6 +569,18 @@ describe 'ProjectEntityHandler', ->
|
|||
|
||||
@ProjectEntityHandler.addFile project_id, folder_id, fileName, {}, (err, fileRef, parentFolder)->
|
||||
|
||||
it "should should send the change in project structure to the doc updater", (done) ->
|
||||
@documentUpdaterHandler.updateProjectStructure = (project_id, user_id, oldDocs, newDocs, oldFiles, newFiles) =>
|
||||
project_id.should.equal project_id
|
||||
newFiles.length.should.equal 1
|
||||
newFile = newFiles[0]
|
||||
newFile.file.name.should.equal fileName
|
||||
newFile.path.should.equal @fileSystemPath
|
||||
newFile.url.should.equal @fileUrl
|
||||
done()
|
||||
|
||||
@ProjectEntityHandler.addFile project_id, folder_id, fileName, {}, () ->
|
||||
|
||||
describe 'replacing a file', ->
|
||||
|
||||
beforeEach ->
|
||||
|
@ -575,12 +600,10 @@ describe 'ProjectEntityHandler', ->
|
|||
done()
|
||||
|
||||
it 'should tell the file store handler to upload the file from disk', (done)->
|
||||
@FileStoreHandler.uploadFileFromDisk = sinon.stub().callsArgWith(3)
|
||||
@ProjectEntityHandler.replaceFile project_id, @file_id, @fsPath, =>
|
||||
@FileStoreHandler.uploadFileFromDisk.calledWith(project_id, @file_id, @fsPath).should.equal true
|
||||
done()
|
||||
|
||||
|
||||
it 'should send the file to the tpds with an incremented rev', (done)->
|
||||
@tpdsUpdateSender.addFile = (options)=>
|
||||
options.project_id.should.equal project_id
|
||||
|
|
Loading…
Reference in a new issue