mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge branch 'master' of github.com:sharelatex/web-sharelatex
This commit is contained in:
commit
027c82ed6b
4 changed files with 40 additions and 14 deletions
|
@ -164,12 +164,17 @@ module.exports = EditorController =
|
||||||
|
|
||||||
moveEntity: (project_id, entity_id, folder_id, entityType, callback)->
|
moveEntity: (project_id, entity_id, folder_id, entityType, callback)->
|
||||||
Metrics.inc "editor.move-entity"
|
Metrics.inc "editor.move-entity"
|
||||||
ProjectEntityHandler.moveEntity project_id, entity_id, folder_id, entityType, =>
|
LockManager.getLock project_id, (err)->
|
||||||
if err?
|
if err?
|
||||||
logger.err err:err, project_id:project_id, entity_id:entity_id, folder_id:folder_id, "error moving entity"
|
logger.err err:err, project_id:project_id, "could not get lock for move entity"
|
||||||
return callback(err)
|
return callback(err)
|
||||||
EditorRealTimeController.emitToRoom project_id, 'reciveEntityMove', entity_id, folder_id
|
ProjectEntityHandler.moveEntity project_id, entity_id, folder_id, entityType, =>
|
||||||
callback?()
|
if err?
|
||||||
|
logger.err err:err, project_id:project_id, entity_id:entity_id, folder_id:folder_id, "error moving entity"
|
||||||
|
return callback(err)
|
||||||
|
LockManager.releaseLock project_id, ->
|
||||||
|
EditorRealTimeController.emitToRoom project_id, 'reciveEntityMove', entity_id, folder_id
|
||||||
|
callback?()
|
||||||
|
|
||||||
renameProject: (project_id, newName, callback = (err) ->) ->
|
renameProject: (project_id, newName, callback = (err) ->) ->
|
||||||
ProjectDetailsHandler.renameProject project_id, newName, ->
|
ProjectDetailsHandler.renameProject project_id, newName, ->
|
||||||
|
|
|
@ -344,15 +344,18 @@ module.exports = ProjectEntityHandler =
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
self._removeElementFromMongoArray Project, project_id, path.mongo, (err)->
|
self._removeElementFromMongoArray Project, project_id, path.mongo, (err)->
|
||||||
return callback(err) if err?
|
return callback(err) if err?
|
||||||
ProjectEntityHandler._putElement project, destinationFolder_id, entity, entityType, (err, result)->
|
# We've updated the project structure by removing the element, so must refresh it.
|
||||||
|
ProjectGetter.getProject project_id, {rootFolder:true, name:true}, (err, project)=>
|
||||||
return callback(err) if err?
|
return callback(err) if err?
|
||||||
opts =
|
ProjectEntityHandler._putElement project, destinationFolder_id, entity, entityType, (err, result)->
|
||||||
project_id:project_id
|
return callback(err) if err?
|
||||||
project_name:project.name
|
opts =
|
||||||
startPath:path.fileSystem
|
project_id:project_id
|
||||||
endPath:result.path.fileSystem,
|
project_name:project.name
|
||||||
rev:entity.rev
|
startPath:path.fileSystem
|
||||||
tpdsUpdateSender.moveEntity opts, callback
|
endPath:result.path.fileSystem,
|
||||||
|
rev:entity.rev
|
||||||
|
tpdsUpdateSender.moveEntity opts, callback
|
||||||
|
|
||||||
deleteEntity: (project_id, entity_id, entityType, callback = (error) ->)->
|
deleteEntity: (project_id, entity_id, entityType, callback = (error) ->)->
|
||||||
self = @
|
self = @
|
||||||
|
@ -501,7 +504,7 @@ module.exports = ProjectEntityHandler =
|
||||||
elementType = "fileRefs"
|
elementType = "fileRefs"
|
||||||
return elementType
|
return elementType
|
||||||
|
|
||||||
if !element?
|
if !element? or !element._id?
|
||||||
e = new Error("no element passed to be inserted")
|
e = new Error("no element passed to be inserted")
|
||||||
logger.err project_id:project._id, folder_id:folder_id, element:element, type:type, "failed trying to insert element as it was null"
|
logger.err project_id:project._id, folder_id:folder_id, element:element, type:type, "failed trying to insert element as it was null"
|
||||||
return callback(e)
|
return callback(e)
|
||||||
|
@ -520,13 +523,13 @@ module.exports = ProjectEntityHandler =
|
||||||
newPath =
|
newPath =
|
||||||
fileSystem: "#{path.fileSystem}/#{element.name}"
|
fileSystem: "#{path.fileSystem}/#{element.name}"
|
||||||
mongo: path.mongo
|
mongo: path.mongo
|
||||||
logger.log project_id: project._id, element_id: element._id, fileType: type, folder_id: folder_id, "adding element to project"
|
|
||||||
id = element._id+''
|
id = element._id+''
|
||||||
element._id = require('mongoose').Types.ObjectId(id)
|
element._id = require('mongoose').Types.ObjectId(id)
|
||||||
conditions = _id:project._id
|
conditions = _id:project._id
|
||||||
mongopath = "#{path.mongo}.#{type}"
|
mongopath = "#{path.mongo}.#{type}"
|
||||||
update = "$push":{}
|
update = "$push":{}
|
||||||
update["$push"][mongopath] = element
|
update["$push"][mongopath] = element
|
||||||
|
logger.log project_id: project._id, element_id: element._id, fileType: type, folder_id: folder_id, mongopath:mongopath, "adding element to project"
|
||||||
Project.update conditions, update, {}, (err)->
|
Project.update conditions, update, {}, (err)->
|
||||||
if err?
|
if err?
|
||||||
logger.err err: err, project_id: project._id, 'error saving in putElement project'
|
logger.err err: err, project_id: project._id, 'error saving in putElement project'
|
||||||
|
|
|
@ -518,12 +518,23 @@ describe "EditorController", ->
|
||||||
@folder_id = "313dasd21dasdsa"
|
@folder_id = "313dasd21dasdsa"
|
||||||
@ProjectEntityHandler.moveEntity = sinon.stub().callsArgWith(4, @err)
|
@ProjectEntityHandler.moveEntity = sinon.stub().callsArgWith(4, @err)
|
||||||
@EditorRealTimeController.emitToRoom = sinon.stub()
|
@EditorRealTimeController.emitToRoom = sinon.stub()
|
||||||
|
@LockManager.releaseLock.callsArgWith(1)
|
||||||
|
@LockManager.getLock.callsArgWith(1)
|
||||||
|
|
||||||
it "should call the ProjectEntityHandler", (done)->
|
it "should call the ProjectEntityHandler", (done)->
|
||||||
@EditorController.moveEntity @project_id, @entity_id, @folder_id, @entityType, =>
|
@EditorController.moveEntity @project_id, @entity_id, @folder_id, @entityType, =>
|
||||||
@ProjectEntityHandler.moveEntity.calledWith(@project_id, @entity_id, @folder_id, @entityType).should.equal true
|
@ProjectEntityHandler.moveEntity.calledWith(@project_id, @entity_id, @folder_id, @entityType).should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
it "should take the lock", (done)->
|
||||||
|
@EditorController.moveEntity @project_id, @entity_id, @folder_id, @entityType, =>
|
||||||
|
@LockManager.getLock.calledWith(@project_id).should.equal true
|
||||||
|
done()
|
||||||
|
|
||||||
|
it "should release the lock", (done)->
|
||||||
|
@EditorController.moveEntity @project_id, @entity_id, @folder_id, @entityType, =>
|
||||||
|
@LockManager.releaseLock.calledWith(@project_id).should.equal true
|
||||||
|
done()
|
||||||
|
|
||||||
it "should emit the update to the room", (done)->
|
it "should emit the update to the room", (done)->
|
||||||
@EditorController.moveEntity @project_id, @entity_id, @folder_id, @entityType, =>
|
@EditorController.moveEntity @project_id, @entity_id, @folder_id, @entityType, =>
|
||||||
|
|
|
@ -1048,6 +1048,13 @@ describe 'ProjectEntityHandler', ->
|
||||||
@projectLocator.findElement.args[0][0].element_id.should.equal @project.rootFolder[0]._id
|
@projectLocator.findElement.args[0][0].element_id.should.equal @project.rootFolder[0]._id
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
it "should error if the element has no _id", (done)->
|
||||||
|
doc =
|
||||||
|
name:"something"
|
||||||
|
@ProjectEntityHandler._putElement @project, @folder._id, doc, "doc", (err)=>
|
||||||
|
@ProjectModel.update.called.should.equal false
|
||||||
|
done()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
describe "_countElements", ->
|
describe "_countElements", ->
|
||||||
|
|
Loading…
Reference in a new issue