support project version on incoming requests

This commit is contained in:
Brian Gough 2018-03-05 12:14:47 +00:00
parent 4a5731440a
commit 0642e3c8c9
5 changed files with 25 additions and 16 deletions

View file

@ -161,10 +161,10 @@ module.exports = HttpController =
updateProject: (req, res, next = (error) ->) ->
timer = new Metrics.Timer("http.updateProject")
project_id = req.params.project_id
{userId, docUpdates, fileUpdates} = req.body
logger.log {project_id, docUpdates, fileUpdates}, "updating project via http"
{userId, docUpdates, fileUpdates, version} = req.body
logger.log {project_id, docUpdates, fileUpdates, version}, "updating project via http"
ProjectManager.updateProjectWithLocks project_id, userId, docUpdates, fileUpdates, (error) ->
ProjectManager.updateProjectWithLocks project_id, userId, docUpdates, fileUpdates, version, (error) ->
timer.done()
return next(error) if error?
logger.log project_id: project_id, "updated project via http"

View file

@ -14,6 +14,7 @@ module.exports = ProjectHistoryRedisManager =
meta:
user_id: user_id
ts: new Date()
version: update.version
update[entity_type] = entity_id
logger.log {project_id, update}, "queue rename operation to project-history"
@ -29,6 +30,7 @@ module.exports = ProjectHistoryRedisManager =
meta:
user_id: user_id
ts: new Date()
version: update.version
update[entity_type] = entitiy_id
logger.log {project_id, update}, "queue add operation to project-history"

View file

@ -105,16 +105,20 @@ module.exports = ProjectManager =
clearProjectState: (project_id, callback = (error) ->) ->
RedisManager.clearProjectState project_id, callback
updateProjectWithLocks: (project_id, user_id, docUpdates, fileUpdates, _callback = (error) ->) ->
updateProjectWithLocks: (project_id, user_id, docUpdates, fileUpdates, version, _callback = (error) ->) ->
timer = new Metrics.Timer("projectManager.updateProject")
callback = (args...) ->
timer.done()
_callback(args...)
project_version = version
project_subversion = 0 # project versions can have multiple operations
project_ops_length = 0
handleDocUpdate = (update, cb) ->
doc_id = update.id
update.version = "#{project_version}.#{project_subversion++}"
if update.docLines?
ProjectHistoryRedisManager.queueAddEntity project_id, 'doc', doc_id, user_id, update, (error, count) ->
project_ops_length = count
@ -126,6 +130,7 @@ module.exports = ProjectManager =
handleFileUpdate = (update, cb) ->
file_id = update.id
update.version = "#{project_version}.#{project_subversion++}"
if update.url?
ProjectHistoryRedisManager.queueAddEntity project_id, 'file', file_id, user_id, update, (error, count) ->
project_ops_length = count

View file

@ -512,19 +512,20 @@ describe "HttpController", ->
@userId = "user-id-123"
@docUpdates = sinon.stub()
@fileUpdates = sinon.stub()
@version = 1234567
@req =
body: {@userId, @docUpdates, @fileUpdates}
body: {@userId, @docUpdates, @fileUpdates, @version}
params:
project_id: @project_id
describe "successfully", ->
beforeEach ->
@ProjectManager.updateProjectWithLocks = sinon.stub().callsArgWith(4)
@ProjectManager.updateProjectWithLocks = sinon.stub().callsArgWith(5)
@HttpController.updateProject(@req, @res, @next)
it "should accept the change", ->
@ProjectManager.updateProjectWithLocks
.calledWith(@project_id, @userId, @docUpdates, @fileUpdates)
.calledWith(@project_id, @userId, @docUpdates, @fileUpdates, @version)
.should.equal true
it "should return a successful No Content response", ->
@ -537,7 +538,7 @@ describe "HttpController", ->
describe "when an errors occurs", ->
beforeEach ->
@ProjectManager.updateProjectWithLocks = sinon.stub().callsArgWith(4, new Error("oops"))
@ProjectManager.updateProjectWithLocks = sinon.stub().callsArgWith(5, new Error("oops"))
@HttpController.updateProject(@req, @res, @next)
it "should call next with the error", ->

View file

@ -18,6 +18,7 @@ describe "ProjectManager", ->
@project_id = "project-id-123"
@user_id = "user-id-123"
@version = 1234567
@HistoryManager.shouldFlushHistoryOps = sinon.stub().returns(false)
@HistoryManager.flushProjectChangesAsync = sinon.stub()
@callback = sinon.stub()
@ -45,7 +46,7 @@ describe "ProjectManager", ->
describe "successfully", ->
beforeEach ->
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @callback
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback
it "should rename the docs in the updates", ->
@DocumentManager.renameDocWithLock
@ -72,7 +73,7 @@ describe "ProjectManager", ->
beforeEach ->
@error = new Error('error')
@DocumentManager.renameDocWithLock = sinon.stub().yields(@error)
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @callback
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback
it "should call the callback with the error", ->
@callback.calledWith(@error).should.equal true
@ -81,7 +82,7 @@ describe "ProjectManager", ->
beforeEach ->
@error = new Error('error')
@ProjectHistoryRedisManager.queueRenameEntity = sinon.stub().yields(@error)
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @callback
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback
it "should call the callback with the error", ->
@callback.calledWith(@error).should.equal true
@ -89,7 +90,7 @@ describe "ProjectManager", ->
describe "with enough ops to flush", ->
beforeEach ->
@HistoryManager.shouldFlushHistoryOps = sinon.stub().returns(true)
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @callback
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback
it "should flush the history", ->
@HistoryManager.flushProjectChangesAsync
@ -113,7 +114,7 @@ describe "ProjectManager", ->
describe "successfully", ->
beforeEach ->
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @callback
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback
it "should add the docs in the updates", ->
@ProjectHistoryRedisManager.queueAddEntity
@ -140,7 +141,7 @@ describe "ProjectManager", ->
beforeEach ->
@error = new Error('error')
@ProjectHistoryRedisManager.queueAddEntity = sinon.stub().yields(@error)
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @callback
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback
it "should call the callback with the error", ->
@callback.calledWith(@error).should.equal true
@ -149,7 +150,7 @@ describe "ProjectManager", ->
beforeEach ->
@error = new Error('error')
@ProjectHistoryRedisManager.queueAddEntity = sinon.stub().yields(@error)
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @callback
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback
it "should call the callback with the error", ->
@callback.calledWith(@error).should.equal true
@ -157,7 +158,7 @@ describe "ProjectManager", ->
describe "with enough ops to flush", ->
beforeEach ->
@HistoryManager.shouldFlushHistoryOps = sinon.stub().returns(true)
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @callback
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback
it "should flush the history", ->
@HistoryManager.flushProjectChangesAsync