pass userId to ProjectEntityHandler.deleteEntity

This commit is contained in:
Hayden Faulds 2017-12-15 10:23:10 +00:00
parent 2ac74b9adc
commit 5f6686ed3b
4 changed files with 23 additions and 26 deletions

View file

@ -110,14 +110,14 @@ module.exports = EditorController =
if err?
logger.err err:err, project_id:project_id, "could not get lock to deleteEntity"
return callback(err)
EditorController.deleteEntityWithoutLock project_id, entity_id, entityType, source, (err)->
EditorController.deleteEntityWithoutLock project_id, entity_id, entityType, source, null, (err)->
LockManager.releaseLock project_id, ()->
callback(err)
deleteEntityWithoutLock: (project_id, entity_id, entityType, source, callback)->
deleteEntityWithoutLock: (project_id, entity_id, entityType, source, userId, callback)->
logger.log {project_id, entity_id, entityType, source}, "start delete process of entity"
Metrics.inc "editor.delete-entity"
ProjectEntityHandler.deleteEntity project_id, entity_id, entityType, (err)->
ProjectEntityHandler.deleteEntity project_id, entity_id, entityType, userId, (err)->
if err?
logger.err err:err, project_id:project_id, entity_id:entity_id, entityType:entityType, "error deleting entity"
return callback(err)

View file

@ -412,7 +412,7 @@ module.exports = ProjectEntityHandler =
callback()
deleteEntity: (project_id, entity_id, entityType, callback = (error) ->)->
deleteEntity: (project_id, entity_id, entityType, userId, callback = (error) ->)->
self = @
logger.log entity_id:entity_id, entityType:entityType, project_id:project_id, "deleting project entity"
if !entityType?
@ -423,7 +423,7 @@ module.exports = ProjectEntityHandler =
return callback(error) if error?
projectLocator.findElement {project: project, element_id: entity_id, type: entityType}, (error, entity, path)=>
return callback(error) if error?
ProjectEntityHandler._cleanUpEntity project, null, entity, entityType, path.fileSystem, (error) ->
ProjectEntityHandler._cleanUpEntity project, userId, entity, entityType, path.fileSystem, (error) ->
return callback(error) if error?
tpdsUpdateSender.deleteEntity project_id:project_id, path:path.fileSystem, project_name:project.name, (error) ->
return callback(error) if error?

View file

@ -382,11 +382,13 @@ describe "EditorController", ->
beforeEach ->
@LockManager.getLock.callsArgWith(1)
@LockManager.releaseLock.callsArgWith(1)
@EditorController.deleteEntityWithoutLock = sinon.stub().callsArgWith(4)
@EditorController.deleteEntityWithoutLock = sinon.stub().callsArgWith(5)
it "should call deleteEntityWithoutLock", (done)->
@EditorController.deleteEntity @project_id, @entity_id, @type, @source, =>
@EditorController.deleteEntityWithoutLock.calledWith(@project_id, @entity_id, @type, @source).should.equal true
@EditorController.deleteEntityWithoutLock
.calledWith(@project_id, @entity_id, @type, @source, null)
.should.equal true
done()
it "should take the lock", (done)->
@ -406,28 +408,23 @@ describe "EditorController", ->
err.should.equal "timed out"
done()
describe 'deleteEntityWithoutLock', ->
beforeEach ->
@ProjectEntityHandler.deleteEntity = (project_id, entity_id, type, callback)-> callback()
beforeEach (done) ->
@entity_id = "entity_id_here"
@type = "doc"
@EditorRealTimeController.emitToRoom = sinon.stub()
@ProjectEntityHandler.deleteEntity = sinon.stub().callsArg(4)
@EditorController.deleteEntityWithoutLock @project_id, @entity_id, @type, @source, @user_id, done
it 'should delete the folder using the project entity handler', (done)->
mock = sinon.mock(@ProjectEntityHandler).expects("deleteEntity").withArgs(@project_id, @entity_id, @type).callsArg(3)
it 'should delete the folder using the project entity handler', ->
@ProjectEntityHandler.deleteEntity
.calledWith(@project_id, @entity_id, @type, @user_id)
.should.equal.true
@EditorController.deleteEntityWithoutLock @project_id, @entity_id, @type, @source, ->
mock.verify()
done()
it 'notify users an entity has been deleted', (done)->
@EditorController.deleteEntityWithoutLock @project_id, @entity_id, @type, @source, =>
it 'notify users an entity has been deleted', ->
@EditorRealTimeController.emitToRoom
.calledWith(@project_id, "removeEntity", @entity_id, @source)
.should.equal true
done()
describe "getting a list of project paths", ->

View file

@ -163,7 +163,7 @@ describe 'ProjectEntityHandler', ->
describe "deleting from Mongo", ->
beforeEach (done) ->
@ProjectEntityHandler.deleteEntity project_id, entity_id, @type = 'file', done
@ProjectEntityHandler.deleteEntity project_id, entity_id, @type = 'file', userId, done
it "should retreive the path", ->
@projectLocator.findElement.called.should.equal true
@ -182,7 +182,7 @@ describe 'ProjectEntityHandler', ->
it "should clean up the entity from the rest of the system", ->
@ProjectEntityHandler._cleanUpEntity
.calledWith(@project, null, @entity, @type, @path.fileSystem)
.calledWith(@project, userId, @entity, @type, @path.fileSystem)
.should.equal true
describe "_cleanUpEntity", ->