add locking for EditorController.renameEntity

This commit is contained in:
Hayden Faulds 2017-12-20 15:21:36 +00:00
parent 4dce9e36c3
commit a8818a4149
2 changed files with 33 additions and 14 deletions

View file

@ -148,13 +148,18 @@ module.exports = EditorController =
newName = sanitize.escape(newName) newName = sanitize.escape(newName)
Metrics.inc "editor.rename-entity" Metrics.inc "editor.rename-entity"
logger.log entity_id:entity_id, entity_id:entity_id, entity_id:entity_id, "reciving new name for entity for project" logger.log entity_id:entity_id, entity_id:entity_id, entity_id:entity_id, "reciving new name for entity for project"
ProjectEntityHandler.renameEntity project_id, entity_id, entityType, newName, userId, (err) -> LockManager.getLock project_id, (err)->
if err? if err?
logger.err err:err, project_id:project_id, entity_id:entity_id, entityType:entityType, newName:newName, "error renaming entity" logger.err err:err, project_id:project_id, "could not get lock for rename entity"
return callback(err) return callback(err)
if newName.length > 0 ProjectEntityHandler.renameEntity project_id, entity_id, entityType, newName, userId, (err) ->
EditorRealTimeController.emitToRoom project_id, 'reciveEntityRename', entity_id, newName if err?
callback?() logger.err err:err, project_id:project_id, entity_id:entity_id, entityType:entityType, newName:newName, "error renaming entity"
return callback(err)
LockManager.releaseLock project_id, ->
if newName.length > 0
EditorRealTimeController.emitToRoom project_id, 'reciveEntityRename', entity_id, newName
callback?()
moveEntity: (project_id, entity_id, folder_id, entityType, userId, callback)-> moveEntity: (project_id, entity_id, folder_id, entityType, userId, callback)->
Metrics.inc "editor.move-entity" Metrics.inc "editor.move-entity"

View file

@ -466,23 +466,37 @@ describe "EditorController", ->
describe "renameEntity", -> describe "renameEntity", ->
beforeEach -> beforeEach (done) ->
@entity_id = "entity_id_here" @entity_id = "entity_id_here"
@entityType = "doc" @entityType = "doc"
@newName = "bobsfile.tex" @newName = "bobsfile.tex"
@ProjectEntityHandler.renameEntity = sinon.stub().callsArg(5) @ProjectEntityHandler.renameEntity = sinon.stub().callsArg(5)
@EditorRealTimeController.emitToRoom = sinon.stub() @EditorRealTimeController.emitToRoom = sinon.stub()
it "should call the project handler", (done)-> @LockManager.releaseLock.callsArgWith(1)
@EditorController.renameEntity @project_id, @entity_id, @entityType, @newName, @user_id, => @LockManager.getLock.callsArgWith(1)
@ProjectEntityHandler.renameEntity.calledWith(@project_id, @entity_id, @entityType, @newName, @user_id).should.equal true
done()
@EditorController.renameEntity @project_id, @entity_id, @entityType, @newName, @user_id, done
it "should emit the update to the room", (done)-> it "should call the project handler", ->
@EditorController.renameEntity @project_id, @entity_id, @entityType, @newName, @user_id, => @ProjectEntityHandler.renameEntity
@EditorRealTimeController.emitToRoom.calledWith(@project_id, 'reciveEntityRename', @entity_id, @newName).should.equal true .calledWith(@project_id, @entity_id, @entityType, @newName, @user_id)
done() .should.equal true
it "should take the lock", ->
@LockManager.getLock
.calledWith(@project_id)
.should.equal true
it "should release the lock", ->
@LockManager.releaseLock
.calledWith(@project_id)
.should.equal true
it "should emit the update to the room", ->
@EditorRealTimeController.emitToRoom
.calledWith(@project_id, 'reciveEntityRename', @entity_id, @newName)
.should.equal true
describe "moveEntity", -> describe "moveEntity", ->
beforeEach -> beforeEach ->