diff options
Diffstat (limited to 'server/middlewares/validators/config.ts')
-rw-r--r-- | server/middlewares/validators/config.ts | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts index 16a840667..5f1ac89bc 100644 --- a/server/middlewares/validators/config.ts +++ b/server/middlewares/validators/config.ts | |||
@@ -1,13 +1,14 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { body } from 'express-validator' | 2 | import { body } from 'express-validator' |
3 | import { isIntOrNull } from '@server/helpers/custom-validators/misc' | 3 | import { isIntOrNull } from '@server/helpers/custom-validators/misc' |
4 | import { isEmailEnabled } from '@server/initializers/config' | 4 | import { CONFIG, isEmailEnabled } from '@server/initializers/config' |
5 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' | 5 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' |
6 | import { isThemeNameValid } from '../../helpers/custom-validators/plugins' | 6 | import { isThemeNameValid } from '../../helpers/custom-validators/plugins' |
7 | import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users' | 7 | import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users' |
8 | import { logger } from '../../helpers/logger' | 8 | import { logger } from '../../helpers/logger' |
9 | import { isThemeRegistered } from '../../lib/plugins/theme-utils' | 9 | import { isThemeRegistered } from '../../lib/plugins/theme-utils' |
10 | import { areValidationErrors } from './shared' | 10 | import { areValidationErrors } from './shared' |
11 | import { HttpStatusCode } from '@shared/models/http/http-error-codes' | ||
11 | 12 | ||
12 | const customConfigUpdateValidator = [ | 13 | const customConfigUpdateValidator = [ |
13 | body('instance.name').exists().withMessage('Should have a valid instance name'), | 14 | body('instance.name').exists().withMessage('Should have a valid instance name'), |
@@ -104,10 +105,21 @@ const customConfigUpdateValidator = [ | |||
104 | } | 105 | } |
105 | ] | 106 | ] |
106 | 107 | ||
108 | function ensureConfigIsEditable (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
109 | if (!CONFIG.WEBADMIN.CONFIGURATION.EDITS.ALLOWED) { | ||
110 | return res.fail({ | ||
111 | status: HttpStatusCode.METHOD_NOT_ALLOWED_405, | ||
112 | message: 'Server configuration is static and cannot be edited' | ||
113 | }) | ||
114 | } | ||
115 | return next() | ||
116 | } | ||
117 | |||
107 | // --------------------------------------------------------------------------- | 118 | // --------------------------------------------------------------------------- |
108 | 119 | ||
109 | export { | 120 | export { |
110 | customConfigUpdateValidator | 121 | customConfigUpdateValidator, |
122 | ensureConfigIsEditable | ||
111 | } | 123 | } |
112 | 124 | ||
113 | function checkInvalidConfigIfEmailDisabled (customConfig: CustomConfig, res: express.Response) { | 125 | function checkInvalidConfigIfEmailDisabled (customConfig: CustomConfig, res: express.Response) { |