mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-04 23:27:13 +00:00
pass userId to EditorHttpController.deleteEntity
This commit is contained in:
parent
5f6686ed3b
commit
ca15fdb6eb
5 changed files with 15 additions and 16 deletions
|
@ -105,12 +105,12 @@ module.exports = EditorController =
|
|||
async.series jobs, (err)->
|
||||
callback err, newFolders, lastFolder
|
||||
|
||||
deleteEntity : (project_id, entity_id, entityType, source, callback)->
|
||||
deleteEntity : (project_id, entity_id, entityType, source, userId, callback)->
|
||||
LockManager.getLock project_id, (err)->
|
||||
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, null, (err)->
|
||||
EditorController.deleteEntityWithoutLock project_id, entity_id, entityType, source, userId, (err)->
|
||||
LockManager.releaseLock project_id, ()->
|
||||
callback(err)
|
||||
|
||||
|
|
|
@ -147,6 +147,7 @@ module.exports = EditorHttpController =
|
|||
project_id = req.params.Project_id
|
||||
entity_id = req.params.entity_id
|
||||
entity_type = req.params.entity_type
|
||||
EditorController.deleteEntity project_id, entity_id, entity_type, "editor", (error) ->
|
||||
user_id = AuthenticationController.getLoggedInUserId(req)
|
||||
EditorController.deleteEntity project_id, entity_id, entity_type, "editor", user_id, (error) ->
|
||||
return next(error) if error?
|
||||
res.sendStatus 204
|
||||
|
|
|
@ -303,14 +303,14 @@ describe "ProjectStructureChanges", ->
|
|||
updates = MockDocUpdaterApi.getProjectStructureUpdates(@example_project_id).docUpdates
|
||||
expect(updates.length).to.equal(1)
|
||||
update = updates[0]
|
||||
#expect(update.userId).to.equal(@owner._id)
|
||||
expect(update.userId).to.equal(@owner._id)
|
||||
expect(update.pathname).to.equal("/bar/foo/new.tex")
|
||||
expect(update.newPathname).to.equal("")
|
||||
|
||||
updates = MockDocUpdaterApi.getProjectStructureUpdates(@example_project_id).fileUpdates
|
||||
expect(updates.length).to.equal(1)
|
||||
update = updates[0]
|
||||
#expect(update.userId).to.equal(@owner._id)
|
||||
expect(update.userId).to.equal(@owner._id)
|
||||
expect(update.pathname).to.equal("/bar/foo/1pixel.png")
|
||||
expect(update.newPathname).to.equal("")
|
||||
|
||||
|
|
|
@ -376,36 +376,34 @@ describe "EditorController", ->
|
|||
err.should.equal "timed out"
|
||||
done()
|
||||
|
||||
|
||||
describe "deleteEntity", ->
|
||||
|
||||
beforeEach ->
|
||||
@LockManager.getLock.callsArgWith(1)
|
||||
@LockManager.releaseLock.callsArgWith(1)
|
||||
@EditorController.deleteEntityWithoutLock = sinon.stub().callsArgWith(5)
|
||||
|
||||
it "should call deleteEntityWithoutLock", (done)->
|
||||
@EditorController.deleteEntity @project_id, @entity_id, @type, @source, =>
|
||||
@EditorController.deleteEntity @project_id, @entity_id, @type, @source, @user_id, =>
|
||||
@EditorController.deleteEntityWithoutLock
|
||||
.calledWith(@project_id, @entity_id, @type, @source, null)
|
||||
.calledWith(@project_id, @entity_id, @type, @source, @user_id)
|
||||
.should.equal true
|
||||
done()
|
||||
|
||||
it "should take the lock", (done)->
|
||||
@EditorController.deleteEntity @project_id, @entity_id, @type, @source, =>
|
||||
@EditorController.deleteEntity @project_id, @entity_id, @type, @source, @user_id, =>
|
||||
@LockManager.getLock.calledWith(@project_id).should.equal true
|
||||
done()
|
||||
|
||||
it "should release the lock", (done)->
|
||||
@EditorController.deleteEntity @project_id, @entity_id, @type, @source, (error)=>
|
||||
@EditorController.deleteEntity @project_id, @entity_id, @type, @source, @user_id, (error) =>
|
||||
@LockManager.releaseLock.calledWith(@project_id).should.equal true
|
||||
done()
|
||||
|
||||
it "should error if it can't cat the lock", (done)->
|
||||
@LockManager.getLock = sinon.stub().callsArgWith(1, "timed out")
|
||||
@EditorController.deleteEntity @project_id, @entity_id, @type, @source, (err)=>
|
||||
expect(err).to.exist
|
||||
err.should.equal "timed out"
|
||||
@EditorController.deleteEntity @project_id, @entity_id, @type, @source, @user_id, (error) =>
|
||||
expect(error).to.exist
|
||||
error.should.equal "timed out"
|
||||
done()
|
||||
|
||||
describe 'deleteEntityWithoutLock', ->
|
||||
|
|
|
@ -331,12 +331,12 @@ describe "EditorHttpController", ->
|
|||
Project_id: @project_id
|
||||
entity_id: @entity_id = "entity-id-123"
|
||||
entity_type: @entity_type = "entity-type"
|
||||
@EditorController.deleteEntity = sinon.stub().callsArg(4)
|
||||
@EditorController.deleteEntity = sinon.stub().callsArg(5)
|
||||
@EditorHttpController.deleteEntity @req, @res
|
||||
|
||||
it "should call EditorController.deleteEntity", ->
|
||||
@EditorController.deleteEntity
|
||||
.calledWith(@project_id, @entity_id, @entity_type, "editor")
|
||||
.calledWith(@project_id, @entity_id, @entity_type, "editor", @userId)
|
||||
.should.equal true
|
||||
|
||||
it "should send back a success response", ->
|
||||
|
|
Loading…
Reference in a new issue