check email enabled for requiresEmailVer config
This commit is contained in:
parent
41d713446c
commit
576ad67aac
|
@ -2,6 +2,8 @@ import * as express from 'express'
|
||||||
import { body } from 'express-validator/check'
|
import { body } from 'express-validator/check'
|
||||||
import { isUserNSFWPolicyValid, isUserVideoQuotaValid, isUserVideoQuotaDailyValid } from '../../helpers/custom-validators/users'
|
import { isUserNSFWPolicyValid, isUserVideoQuotaValid, isUserVideoQuotaDailyValid } from '../../helpers/custom-validators/users'
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
|
import { CustomConfig } from '../../../shared/models/server/custom-config.model'
|
||||||
|
import { Emailer } from '../../lib/emailer'
|
||||||
import { areValidationErrors } from './utils'
|
import { areValidationErrors } from './utils'
|
||||||
|
|
||||||
const customConfigUpdateValidator = [
|
const customConfigUpdateValidator = [
|
||||||
|
@ -46,11 +48,27 @@ const customConfigUpdateValidator = [
|
||||||
logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body })
|
logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body })
|
||||||
|
|
||||||
if (areValidationErrors(req, res)) return
|
if (areValidationErrors(req, res)) return
|
||||||
|
if (!checkInvalidConfigIfEmailDisabled(req.body as CustomConfig, res)) return
|
||||||
|
|
||||||
return next()
|
return next()
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
export {
|
export {
|
||||||
customConfigUpdateValidator
|
customConfigUpdateValidator
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkInvalidConfigIfEmailDisabled (customConfig: CustomConfig, res: express.Response) {
|
||||||
|
if (Emailer.isEnabled()) return true
|
||||||
|
|
||||||
|
if (customConfig.signup.requiresEmailVerification === true) {
|
||||||
|
res.status(400)
|
||||||
|
.send({ error: 'Emailer is disabled but you require signup email verification.' })
|
||||||
|
.end()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
|
@ -167,6 +167,25 @@ describe('Test config API validators', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Should fail if email disabled and signup requires email verification', async function () {
|
||||||
|
// opposite scenario - succcess when enable enabled - covered via tests/api/users/user-verification.ts
|
||||||
|
const newUpdateParams = immutableAssign(updateParams, {
|
||||||
|
signup: {
|
||||||
|
enabled: true,
|
||||||
|
limit: 5,
|
||||||
|
requiresEmailVerification: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
await makePutBodyRequest({
|
||||||
|
url: server.url,
|
||||||
|
path,
|
||||||
|
fields: newUpdateParams,
|
||||||
|
token: server.accessToken,
|
||||||
|
statusCodeExpected: 400
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it('Should success with the correct parameters', async function () {
|
it('Should success with the correct parameters', async function () {
|
||||||
await makePutBodyRequest({
|
await makePutBodyRequest({
|
||||||
url: server.url,
|
url: server.url,
|
||||||
|
|
|
@ -81,7 +81,7 @@ function checkUpdatedConfig (data: CustomConfig) {
|
||||||
|
|
||||||
expect(data.signup.enabled).to.be.false
|
expect(data.signup.enabled).to.be.false
|
||||||
expect(data.signup.limit).to.equal(5)
|
expect(data.signup.limit).to.equal(5)
|
||||||
expect(data.signup.requiresEmailVerification).to.be.true
|
expect(data.signup.requiresEmailVerification).to.be.false
|
||||||
|
|
||||||
expect(data.admin.email).to.equal('superadmin1@example.com')
|
expect(data.admin.email).to.equal('superadmin1@example.com')
|
||||||
expect(data.contactForm.enabled).to.be.false
|
expect(data.contactForm.enabled).to.be.false
|
||||||
|
@ -186,7 +186,7 @@ describe('Test config', function () {
|
||||||
signup: {
|
signup: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
limit: 5,
|
limit: 5,
|
||||||
requiresEmailVerification: true
|
requiresEmailVerification: false
|
||||||
},
|
},
|
||||||
admin: {
|
admin: {
|
||||||
email: 'superadmin1@example.com'
|
email: 'superadmin1@example.com'
|
||||||
|
|
Loading…
Reference in New Issue