From a8818a414928c98c99867ab38f8e8936feff49b1 Mon Sep 17 00:00:00 2001 From: Hayden Faulds Date: Wed, 20 Dec 2017 15:21:36 +0000 Subject: [PATCH] add locking for EditorController.renameEntity --- .../Features/Editor/EditorController.coffee | 15 ++++++--- .../Editor/EditorControllerTests.coffee | 32 +++++++++++++------ 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/services/web/app/coffee/Features/Editor/EditorController.coffee b/services/web/app/coffee/Features/Editor/EditorController.coffee index 4019a9f383..e24a29087a 100644 --- a/services/web/app/coffee/Features/Editor/EditorController.coffee +++ b/services/web/app/coffee/Features/Editor/EditorController.coffee @@ -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" diff --git a/services/web/test/unit/coffee/Editor/EditorControllerTests.coffee b/services/web/test/unit/coffee/Editor/EditorControllerTests.coffee index 1a8065efb1..abfaa5502a 100644 --- a/services/web/test/unit/coffee/Editor/EditorControllerTests.coffee +++ b/services/web/test/unit/coffee/Editor/EditorControllerTests.coffee @@ -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 ->