Merge pull request #9 from sharelatex/ja-track-changes

Return ranges from docupdater to client
This commit is contained in:
James Allen 2017-01-17 10:06:36 +01:00 committed by GitHub
commit e72504e6ec
6 changed files with 29 additions and 23 deletions

View file

@ -22,7 +22,7 @@ module.exports = DocumentUpdaterManager =
body = JSON.parse(body)
catch error
return callback(error)
callback null, body?.lines, body?.version, body?.ops
callback null, body?.lines, body?.version, body?.ranges, body?.ops
else if res.statusCode == 422 # Unprocessable Entity
err = new Error("doc updater could not load requested ops")
err.statusCode = res.statusCode

View file

@ -70,7 +70,7 @@ module.exports = WebsocketController =
callback()
, WebsocketController.FLUSH_IF_EMPTY_DELAY
joinDoc: (client, doc_id, fromVersion = -1, callback = (error, doclines, version, ops) ->) ->
joinDoc: (client, doc_id, fromVersion = -1, callback = (error, doclines, version, ops, ranges) ->) ->
metrics.inc "editor.join-doc"
Utils.getClientAttributes client, ["project_id", "user_id"], (error, {project_id, user_id}) ->
return callback(error) if error?
@ -79,7 +79,7 @@ module.exports = WebsocketController =
AuthorizationManager.assertClientCanViewProject client, (error) ->
return callback(error) if error?
DocumentUpdaterManager.getDocument project_id, doc_id, fromVersion, (error, lines, version, ops) ->
DocumentUpdaterManager.getDocument project_id, doc_id, fromVersion, (error, lines, version, ranges, ops) ->
return callback(error) if error?
# Encode any binary bits of data so it can go via WebSockets
# See http://ecmanaut.blogspot.co.uk/2006/07/encoding-decoding-utf8-in-javascript.html
@ -93,7 +93,7 @@ module.exports = WebsocketController =
escapedLines.push line
AuthorizationManager.addAccessToDoc client, doc_id
client.join(doc_id)
callback null, escapedLines, version, ops
callback null, escapedLines, version, ops, ranges
logger.log {user_id, project_id, doc_id, fromVersion, client_id: client.id}, "client joined doc"
leaveDoc: (client, doc_id, callback = (error) ->) ->

View file

@ -13,6 +13,7 @@ describe "joinDoc", ->
@lines = ["test", "doc", "lines"]
@version = 42
@ops = ["mock", "doc", "ops"]
@ranges = {"mock": "ranges"}
describe "when authorised readAndWrite", ->
before (done) ->
@ -24,7 +25,7 @@ describe "joinDoc", ->
cb(e)
(cb) =>
FixturesManager.setUpDoc @project_id, {@lines, @version, @ops}, (e, {@doc_id}) =>
FixturesManager.setUpDoc @project_id, {@lines, @version, @ops, @ranges}, (e, {@doc_id}) =>
cb(e)
(cb) =>
@ -43,8 +44,8 @@ describe "joinDoc", ->
.calledWith(@project_id, @doc_id, -1)
.should.equal true
it "should return the doc lines, version and ops", ->
@returnedArgs.should.deep.equal [@lines, @version, @ops]
it "should return the doc lines, version, ranges and ops", ->
@returnedArgs.should.deep.equal [@lines, @version, @ops, @ranges]
it "should have joined the doc room", (done) ->
RealTimeClient.getConnectedClient @client.socket.sessionid, (error, client) =>
@ -61,7 +62,7 @@ describe "joinDoc", ->
cb(e)
(cb) =>
FixturesManager.setUpDoc @project_id, {@lines, @version, @ops}, (e, {@doc_id}) =>
FixturesManager.setUpDoc @project_id, {@lines, @version, @ops, @ranges}, (e, {@doc_id}) =>
cb(e)
(cb) =>
@ -80,8 +81,8 @@ describe "joinDoc", ->
.calledWith(@project_id, @doc_id, -1)
.should.equal true
it "should return the doc lines, version and ops", ->
@returnedArgs.should.deep.equal [@lines, @version, @ops]
it "should return the doc lines, version, ranges and ops", ->
@returnedArgs.should.deep.equal [@lines, @version, @ops, @ranges]
it "should have joined the doc room", (done) ->
RealTimeClient.getConnectedClient @client.socket.sessionid, (error, client) =>
@ -98,7 +99,7 @@ describe "joinDoc", ->
cb(e)
(cb) =>
FixturesManager.setUpDoc @project_id, {@lines, @version, @ops}, (e, {@doc_id}) =>
FixturesManager.setUpDoc @project_id, {@lines, @version, @ops, @ranges}, (e, {@doc_id}) =>
cb(e)
(cb) =>
@ -117,8 +118,8 @@ describe "joinDoc", ->
.calledWith(@project_id, @doc_id, -1)
.should.equal true
it "should return the doc lines, version and ops", ->
@returnedArgs.should.deep.equal [@lines, @version, @ops]
it "should return the doc lines, version, ranges and ops", ->
@returnedArgs.should.deep.equal [@lines, @version, @ops, @ranges]
it "should have joined the doc room", (done) ->
RealTimeClient.getConnectedClient @client.socket.sessionid, (error, client) =>
@ -140,7 +141,7 @@ describe "joinDoc", ->
cb(e)
(cb) =>
FixturesManager.setUpDoc @project_id, {@lines, @version, @ops}, (e, {@doc_id}) =>
FixturesManager.setUpDoc @project_id, {@lines, @version, @ops, @ranges}, (e, {@doc_id}) =>
cb(e)
(cb) =>
@ -159,8 +160,8 @@ describe "joinDoc", ->
.calledWith(@project_id, @doc_id, @fromVersion)
.should.equal true
it "should return the doc lines, version and ops", ->
@returnedArgs.should.deep.equal [@lines, @version, @ops]
it "should return the doc lines, version, ranges and ops", ->
@returnedArgs.should.deep.equal [@lines, @version, @ops, @ranges]
it "should have joined the doc room", (done) ->
RealTimeClient.getConnectedClient @client.socket.sessionid, (error, client) =>

View file

@ -32,9 +32,9 @@ module.exports = FixturesManager =
options.lines ||= ["doc", "lines"]
options.version ||= 42
options.ops ||= ["mock", "ops"]
{doc_id, lines, version, ops} = options
{doc_id, lines, version, ops, ranges} = options
MockDocUpdaterServer.createMockDoc project_id, doc_id, {lines, version, ops}
MockDocUpdaterServer.createMockDoc project_id, doc_id, {lines, version, ops, ranges}
MockDocUpdaterServer.run (error) =>
throw error if error?
callback null, {project_id, doc_id, lines, version, ops}

View file

@ -20,6 +20,9 @@ describe 'DocumentUpdaterManager', ->
'logger-sharelatex': @logger = {log: sinon.stub(), error: sinon.stub(), warn: sinon.stub()}
'request': @request = {}
'redis-sharelatex' : createClient: () => @rclient
'metrics-sharelatex': @Metrics =
Timer: class Timer
done: () ->
describe "getDocument", ->
beforeEach ->
@ -31,6 +34,7 @@ describe 'DocumentUpdaterManager', ->
lines: @lines
version: @version
ops: @ops = ["mock-op-1", "mock-op-2"]
ranges: @ranges = {"mock": "ranges"}
@fromVersion = 2
@request.get = sinon.stub().callsArgWith(1, null, {statusCode: 200}, @body)
@DocumentUpdaterManager.getDocument @project_id, @doc_id, @fromVersion, @callback
@ -39,8 +43,8 @@ describe 'DocumentUpdaterManager', ->
url = "#{@settings.apis.documentupdater.url}/project/#{@project_id}/doc/#{@doc_id}?fromVersion=#{@fromVersion}"
@request.get.calledWith(url).should.equal true
it "should call the callback with the lines and version", ->
@callback.calledWith(null, @lines, @version, @ops).should.equal true
it "should call the callback with the lines, version, ranges and ops", ->
@callback.calledWith(null, @lines, @version, @ranges, @ops).should.equal true
describe "when the document updater API returns an error", ->
beforeEach ->

View file

@ -170,11 +170,12 @@ describe 'WebsocketController', ->
@doc_lines = ["doc", "lines"]
@version = 42
@ops = ["mock", "ops"]
@ranges = { "mock": "ranges" }
@client.params.project_id = @project_id
@AuthorizationManager.addAccessToDoc = sinon.stub()
@AuthorizationManager.assertClientCanViewProject = sinon.stub().callsArgWith(1, null)
@DocumentUpdaterManager.getDocument = sinon.stub().callsArgWith(3, null, @doc_lines, @version, @ops)
@DocumentUpdaterManager.getDocument = sinon.stub().callsArgWith(3, null, @doc_lines, @version, @ranges, @ops)
describe "with a fromVersion", ->
beforeEach ->
@ -201,9 +202,9 @@ describe 'WebsocketController', ->
.calledWith(@doc_id)
.should.equal true
it "should call the callback with the lines, version and ops", ->
it "should call the callback with the lines, version, ranges and ops", ->
@callback
.calledWith(null, @doc_lines, @version, @ops)
.calledWith(null, @doc_lines, @version, @ops, @ranges)
.should.equal true
it "should increment the join-doc metric", ->