Merge branch 'ja-track-changes' of github.com:sharelatex/web-sharelatex into ja-track-changes

This commit is contained in:
Paulo Reis 2017-01-09 14:30:40 +00:00
commit f0ab1fa2d4
7 changed files with 63 additions and 56 deletions

View file

@ -137,15 +137,21 @@ module.exports = DocumentUpdaterHandler =
logger.error project_id:project_id, doc_id:doc_id, url: url, "doc updater returned a non-success status code: #{res.statusCode}"
callback new Error("doc updater returned a non-success status code: #{res.statusCode}")
getNumberOfDocsInMemory : (callback)->
request.get "#{settings.apis.documentupdater.url}/total", (err, req, body)->
try
body = JSON.parse body
catch err
logger.err err:err, "error parsing response from doc updater about the total number of docs"
callback(err, body?.total)
acceptChange: (project_id, doc_id, change_id, callback = (error) ->) ->
timer = new metrics.Timer("accept-change")
url = "#{settings.apis.documentupdater.url}/project/#{project_id}/doc/#{doc_id}/change/#{change_id}/accept"
logger.log {project_id, doc_id, change_id}, "accepting change in document updater"
request.post url, (error, res, body)->
timer.done()
if error?
logger.error {err:error, project_id, doc_id, change_id}, "error accepting change in doc updater"
return callback(error)
if res.statusCode >= 200 and res.statusCode < 300
logger.log {project_id, doc_id, change_id}, "accepted change in document updater"
return callback(null)
else
logger.error {project_id, doc_id, change_id}, "doc updater returned a non-success status code: #{res.statusCode}"
callback new Error("doc updater returned a non-success status code: #{res.statusCode}")
PENDINGUPDATESKEY = "PendingUpdates"
DOCLINESKEY = "doclines"

View file

@ -1,6 +1,7 @@
RangesManager = require "./RangesManager"
logger = require "logger-sharelatex"
UserInfoController = require "../User/UserInfoController"
DocumentUpdaterHandler = require "../DocumentUpdater/DocumentUpdaterHandler"
module.exports = RangesController =
getAllRanges: (req, res, next) ->
@ -18,3 +19,10 @@ module.exports = RangesController =
return next(error) if error?
users = (UserInfoController.formatPersonalInfo(user) for user in users)
res.json users
acceptChange: (req, res, next) ->
{project_id, doc_id, change_id} = req.params
logger.log {project_id, doc_id, change_id}, "request to accept change"
DocumentUpdaterHandler.acceptChange project_id, doc_id, change_id, (error) ->
return next(error) if error?
res.send 204

View file

@ -179,6 +179,7 @@ module.exports = class Router
webRouter.get "/project/:project_id/ranges", AuthorizationMiddlewear.ensureUserCanReadProject, RangesController.getAllRanges
webRouter.get "/project/:project_id/ranges/users", AuthorizationMiddlewear.ensureUserCanReadProject, RangesController.getAllRangesUsers
webRouter.post "/project/:project_id/doc/:doc_id/changes/:change_id/accept", AuthorizationMiddlewear.ensureUserCanWriteProjectContent, RangesController.acceptChange
webRouter.get '/Project/:Project_id/download/zip', AuthorizationMiddlewear.ensureUserCanReadProject, ProjectDownloadsController.downloadProject
webRouter.get '/project/download/zip', AuthorizationMiddlewear.ensureUserCanReadMultipleProjects, ProjectDownloadsController.downloadMultipleProjects

View file

@ -340,7 +340,7 @@ define [
_applyOpsToRanges: (ops = [], oldSnapshot, msg) ->
track_changes_as = null
remote_op = msg?
if msg.meta?.tc?
if msg?.meta?.tc?
@ranges.setIdSeed(msg.meta.tc)
if remote_op and msg.meta?.tc
track_changes_as = msg.meta.user_id

View file

@ -197,8 +197,9 @@ define [
$scope.$broadcast "review-panel:recalculate-screen-positions"
$scope.$broadcast "review-panel:layout"
$scope.acceptChange = (entry_id) ->
$http.post "/project/#{$scope.project_id}/doc/#{$scope.editor.open_doc_id}/changes/#{entry_id}/accept", {_csrf: window.csrfToken}
$scope.$broadcast "change:accept", entry_id
$scope.rejectChange = (entry_id) ->

View file

@ -8,8 +8,7 @@ path = require 'path'
_ = require 'underscore'
modulePath = path.join __dirname, '../../../../app/js/Features/DocumentUpdater/DocumentUpdaterHandler'
describe 'DocumentUpdaterHandler - Flushing documents :', ->
describe 'DocumentUpdaterHandler', ->
beforeEach ->
@project_id = "project-id-923"
@doc_id = "doc-id-394"
@ -296,3 +295,38 @@ describe 'DocumentUpdaterHandler - Flushing documents :', ->
@callback
.calledWith(new Error("doc updater returned failure status code: 500"))
.should.equal true
describe "acceptChange", ->
beforeEach ->
@change_id = "mock-change-id-1"
@callback = sinon.stub()
describe "successfully", ->
beforeEach ->
@request.post = sinon.stub().callsArgWith(1, null, {statusCode: 200}, @body)
@handler.acceptChange @project_id, @doc_id, @change_id, @callback
it 'should accept the change in the document updater', ->
url = "#{@settings.apis.documentupdater.url}/project/#{@project_id}/doc/#{@doc_id}/change/#{@change_id}/accept"
@request.post.calledWith(url).should.equal true
it "should call the callback", ->
@callback.calledWith(null).should.equal true
describe "when the document updater API returns an error", ->
beforeEach ->
@request.post = sinon.stub().callsArgWith(1, @error = new Error("something went wrong"), null, null)
@handler.acceptChange @project_id, @doc_id, @change_id, @callback
it "should return an error to the callback", ->
@callback.calledWith(@error).should.equal true
describe "when the document updater returns a failure error code", ->
beforeEach ->
@request.post = sinon.stub().callsArgWith(1, null, { statusCode: 500 }, "")
@handler.acceptChange @project_id, @doc_id, @change_id, @callback
it "should return the callback with an error", ->
@callback
.calledWith(new Error("doc updater returned failure status code: 500"))
.should.equal true

View file

@ -1,43 +0,0 @@
path = require("path")
sinon = require("sinon")
SandboxedModule = require('sandboxed-module')
modulePath = path.join __dirname, '../../../../app/js/Features/DocumentUpdater/DocumentUpdaterHandler'
describe "getNumberOfDocsInMemory", ->
beforeEach ->
@host = "doc.updater"
@noOfDocs = 42
@callback = sinon.stub()
@DocumentUpdateHandler = SandboxedModule.require modulePath, requires:
"redis-sharelatex" :
createClient: () ->
auth:->
"soa-req-id": null
"logger-sharelatex": @logger =
log: sinon.stub()
error: sinon.stub()
"../../infrastructure/Metrics" : @metrics
"../../Features/Project/ProjectLocator": @ProjectLocator = {}
"../../models/Project":Project:{}
"request" : defaults: () => @request = {}
"settings-sharelatex":
apis: documentupdater: url: @host
redis: web:{}
@request.get = sinon.stub().callsArgWith(1, null, {statusCode: 200}, JSON.stringify(total: @noOfDocs))
@DocumentUpdateHandler.getNumberOfDocsInMemory @callback
it "should call the doc updater", ->
@request.get
.calledWith("#{@host}/total")
.should.equal true
it "should return the number of docs", ->
@callback
.calledWith(null, @noOfDocs)
.should.equal true