diff --git a/services/web/app/coffee/Features/TrackChanges/TrackChangesController.coffee b/services/web/app/coffee/Features/TrackChanges/TrackChangesController.coffee index 1d7674e9da..f548cadde6 100644 --- a/services/web/app/coffee/Features/TrackChanges/TrackChangesController.coffee +++ b/services/web/app/coffee/Features/TrackChanges/TrackChangesController.coffee @@ -1,13 +1,21 @@ logger = require "logger-sharelatex" request = require "request" settings = require "settings-sharelatex" +AuthenticationController = require "../Authentication/AuthenticationController" module.exports = TrackChangesController = proxyToTrackChangesApi: (req, res, next = (error) ->) -> - url = settings.apis.trackchanges.url + req.url - logger.log url: url, "proxying to track-changes api" - getReq = request(url: url, method: req.method) - getReq.pipe(res) - getReq.on "error", (error) -> - logger.error err: error, "track-changes API error" - next(error) \ No newline at end of file + AuthenticationController.getLoggedInUserId req, (error, user_id) -> + return next(error) if error? + url = settings.apis.trackchanges.url + req.url + logger.log url: url, "proxying to track-changes api" + getReq = request( + url: url + method: req.method + headers: + "X-User-Id": user_id + ) + getReq.pipe(res) + getReq.on "error", (error) -> + logger.error err: error, "track-changes API error" + next(error) \ No newline at end of file diff --git a/services/web/app/views/templates.jade b/services/web/app/views/templates.jade index d63f2efeb0..04b152dbf5 100644 --- a/services/web/app/views/templates.jade +++ b/services/web/app/views/templates.jade @@ -439,14 +439,17 @@ input(type="radio",name="toVersion").change-selector-to div(class='change-description') - div(class='change-date') {{date}} - div(class='change-name') - div.color-square(style="background-color: hsl({{hue}}, 100%, 70%);") - span {{name}} + div(class='change-date') {{date}} + div {{{users}}} div(class='restore') a(href="#") Restore to here + script(type='text/template')#changeListItemUserTemplate + div(class='change-name') + div.color-square(style="background-color: hsl({{hue}}, 100%, 70%);") + span {{name}} + script(type='text/template')#changeListTemplate ul.change-list.nav.nav-pills.nav-stacked li.loading-changes Loading... diff --git a/services/web/public/coffee/pdf/PdfManager.coffee b/services/web/public/coffee/pdf/PdfManager.coffee index ee98a1b179..8315a6a311 100644 --- a/services/web/public/coffee/pdf/PdfManager.coffee +++ b/services/web/public/coffee/pdf/PdfManager.coffee @@ -143,7 +143,6 @@ define [ @view.showLog() if outputFiles? - console.log "outputFiles", outputFiles @view.showOutputFileDownloadLinks(outputFiles) fetchLogAndUpdateView: (pdfExists) -> diff --git a/services/web/public/coffee/track-changes/ChangeListView.coffee b/services/web/public/coffee/track-changes/ChangeListView.coffee index 937542d43f..36b190ee5f 100644 --- a/services/web/public/coffee/track-changes/ChangeListView.coffee +++ b/services/web/public/coffee/track-changes/ChangeListView.coffee @@ -158,24 +158,26 @@ define [ "click .restore a": "onRestoreClick" - template : $("#changeListItemTemplate").html() + templates: + item: $("#changeListItemTemplate").html() + user: $("#changeListItemUserTemplate").html() initialize: -> @render() render: -> - @$el.html Mustache.to_html(@template, @modelView()) - return this - - modelView: -> - modelView = { - hue: @model.get("user").hue() + userHtml = for user in @model.get("users") + Mustache.to_html @templates.user, { + hue: user.hue() + name: user.name() + } + data = { date: moment(parseInt(@model.get("end_ts"), 10)).calendar() - name: @model.get("user").name() + users: userHtml.join("") } - # modelView.start_ts = util.formatDate(modelView.start_ts) - # modelView.end_ts = util.formatDate(modelView.end_ts) - return modelView + + @$el.html Mustache.to_html(@templates.item, data) + return this onClick: (e) -> e.preventDefault() diff --git a/services/web/public/coffee/track-changes/TrackChangesManager.coffee b/services/web/public/coffee/track-changes/TrackChangesManager.coffee index b6b2da45a2..99265838ee 100644 --- a/services/web/public/coffee/track-changes/TrackChangesManager.coffee +++ b/services/web/public/coffee/track-changes/TrackChangesManager.coffee @@ -37,8 +37,8 @@ define [ @diff = new Diff({ project_id: @project_id doc_id: @doc_id - from: fromModel.get("version") - to: toModel.get("version") + from: fromModel.get("fromVersion") + to: toModel.get("toVersion") }) @diffView = new DiffView( model: @diff diff --git a/services/web/public/coffee/track-changes/models/Change.coffee b/services/web/public/coffee/track-changes/models/Change.coffee index 845c44d5ec..bd1913e67f 100644 --- a/services/web/public/coffee/track-changes/models/Change.coffee +++ b/services/web/public/coffee/track-changes/models/Change.coffee @@ -7,10 +7,12 @@ define [ model = { start_ts: change.meta.start_ts end_ts: change.meta.end_ts - version: change.v + fromVersion: change.fromV + toVersion: change.toV } - if change.meta.user? - model.user = User.findOrBuild(change.meta.user.id, change.meta.user) - else - model.user = User.getAnonymousUser() + model.users = [] + for user in change.meta.users or [] + model.users.push User.findOrBuild(user.id, user) + if model.users.length == 0 + model.users.push User.getAnonymousUser() return model \ No newline at end of file diff --git a/services/web/public/coffee/track-changes/models/ChangeList.coffee b/services/web/public/coffee/track-changes/models/ChangeList.coffee index cfc7673a6a..17902223d2 100644 --- a/services/web/public/coffee/track-changes/models/ChangeList.coffee +++ b/services/web/public/coffee/track-changes/models/ChangeList.coffee @@ -12,7 +12,7 @@ define [ url = "/project/#{@options.project_id}/doc/#{@options.doc_id}/updates?limit=#{@batchSize}" if @models.length > 0 last = @models[@models.length - 1] - url += "&to=#{last.get("version") - 1}" + url += "&to=#{last.get("fromVersion") - 1}" return url parse: (json) -> diff --git a/services/web/public/stylesheets/less/trackchanges.less b/services/web/public/stylesheets/less/trackchanges.less index 031356225f..584a2cbfd8 100644 --- a/services/web/public/stylesheets/less/trackchanges.less +++ b/services/web/public/stylesheets/less/trackchanges.less @@ -28,7 +28,7 @@ background-color: white; .track-changes-header { - background-color: black; + background-color: #282828; h3 { color: white; padding-left: 8px; diff --git a/services/web/test/UnitTests/coffee/TrackChanges/TrackChangesControllerTests.coffee b/services/web/test/UnitTests/coffee/TrackChanges/TrackChangesControllerTests.coffee index 9aa558a77e..ad9f1ed04a 100644 --- a/services/web/test/UnitTests/coffee/TrackChanges/TrackChangesControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/TrackChanges/TrackChangesControllerTests.coffee @@ -10,12 +10,14 @@ describe "TrackChangesController", -> "request" : @request = sinon.stub() "settings-sharelatex": @settings = {} "logger-sharelatex": @logger = {log: sinon.stub(), error: sinon.stub()} + "../Authentication/AuthenticationController": @AuthenticationController = {} describe "proxyToTrackChangesApi", -> beforeEach -> @req = { url: "/mock/url", method: "POST" } @res = "mock-res" @next = sinon.stub() + @user_id = "user-id-123" @settings.apis = trackchanges: url: "http://trackchanges.example.com" @@ -24,14 +26,22 @@ describe "TrackChangesController", -> pipe: sinon.stub() on: (event, handler) -> @events[event] = handler @request.returns @proxy + @AuthenticationController.getLoggedInUserId = sinon.stub().callsArgWith(1, null, @user_id) @TrackChangesController.proxyToTrackChangesApi @req, @res, @next describe "successfully", -> + it "should get the user id", -> + @AuthenticationController.getLoggedInUserId + .calledWith(@req) + .should.equal true + it "should call the track changes api", -> @request .calledWith({ url: "#{@settings.apis.trackchanges.url}#{@req.url}" method: @req.method + headers: + "X-User-Id": @user_id }) .should.equal true