mirror of
https://github.com/overleaf/overleaf.git
synced 2024-09-16 02:52:31 -04:00
send licences graph request to v1 for data instead of analytics
This commit is contained in:
parent
eeadd1e9bb
commit
8d72fc78fc
5 changed files with 60 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
AnalyticsManager = require "./AnalyticsManager"
|
AnalyticsManager = require "./AnalyticsManager"
|
||||||
Errors = require "../Errors/Errors"
|
Errors = require "../Errors/Errors"
|
||||||
AuthenticationController = require("../Authentication/AuthenticationController")
|
AuthenticationController = require("../Authentication/AuthenticationController")
|
||||||
|
InstitutionsAPI = require("../Institutions/InstitutionsAPI")
|
||||||
GeoIpLookup = require '../../infrastructure/GeoIpLookup'
|
GeoIpLookup = require '../../infrastructure/GeoIpLookup'
|
||||||
|
|
||||||
module.exports = AnalyticsController =
|
module.exports = AnalyticsController =
|
||||||
|
@ -23,6 +24,15 @@ module.exports = AnalyticsController =
|
||||||
AnalyticsManager.recordEvent user_id, req.params.event, req.body, (error) ->
|
AnalyticsManager.recordEvent user_id, req.params.event, req.body, (error) ->
|
||||||
respondWith(error, res, next)
|
respondWith(error, res, next)
|
||||||
|
|
||||||
|
licences: (req, res, next) ->
|
||||||
|
AuthenticationController.getLoggedInUserId(req) or req.sessionID
|
||||||
|
{resource_id, start_date, end_date, lag} = req.query
|
||||||
|
InstitutionsAPI.getInstitutionLicences resource_id, start_date, end_date, lag, (error, licences) ->
|
||||||
|
if error?
|
||||||
|
res.send 503
|
||||||
|
else
|
||||||
|
res.send licences
|
||||||
|
|
||||||
respondWith = (error, res, next) ->
|
respondWith = (error, res, next) ->
|
||||||
if error instanceof Errors.ServiceNotConfiguredError
|
if error instanceof Errors.ServiceNotConfiguredError
|
||||||
# ignore, no-op
|
# ignore, no-op
|
||||||
|
|
|
@ -9,6 +9,8 @@ module.exports =
|
||||||
webRouter.put '/editingSession/:projectId',
|
webRouter.put '/editingSession/:projectId',
|
||||||
AnalyticsController.updateEditingSession
|
AnalyticsController.updateEditingSession
|
||||||
|
|
||||||
|
webRouter.get '/graphs/licences', AnalyticsController.licences
|
||||||
|
|
||||||
publicApiRouter.use '/analytics/graphs',
|
publicApiRouter.use '/analytics/graphs',
|
||||||
AuthenticationController.httpAuth,
|
AuthenticationController.httpAuth,
|
||||||
AnalyticsProxy.call('/graphs')
|
AnalyticsProxy.call('/graphs')
|
||||||
|
|
|
@ -11,6 +11,13 @@ module.exports = InstitutionsAPI =
|
||||||
defaultErrorMessage: "Couldn't get institution affiliations"
|
defaultErrorMessage: "Couldn't get institution affiliations"
|
||||||
}, callback
|
}, callback
|
||||||
|
|
||||||
|
getInstitutionLicences: (institutionId, startDate, endDate, lag, callback = (error, body) ->) ->
|
||||||
|
makeAffiliationRequest {
|
||||||
|
method: 'GET'
|
||||||
|
path: "/api/v2/institutions/#{institutionId.toString()}/institution_licences"
|
||||||
|
body: {start_date: startDate, end_date: endDate, lag}
|
||||||
|
defaultErrorMessage: "Couldn't get institution affiliations"
|
||||||
|
}, callback
|
||||||
|
|
||||||
getUserAffiliations: (userId, callback = (error, body) ->) ->
|
getUserAffiliations: (userId, callback = (error, body) ->) ->
|
||||||
makeAffiliationRequest {
|
makeAffiliationRequest {
|
||||||
|
|
|
@ -17,9 +17,13 @@ describe 'AnalyticsController', ->
|
||||||
updateEditingSession: sinon.stub().callsArgWith(3)
|
updateEditingSession: sinon.stub().callsArgWith(3)
|
||||||
recordEvent: sinon.stub().callsArgWith(3)
|
recordEvent: sinon.stub().callsArgWith(3)
|
||||||
|
|
||||||
|
@InstitutionsAPI =
|
||||||
|
getInstitutionLicences: sinon.stub().callsArgWith(4)
|
||||||
|
|
||||||
@controller = SandboxedModule.require modulePath, requires:
|
@controller = SandboxedModule.require modulePath, requires:
|
||||||
"./AnalyticsManager":@AnalyticsManager
|
"./AnalyticsManager":@AnalyticsManager
|
||||||
"../Authentication/AuthenticationController":@AuthenticationController
|
"../Authentication/AuthenticationController":@AuthenticationController
|
||||||
|
"../Institutions/InstitutionsAPI":@InstitutionsAPI
|
||||||
"logger-sharelatex":
|
"logger-sharelatex":
|
||||||
log:->
|
log:->
|
||||||
'../../infrastructure/GeoIpLookup': @GeoIpLookup =
|
'../../infrastructure/GeoIpLookup': @GeoIpLookup =
|
||||||
|
@ -66,3 +70,19 @@ describe 'AnalyticsController', ->
|
||||||
@controller.recordEvent @req, @res
|
@controller.recordEvent @req, @res
|
||||||
@AnalyticsManager.recordEvent.calledWith(@req.sessionID, @req.params["event"], @req.body).should.equal true
|
@AnalyticsManager.recordEvent.calledWith(@req.sessionID, @req.params["event"], @req.body).should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
describe "licences", ->
|
||||||
|
beforeEach ->
|
||||||
|
@req =
|
||||||
|
query:
|
||||||
|
resource_id:1
|
||||||
|
start_date:'1514764800'
|
||||||
|
end_date:'1530662400'
|
||||||
|
resource_type:'institution'
|
||||||
|
sessionID: "sessionIDHere"
|
||||||
|
session: {}
|
||||||
|
|
||||||
|
it "should trigger institutions api to fetch licences graph data", (done)->
|
||||||
|
@controller.licences @req, @res
|
||||||
|
@InstitutionsAPI.getInstitutionLicences.calledWith(@req.query["resource_id"], @req.query["start_date"], @req.query["end_date"], @req.query["lag"]).should.equal true
|
||||||
|
done()
|
||||||
|
|
|
@ -41,6 +41,26 @@ describe "InstitutionsAPI", ->
|
||||||
body.should.equal responseBody
|
body.should.equal responseBody
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
describe 'getInstitutionLicences', ->
|
||||||
|
it 'get licences', (done)->
|
||||||
|
@institutionId = 123
|
||||||
|
responseBody = {"lag":"monthly","data":[{"key":"users","values":[{"x":"2018-01-01","y":1}]}]}
|
||||||
|
@request.yields(null, { statusCode: 200 }, responseBody)
|
||||||
|
startDate = '1417392000'
|
||||||
|
endDate = '1420848000'
|
||||||
|
@InstitutionsAPI.getInstitutionLicences @institutionId, startDate, endDate, 'monthly', (err, body) =>
|
||||||
|
should.not.exist(err)
|
||||||
|
@request.calledOnce.should.equal true
|
||||||
|
requestOptions = @request.lastCall.args[0]
|
||||||
|
expectedUrl = "v1.url/api/v2/institutions/#{@institutionId}/institution_licences"
|
||||||
|
requestOptions.url.should.equal expectedUrl
|
||||||
|
requestOptions.method.should.equal 'GET'
|
||||||
|
requestOptions.body['start_date'].should.equal startDate
|
||||||
|
requestOptions.body['end_date'].should.equal endDate
|
||||||
|
requestOptions.body.lag.should.equal 'monthly'
|
||||||
|
body.should.equal responseBody
|
||||||
|
done()
|
||||||
|
|
||||||
describe 'getUserAffiliations', ->
|
describe 'getUserAffiliations', ->
|
||||||
it 'get affiliations', (done)->
|
it 'get affiliations', (done)->
|
||||||
responseBody = [{ foo: 'bar' }]
|
responseBody = [{ foo: 'bar' }]
|
||||||
|
|
Loading…
Reference in a new issue