mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
added lock around move element
This commit is contained in:
parent
d07e084446
commit
76b3a78988
3 changed files with 21 additions and 5 deletions
|
@ -164,10 +164,15 @@ module.exports = EditorController =
|
|||
|
||||
moveEntity: (project_id, entity_id, folder_id, entityType, callback)->
|
||||
Metrics.inc "editor.move-entity"
|
||||
LockManager.getLock project_id, (err)->
|
||||
if err?
|
||||
logger.err err:err, project_id:project_id, "could not get lock for move entity"
|
||||
return callback(err)
|
||||
ProjectEntityHandler.moveEntity project_id, entity_id, folder_id, entityType, =>
|
||||
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?()
|
||||
|
||||
|
|
|
@ -520,13 +520,13 @@ module.exports = ProjectEntityHandler =
|
|||
newPath =
|
||||
fileSystem: "#{path.fileSystem}/#{element.name}"
|
||||
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+''
|
||||
element._id = require('mongoose').Types.ObjectId(id)
|
||||
conditions = _id:project._id
|
||||
mongopath = "#{path.mongo}.#{type}"
|
||||
update = "$push":{}
|
||||
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)->
|
||||
if err?
|
||||
logger.err err: err, project_id: project._id, 'error saving in putElement project'
|
||||
|
|
|
@ -518,12 +518,23 @@ describe "EditorController", ->
|
|||
@folder_id = "313dasd21dasdsa"
|
||||
@ProjectEntityHandler.moveEntity = sinon.stub().callsArgWith(4, @err)
|
||||
@EditorRealTimeController.emitToRoom = sinon.stub()
|
||||
@LockManager.releaseLock.callsArgWith(1)
|
||||
@LockManager.getLock.callsArgWith(1)
|
||||
|
||||
it "should call the ProjectEntityHandler", (done)->
|
||||
@EditorController.moveEntity @project_id, @entity_id, @folder_id, @entityType, =>
|
||||
@ProjectEntityHandler.moveEntity.calledWith(@project_id, @entity_id, @folder_id, @entityType).should.equal true
|
||||
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)->
|
||||
@EditorController.moveEntity @project_id, @entity_id, @folder_id, @entityType, =>
|
||||
|
|
Loading…
Reference in a new issue