[web] Move confirm_university_domain to institutions module, and /api/clsi/compile/* to publish-modal module (#19797)

* Move `/api/institutions/confirm_university_domain` to institutions module

* Move `confirmDomain` to institutions module

* Move `/api/clsi/compile/*` endpoints to `publish-modal` module

* Move ApiClsiTests to publish-modal module

* Revert move of MockClsiApi. It's still needed in the main acceptance tests

GitOrigin-RevId: b59c2921e03b94546d72d21e60a688eb1ae1d05e
This commit is contained in:
Antoine Clausse 2024-08-12 09:51:12 +02:00 committed by Copybot
parent 4bb4601d9d
commit 8736bee460
4 changed files with 0 additions and 207 deletions

View file

@ -1,13 +0,0 @@
const InstitutionsManager = require('./InstitutionsManager')
module.exports = {
confirmDomain(req, res, next) {
const { hostname } = req.body
InstitutionsManager.confirmDomain(hostname, function (error) {
if (error) {
return next(error)
}
res.sendStatus(200)
})
},
}

View file

@ -15,7 +15,6 @@ const NotificationsHandler = require('../Notifications/NotificationsHandler')
const SubscriptionLocator = require('../Subscription/SubscriptionLocator')
const { Institution } = require('../../models/Institution')
const { Subscription } = require('../../models/Subscription')
const Queues = require('../../infrastructure/Queues')
const OError = require('@overleaf/o-error')
const ASYNC_LIMIT = parseInt(process.env.ASYNC_LIMIT, 10) || 5
@ -255,14 +254,6 @@ const InstitutionsManager = {
)
},
/**
* Enqueue a job for adding affiliations for when a domain is confirmed
*/
async confirmDomain(hostname) {
const queue = Queues.getQueue('confirm-institution-domain')
await queue.add({ hostname })
},
async fetchV1Data(institution) {
const url = `${Settings.apis.v1.url}/universities/list/${institution.v1Id}`
try {

View file

@ -56,7 +56,6 @@ const TokenAccessRouter = require('./Features/TokenAccess/TokenAccessRouter')
const Features = require('./infrastructure/Features')
const LinkedFilesRouter = require('./Features/LinkedFiles/LinkedFilesRouter')
const TemplatesRouter = require('./Features/Templates/TemplatesRouter')
const InstitutionsController = require('./Features/Institutions/InstitutionsController')
const UserMembershipRouter = require('./Features/UserMembership/UserMembershipRouter')
const SystemMessageController = require('./Features/SystemMessages/SystemMessageController')
const AnalyticsRegistrationSourceMiddleware = require('./Features/Analytics/AnalyticsRegistrationSourceMiddleware')
@ -1152,34 +1151,6 @@ function initialize(webRouter, privateApiRouter, publicApiRouter) {
BetaProgramController.optOut
)
// New "api" endpoints. Started as a way for v1 to call over to v2 (for
// long-term features, as opposed to the nominally temporary ones in the
// overleaf-integration module), but may expand beyond that role.
publicApiRouter.post(
'/api/clsi/compile/:submission_id',
AuthenticationController.requirePrivateApiAuth(),
CompileController.compileSubmission
)
publicApiRouter.get(
/^\/api\/clsi\/compile\/([^/]*)\/build\/([0-9a-f-]+)\/output\/(.*)$/,
function (req, res, next) {
const params = {
submission_id: req.params[0],
build_id: req.params[1],
file: req.params[2],
}
req.params = params
next()
},
AuthenticationController.requirePrivateApiAuth(),
CompileController.getFileFromClsiWithoutUser
)
publicApiRouter.post(
'/api/institutions/confirm_university_domain',
AuthenticationController.requirePrivateApiAuth(),
InstitutionsController.confirmDomain
)
webRouter.get('/chrome', function (req, res, next) {
// Match v1 behaviour - this is used for a Chrome web app
if (SessionManager.isUserLoggedIn(req.session)) {

View file

@ -1,156 +0,0 @@
/* eslint-disable
max-len,
no-unused-vars,
n/no-deprecated-api,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const { expect } = require('chai')
const request = require('./helpers/request')
const Settings = require('@overleaf/settings')
const auth = Buffer.from('overleaf:password').toString('base64')
const authedRequest = request.defaults({
headers: {
Authorization: `Basic ${auth}`,
},
})
describe('ApiClsiTests', function () {
describe('compile', function () {
beforeEach(function (done) {
this.compileSpec = {
compile: {
options: {
compiler: 'pdflatex',
timeout: 60,
},
rootResourcePath: 'main.tex',
resources: [
{
path: 'main/tex',
content:
'\\documentclass{article}\n\\begin{document}\nHello World\n\\end{document}',
},
{
path: 'image.png',
url: 'www.example.com/image.png',
modified: 123456789,
},
],
},
}
return done()
})
describe('valid request', function () {
it('returns success and a list of output files', function (done) {
return authedRequest.post(
{
uri: '/api/clsi/compile/abcd',
json: this.compileSpec,
},
(error, response, body) => {
if (error != null) {
throw error
}
expect(response.statusCode).to.equal(200)
expect(response.body).to.deep.equal({
status: 'success',
outputFiles: [
{
path: 'project.pdf',
url: '/project/abcd/build/1234/output/project.pdf',
type: 'pdf',
build: 1234,
},
{
path: 'project.log',
url: '/project/abcd/build/1234/output/project.log',
type: 'log',
build: 1234,
},
],
})
return done()
}
)
})
})
describe('unauthorized', function () {
it('returns 401', function (done) {
return request.post(
{
uri: '/api/clsi/compile/abcd',
json: this.compileSpec,
},
(error, response, body) => {
if (error != null) {
throw error
}
expect(response.statusCode).to.equal(401)
expect(response.body).to.equal('Unauthorized')
return done()
}
)
})
})
})
describe('get output', function () {
describe('valid file', function () {
it('returns the file', function (done) {
return authedRequest.get(
'/api/clsi/compile/abcd/build/1234/output/project.pdf',
(error, response, body) => {
if (error != null) {
throw error
}
expect(response.statusCode).to.equal(200)
expect(response.body).to.equal('mock-pdf')
return done()
}
)
})
})
describe('invalid file', function () {
it('returns 404', function (done) {
return authedRequest.get(
'/api/clsi/compile/abcd/build/1234/output/project.aux',
(error, response, body) => {
if (error != null) {
throw error
}
expect(response.statusCode).to.equal(404)
expect(response.body).to.not.equal('mock-pdf')
return done()
}
)
})
})
describe('unauthorized', function () {
it('returns 401', function (done) {
return request.get(
'/api/clsi/compile/abcd/build/1234/output/project.pdf',
(error, response, body) => {
if (error != null) {
throw error
}
expect(response.statusCode).to.equal(401)
expect(response.body).to.not.equal('mock-pdf')
return done()
}
)
})
})
})
})