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)
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"
ProjectEntityHandler.renameEntity project_id, entity_id, entityType, newName, userId, (err) ->
LockManager.getLock project_id, (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)
if newName.length > 0
EditorRealTimeController.emitToRoom project_id, 'reciveEntityRename', entity_id, newName
callback?()
ProjectEntityHandler.renameEntity project_id, entity_id, entityType, newName, userId, (err) ->
if err?
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)->
Metrics.inc "editor.move-entity"

View file

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