Merge pull request #2746 from overleaf/ew-jpa-fix-deprecated-express-methods

[misc] fix express deprecations

GitOrigin-RevId: 78c730578c6a671f142837c98f98d5fd260332a5
This commit is contained in:
Miguel Serrano 2020-05-06 12:02:16 +02:00 committed by Copybot
parent 0ba6a1f11d
commit 0583f7a667
21 changed files with 65 additions and 74 deletions

View file

@ -8,7 +8,7 @@ const Features = require('../../infrastructure/Features')
module.exports = {
updateEditingSession(req, res, next) {
if (!Features.hasFeature('analytics')) {
return res.send(204)
return res.sendStatus(204)
}
const userId = AuthenticationController.getLoggedInUserId(req)
const { projectId } = req.params
@ -27,13 +27,13 @@ module.exports = {
)
})
} else {
res.send(204)
res.sendStatus(204)
}
},
recordEvent(req, res, next) {
if (!Features.hasFeature('analytics')) {
return res.send(204)
return res.sendStatus(204)
}
const userId =
AuthenticationController.getLoggedInUserId(req) || req.sessionID

View file

@ -53,7 +53,7 @@ module.exports = ChatController = {
'new-chat-message',
message
)
return res.send(204)
return res.sendStatus(204)
})
}
)

View file

@ -214,13 +214,13 @@ module.exports = CompileController = {
return rateLimit(function(err, canContinue) {
if (err != null) {
logger.err({ err }, 'error checking rate limit for pdf download')
return res.send(500)
return res.sendStatus(500)
} else if (!canContinue) {
logger.log(
{ project_id, ip: req.ip },
'rate limit hit downloading pdf'
)
return res.send(500)
return res.sendStatus(500)
} else {
return CompileController._downloadAsUser(req, function(
error,

View file

@ -106,7 +106,7 @@ module.exports = LinkedFilesController = {
linkedFileData == null ||
(linkedFileData != null ? linkedFileData.provider : undefined) == null
) {
return res.send(409)
return res.sendStatus(409)
}
const { provider } = linkedFileData
const parent_folder_id = parentFolder._id

View file

@ -35,6 +35,8 @@ module.exports = {
markNotificationAsRead(req, res) {
const user_id = AuthenticationController.getLoggedInUserId(req)
const { notification_id } = req.params
NotificationsHandler.markAsRead(user_id, notification_id, () => res.send())
NotificationsHandler.markAsRead(user_id, notification_id, () =>
res.sendStatus(200)
)
}
}

View file

@ -22,10 +22,10 @@ module.exports = {
}
RateLimiter.addCount(opts, (err, canContinue) => {
if (err != null) {
res.send(500, { message: err.message })
res.status(500).send({ message: err.message })
}
if (!canContinue) {
return res.send(429, {
return res.status(429).send({
message: req.i18n.translate('rate_limit_hit_wait')
})
}
@ -35,17 +35,17 @@ module.exports = {
{ err },
'failed to generate and email password reset token'
)
res.send(500, { message: err.message })
res.status(500).send({ message: err.message })
} else if (status === 'primary') {
res.send(200, {
res.status(200).send({
message: { text: req.i18n.translate('password_reset_email_sent') }
})
} else if (status === 'secondary') {
res.send(404, {
res.status(404).send({
message: req.i18n.translate('secondary_email_password_reset')
})
} else {
res.send(404, {
res.status(404).send({
message: req.i18n.translate('cant_find_email')
})
}

View file

@ -126,7 +126,7 @@ module.exports = AdminController = {
Settings.mongo.writeAll = true
return DocumentUpdaterHandler.flushAllDocsToMongo(function() {
logger.log('all docs have been saved to mongo')
return res.send()
return res.sendStatus(200)
})
},

View file

@ -467,9 +467,9 @@ module.exports = SubscriptionController = {
}
return SubscriptionHandler.extendTrial(subscription, 14, function(err) {
if (err != null) {
return res.send(500)
return res.sendStatus(500)
} else {
return res.send(200)
return res.sendStatus(200)
}
})
})

View file

@ -37,7 +37,7 @@ module.exports = {
)
return next(err)
}
return res.send()
return res.sendStatus(200)
}
)
},
@ -61,7 +61,7 @@ module.exports = {
)
return res.sendStatus(500)
}
return res.send()
return res.sendStatus(200)
}
)
})

View file

@ -148,7 +148,7 @@ const UserController = {
'Failed to unsubscribe user from newsletter'
)
}
res.send()
res.sendStatus(200)
})
})
},
@ -259,7 +259,7 @@ const UserController = {
{ err, userId },
'error getting user for email update'
)
return res.send(500)
return res.sendStatus(500)
}
AuthenticationController.setInSessionUser(req, {
email: user.email,

View file

@ -37,7 +37,7 @@ module.exports = UserController = {
} else if (/^[a-f0-9]{24}$/.test(userId)) {
query = { _id: ObjectId(userId) }
} else {
return res.send(400)
return res.sendStatus(400)
}
UserGetter.getUser(
@ -48,7 +48,7 @@ module.exports = UserController = {
return next(error)
}
if (!user) {
return res.send(404)
return res.sendStatus(404)
}
UserController.sendFormattedPersonalInfo(user, res, next)
}

View file

@ -126,7 +126,7 @@ module.exports = {
if (error != null) {
return next(error)
}
return res.send()
return res.sendStatus(200)
}
)
},

View file

@ -1043,7 +1043,7 @@ function initialize(webRouter, privateApiRouter, publicApiRouter) {
privateApiRouter.get('/opps-small', function(req, res, next) {
logger.err('test error occured')
res.send()
res.sendStatus(200)
})
webRouter.post('/error/client', function(req, res, next) {

View file

@ -79,7 +79,7 @@ module.exports = MockProjectHistoryApi = {
if (this.oldFiles[key] != null) {
res.send(this.oldFiles[key])
} else {
res.send(404)
res.sendStatus(404)
}
}
)
@ -99,7 +99,7 @@ module.exports = MockProjectHistoryApi = {
if (this.projectVersions[projectId] != null) {
res.json(this.projectVersions[projectId])
} else {
res.send(404)
res.sendStatus(404)
}
})
@ -109,7 +109,7 @@ module.exports = MockProjectHistoryApi = {
if (labels != null) {
res.json(labels)
} else {
res.send(404)
res.sendStatus(404)
}
})
@ -135,9 +135,9 @@ module.exports = MockProjectHistoryApi = {
: undefined
if (label != null) {
this.deleteLabel(projectId, labelId)
res.send(204)
res.sendStatus(204)
} else {
res.send(404)
res.sendStatus(404)
}
}
)

View file

@ -55,10 +55,11 @@ describe('ChatController', function() {
project_id: this.project_id
}
}
return (this.res = {
this.res = {
json: sinon.stub(),
send: sinon.stub()
})
send: sinon.stub(),
sendStatus: sinon.stub()
}
})
describe('sendMessage', function() {
@ -105,7 +106,7 @@ describe('ChatController', function() {
})
it('should return a 204 status code', function() {
return this.res.send.calledWith(204).should.equal(true)
return this.res.sendStatus.calledWith(204).should.equal(true)
})
})

View file

@ -82,7 +82,7 @@ describe('NotificationsController', function() {
it('should send a delete request when a delete has been received to mark a notification', function(done) {
return this.controller.markNotificationAsRead(this.req, {
send: () => {
sendStatus: () => {
this.handler.markAsRead
.calledWith(user_id, notification_id)
.should.equal(true)

View file

@ -2,6 +2,7 @@ const SandboxedModule = require('sandboxed-module')
const path = require('path')
const sinon = require('sinon')
const { expect } = require('chai')
const MockResponse = require('../helpers/MockResponse')
const MODULE_PATH = path.join(
__dirname,
@ -26,7 +27,7 @@ describe('PasswordResetController', function() {
session: {},
query: {}
}
this.res = {}
this.res = new MockResponse()
this.settings = {}
this.PasswordResetHandler = {
@ -71,14 +72,12 @@ describe('PasswordResetController', function() {
'primary'
)
this.RateLimiter.addCount.callsArgWith(1, null, false)
this.res.send = code => {
code.should.equal(429)
this.PasswordResetHandler.generateAndEmailResetToken
.calledWith(this.email)
.should.equal(false)
done()
}
this.PasswordResetController.requestReset(this.req, this.res)
this.PasswordResetHandler.generateAndEmailResetToken
.calledWith(this.email)
.should.equal(false)
this.res.statusCode.should.equal(429)
done()
})
it('should tell the handler to process that email', function(done) {
@ -88,14 +87,12 @@ describe('PasswordResetController', function() {
null,
'primary'
)
this.res.send = code => {
code.should.equal(200)
this.PasswordResetHandler.generateAndEmailResetToken
.calledWith(this.email)
.should.equal(true)
done()
}
this.PasswordResetController.requestReset(this.req, this.res)
this.PasswordResetHandler.generateAndEmailResetToken
.calledWith(this.email)
.should.equal(true)
this.res.statusCode.should.equal(200)
done()
})
it('should send a 500 if there is an error', function(done) {
@ -104,11 +101,9 @@ describe('PasswordResetController', function() {
1,
'error'
)
this.res.send = code => {
code.should.equal(500)
done()
}
this.PasswordResetController.requestReset(this.req, this.res)
this.res.statusCode.should.equal(500)
done()
})
it("should send a 404 if the email doesn't exist", function(done) {
@ -118,11 +113,9 @@ describe('PasswordResetController', function() {
null,
null
)
this.res.send = code => {
code.should.equal(404)
done()
}
this.PasswordResetController.requestReset(this.req, this.res)
this.res.statusCode.should.equal(404)
done()
})
it('should send a 404 if the email is registered as a secondard email', function(done) {
@ -132,11 +125,9 @@ describe('PasswordResetController', function() {
null,
'secondary'
)
this.res.send = code => {
code.should.equal(404)
done()
}
this.PasswordResetController.requestReset(this.req, this.res)
this.res.statusCode.should.equal(404)
done()
})
it('should normalize the email address', function(done) {
@ -148,14 +139,12 @@ describe('PasswordResetController', function() {
null,
'primary'
)
this.res.send = code => {
code.should.equal(200)
this.PasswordResetHandler.generateAndEmailResetToken
.calledWith(this.email.toLowerCase().trim())
.should.equal(true)
done()
}
this.PasswordResetController.requestReset(this.req, this.res)
this.PasswordResetHandler.generateAndEmailResetToken
.calledWith(this.email.toLowerCase().trim())
.should.equal(true)
this.res.statusCode.should.equal(200)
done()
})
})

View file

@ -81,7 +81,7 @@ describe('SubscriptionGroupController', function() {
this.req.entity = this.subscription
const res = {
send: () => {
sendStatus: () => {
this.GroupHandler.removeUserFromGroup
.calledWith(this.subscriptionId, userIdToRemove)
.should.equal(true)

View file

@ -267,7 +267,7 @@ describe('UserController', function() {
describe('unsubscribe', function() {
it('should send the user to unsubscribe', function(done) {
this.res.send = code => {
this.res.sendStatus = () => {
this.NewsLetterManager.unsubscribe
.calledWith(this.user)
.should.equal(true)

View file

@ -231,7 +231,7 @@ describe('UserMembershipController', function() {
it('remove user', function(done) {
return this.UserMembershipController.remove(this.req, {
send: () => {
sendStatus: () => {
sinon.assert.calledWithMatch(
this.UserMembershipHandler.removeUser,
this.subscription,

View file

@ -52,7 +52,6 @@ class MockResponse {
sendStatus(status) {
if (arguments.length < 2) {
if (typeof status !== 'number') {
const body = status
status = 200
}
}
@ -72,7 +71,7 @@ class MockResponse {
if (arguments.length < 2) {
if (typeof status !== 'number') {
body = status
status = 200
status = this.statusCode || 200
}
}
this.statusCode = status