From 8523c2115883c7d4f9569a04b5519fac485026b8 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Mon, 12 Feb 2024 10:36:44 +0000 Subject: [PATCH] Merge pull request #16948 from overleaf/jpa-rails-sharelatex-rebranding-step-2 [web] migrate v1 api calls away from ShareLaTeX branded endpoints GitOrigin-RevId: af08ee029d0cee8f0f171d21b4f2b0b76222b3f8 --- .../src/Features/Exports/ExportsHandler.js | 6 +-- .../Subscription/V1SubscriptionManager.js | 4 +- .../Features/Templates/TemplatesManager.js | 2 +- .../TokenAccess/TokenAccessHandler.js | 4 +- .../Features/TokenGenerator/TokenGenerator.js | 2 +- services/web/app/src/Features/V1/V1Handler.js | 4 +- services/web/scripts/ukamf/check-certs.js | 2 +- .../test/acceptance/src/mocks/MockV1Api.js | 39 +++++++++---------- .../unit/src/Exports/ExportsHandlerTests.js | 6 +-- .../src/Templates/TemplatesManagerTests.js | 2 +- .../TokenAccess/TokenAccessHandlerTests.js | 4 +- 11 files changed, 36 insertions(+), 39 deletions(-) diff --git a/services/web/app/src/Features/Exports/ExportsHandler.js b/services/web/app/src/Features/Exports/ExportsHandler.js index 9854cd3711..d55515af03 100644 --- a/services/web/app/src/Features/Exports/ExportsHandler.js +++ b/services/web/app/src/Features/Exports/ExportsHandler.js @@ -170,7 +170,7 @@ module.exports = ExportsHandler = { } return request.post( { - url: `${settings.apis.v1.url}/api/v1/sharelatex/exports`, + url: `${settings.apis.v1.url}/api/v1/overleaf/exports`, auth: { user: settings.apis.v1.user, pass: settings.apis.v1.pass }, json: exportData, timeout: settings.apis.v1.timeout, @@ -230,7 +230,7 @@ module.exports = ExportsHandler = { } return request.get( { - url: `${settings.apis.v1.url}/api/v1/sharelatex/exports/${exportId}`, + url: `${settings.apis.v1.url}/api/v1/overleaf/exports/${exportId}`, auth: { user: settings.apis.v1.user, pass: settings.apis.v1.pass }, timeout: settings.apis.v1.timeout, }, @@ -259,7 +259,7 @@ module.exports = ExportsHandler = { } return request.get( { - url: `${settings.apis.v1.url}/api/v1/sharelatex/exports/${exportId}/${type}_url`, + url: `${settings.apis.v1.url}/api/v1/overleaf/exports/${exportId}/${type}_url`, auth: { user: settings.apis.v1.user, pass: settings.apis.v1.pass }, timeout: settings.apis.v1.timeout, }, diff --git a/services/web/app/src/Features/Subscription/V1SubscriptionManager.js b/services/web/app/src/Features/Subscription/V1SubscriptionManager.js index 45731cce6c..4408079b7c 100644 --- a/services/web/app/src/Features/Subscription/V1SubscriptionManager.js +++ b/services/web/app/src/Features/Subscription/V1SubscriptionManager.js @@ -12,7 +12,7 @@ module.exports = V1SubscriptionManager = { { method: 'GET', url(v1Id) { - return `/api/v1/sharelatex/users/${v1Id}/subscriptions` + return `/api/v1/overleaf/users/${v1Id}/subscriptions` }, }, callback @@ -25,7 +25,7 @@ module.exports = V1SubscriptionManager = { { method: 'DELETE', url(v1Id) { - return `/api/v1/sharelatex/users/${v1Id}/subscription` + return `/api/v1/overleaf/users/${v1Id}/subscription` }, }, callback diff --git a/services/web/app/src/Features/Templates/TemplatesManager.js b/services/web/app/src/Features/Templates/TemplatesManager.js index 5f6ef2b4e7..baa840b2e2 100644 --- a/services/web/app/src/Features/Templates/TemplatesManager.js +++ b/services/web/app/src/Features/Templates/TemplatesManager.js @@ -28,7 +28,7 @@ const TemplatesManager = { _callback ) { const callback = _.once(_callback) - const zipUrl = `${settings.apis.v1.url}/api/v1/sharelatex/templates/${templateVersionId}` + const zipUrl = `${settings.apis.v1.url}/api/v1/overleaf/templates/${templateVersionId}` const zipReq = request(zipUrl, { auth: { user: settings.apis.v1.user, diff --git a/services/web/app/src/Features/TokenAccess/TokenAccessHandler.js b/services/web/app/src/Features/TokenAccess/TokenAccessHandler.js index a1d54afd0c..46f226789f 100644 --- a/services/web/app/src/Features/TokenAccess/TokenAccessHandler.js +++ b/services/web/app/src/Features/TokenAccess/TokenAccessHandler.js @@ -254,7 +254,7 @@ const TokenAccessHandler = { return callback(null, { allow: true }) } V1Api.request( - { url: `/api/v1/sharelatex/docs/${token}/is_published` }, + { url: `/api/v1/overleaf/docs/${token}/is_published` }, function (err, response, body) { if (err != null) { return callback(err) @@ -271,7 +271,7 @@ const TokenAccessHandler = { exported: false, }) } - const v1Url = `/api/v1/sharelatex/docs/${token}/info` + const v1Url = `/api/v1/overleaf/docs/${token}/info` V1Api.request({ url: v1Url }, function (err, response, body) { if (err != null) { return callback(err) diff --git a/services/web/app/src/Features/TokenGenerator/TokenGenerator.js b/services/web/app/src/Features/TokenGenerator/TokenGenerator.js index 883b1d5cc3..21f69cc5ec 100644 --- a/services/web/app/src/Features/TokenGenerator/TokenGenerator.js +++ b/services/web/app/src/Features/TokenGenerator/TokenGenerator.js @@ -74,7 +74,7 @@ const TokenGenerator = { return V1Api.request( { - url: `/api/v1/sharelatex/docs/read_token/${token}/exists`, + url: `/api/v1/overleaf/docs/read_token/${token}/exists`, json: true, }, function (err, response, body) { diff --git a/services/web/app/src/Features/V1/V1Handler.js b/services/web/app/src/Features/V1/V1Handler.js index 5634804b58..447a2f4635 100644 --- a/services/web/app/src/Features/V1/V1Handler.js +++ b/services/web/app/src/Features/V1/V1Handler.js @@ -21,7 +21,7 @@ module.exports = V1Handler = { return V1Api.request( { method: 'POST', - url: '/api/v1/sharelatex/login', + url: '/api/v1/overleaf/login', json: { email, password }, expectedStatusCodes: [403], }, @@ -58,7 +58,7 @@ module.exports = V1Handler = { return V1Api.request( { method: 'POST', - url: '/api/v1/sharelatex/reset_password', + url: '/api/v1/overleaf/reset_password', json: { user_id: v1UserId, password, diff --git a/services/web/scripts/ukamf/check-certs.js b/services/web/scripts/ukamf/check-certs.js index b9dc11450c..aa00530cc5 100644 --- a/services/web/scripts/ukamf/check-certs.js +++ b/services/web/scripts/ukamf/check-certs.js @@ -44,7 +44,7 @@ async function checkCert(ukamfDB, providerId) { const { body } = await V1Api.request({ json: true, qs: { university_id: providerId }, - uri: '/api/v1/sharelatex/university_saml', + uri: '/api/v1/overleaf/university_saml', }) // show notice if sso not currently enabled if (body.sso_enabled === true) { diff --git a/services/web/test/acceptance/src/mocks/MockV1Api.js b/services/web/test/acceptance/src/mocks/MockV1Api.js index 15cdb7b889..8d4d53ab70 100644 --- a/services/web/test/acceptance/src/mocks/MockV1Api.js +++ b/services/web/test/acceptance/src/mocks/MockV1Api.js @@ -156,20 +156,17 @@ class MockV1Api extends AbstractMockApi { } applyRoutes() { - this.app.get( - '/api/v1/sharelatex/users/:v1_user_id/plan_code', - (req, res) => { - const user = this.users[req.params.v1_user_id] - if (user) { - res.json(user) - } else { - res.sendStatus(404) - } + this.app.get('/api/v1/overleaf/users/:v1_user_id/plan_code', (req, res) => { + const user = this.users[req.params.v1_user_id] + if (user) { + res.json(user) + } else { + res.sendStatus(404) } - ) + }) this.app.get( - '/api/v1/sharelatex/users/:v1_user_id/subscriptions', + '/api/v1/overleaf/users/:v1_user_id/subscriptions', (req, res) => { const user = this.users[req.params.v1_user_id] if (user && user.subscription) { @@ -181,7 +178,7 @@ class MockV1Api extends AbstractMockApi { ) this.app.get( - '/api/v1/sharelatex/users/:v1_user_id/subscription_status', + '/api/v1/overleaf/users/:v1_user_id/subscription_status', (req, res) => { const user = this.users[req.params.v1_user_id] if (user && user.subscription_status) { @@ -193,7 +190,7 @@ class MockV1Api extends AbstractMockApi { ) this.app.delete( - '/api/v1/sharelatex/users/:v1_user_id/subscription', + '/api/v1/overleaf/users/:v1_user_id/subscription', (req, res) => { const user = this.users[req.params.v1_user_id] if (user) { @@ -205,12 +202,12 @@ class MockV1Api extends AbstractMockApi { } ) - this.app.post('/api/v1/sharelatex/users/:v1_user_id/sync', (req, res) => { + this.app.post('/api/v1/overleaf/users/:v1_user_id/sync', (req, res) => { this.syncUserFeatures(req.params.v1_user_id) res.sendStatus(200) }) - this.app.post('/api/v1/sharelatex/exports', (req, res) => { + this.app.post('/api/v1/overleaf/exports', (req, res) => { this.exportParams = Object.assign({}, req.body) res.json({ exportId: this.exportId }) }) @@ -370,7 +367,7 @@ class MockV1Api extends AbstractMockApi { } }) - this.app.put('/api/v1/sharelatex/users/:id/email', (req, res) => { + this.app.put('/api/v1/overleaf/users/:id/email', (req, res) => { const { email } = req.body && req.body.user if (this.existingEmails.includes(email)) { res.sendStatus(409) @@ -380,7 +377,7 @@ class MockV1Api extends AbstractMockApi { } }) - this.app.post('/api/v1/sharelatex/login', (req, res) => { + this.app.post('/api/v1/overleaf/login', (req, res) => { for (const id in this.users) { const user = this.users[id] if ( @@ -425,12 +422,12 @@ class MockV1Api extends AbstractMockApi { } }) - this.app.get('/api/v1/sharelatex/docs/:token/is_published', (req, res) => { + this.app.get('/api/v1/overleaf/docs/:token/is_published', (req, res) => { return res.json({ allow: true }) }) this.app.get( - '/api/v1/sharelatex/users/:user_id/docs/:token/info', + '/api/v1/overleaf/users/:user_id/docs/:token/info', (req, res) => { const info = this.getDocInfo(req.params.token) || { exists: false, @@ -440,7 +437,7 @@ class MockV1Api extends AbstractMockApi { } ) - this.app.get('/api/v1/sharelatex/docs/:token/info', (req, res) => { + this.app.get('/api/v1/overleaf/docs/:token/info', (req, res) => { const info = this.getDocInfo(req.params.token) || { exists: false, exported: false, @@ -449,7 +446,7 @@ class MockV1Api extends AbstractMockApi { }) this.app.get( - '/api/v1/sharelatex/docs/read_token/:token/exists', + '/api/v1/overleaf/docs/read_token/:token/exists', (req, res) => { res.json({ exists: false }) } diff --git a/services/web/test/unit/src/Exports/ExportsHandlerTests.js b/services/web/test/unit/src/Exports/ExportsHandlerTests.js index 5708f55e7a..454fc7eb61 100644 --- a/services/web/test/unit/src/Exports/ExportsHandlerTests.js +++ b/services/web/test/unit/src/Exports/ExportsHandlerTests.js @@ -531,7 +531,7 @@ describe('ExportsHandler', function () { it('should issue the request', function () { return expect(this.stubPost.getCall(0).args[0]).to.deep.equal({ - url: this.settings.apis.v1.url + '/api/v1/sharelatex/exports', + url: this.settings.apis.v1.url + '/api/v1/overleaf/exports', auth: { user: this.settings.apis.v1.user, pass: this.settings.apis.v1.pass, @@ -626,7 +626,7 @@ describe('ExportsHandler', function () { return expect(this.stubGet.getCall(0).args[0]).to.deep.equal({ url: this.settings.apis.v1.url + - '/api/v1/sharelatex/exports/' + + '/api/v1/overleaf/exports/' + this.export_id, auth: { user: this.settings.apis.v1.user, @@ -680,7 +680,7 @@ describe('ExportsHandler', function () { return expect(this.stubGet.getCall(0).args[0]).to.deep.equal({ url: this.settings.apis.v1.url + - '/api/v1/sharelatex/exports/' + + '/api/v1/overleaf/exports/' + this.export_id + '/zip_url', auth: { diff --git a/services/web/test/unit/src/Templates/TemplatesManagerTests.js b/services/web/test/unit/src/Templates/TemplatesManagerTests.js index 930b550276..38a5933615 100644 --- a/services/web/test/unit/src/Templates/TemplatesManagerTests.js +++ b/services/web/test/unit/src/Templates/TemplatesManagerTests.js @@ -121,7 +121,7 @@ describe('TemplatesManager', function () { it('should fetch zip from v1 based on template id', function () { return this.request.should.have.been.calledWith( - `${this.v1Url}/api/v1/sharelatex/templates/${this.templateVersionId}` + `${this.v1Url}/api/v1/overleaf/templates/${this.templateVersionId}` ) }) diff --git a/services/web/test/unit/src/TokenAccess/TokenAccessHandlerTests.js b/services/web/test/unit/src/TokenAccess/TokenAccessHandlerTests.js index e3e15b9792..866fb2f2c4 100644 --- a/services/web/test/unit/src/TokenAccess/TokenAccessHandlerTests.js +++ b/services/web/test/unit/src/TokenAccess/TokenAccessHandlerTests.js @@ -549,7 +549,7 @@ describe('TokenAccessHandler', function () { it('should return response body', function () { expect( this.V1Api.request.calledWith({ - url: `/api/v1/sharelatex/docs/${this.token}/is_published`, + url: `/api/v1/overleaf/docs/${this.token}/is_published`, }) ).to.equal(true) expect(this.callback.calledWith(null, 'mock-data')).to.equal(true) @@ -617,7 +617,7 @@ describe('TokenAccessHandler', function () { it('should return response body', function () { expect( this.V1Api.request.calledWith({ - url: `/api/v1/sharelatex/docs/${this.token}/info`, + url: `/api/v1/overleaf/docs/${this.token}/info`, }) ).to.equal(true) expect(this.callback.calledWith(null, 'mock-data')).to.equal(true)