aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators
diff options
context:
space:
mode:
authorJelle Besseling <jelle@pingiun.com>2021-10-12 13:33:44 +0200
committerGitHub <noreply@github.com>2021-10-12 13:33:44 +0200
commit8d8a037e3fe9b1d2ccbc4169ce59b13000b59cb0 (patch)
tree755ba56bc3acbd82ec195974545581c1e49aae5e /server/middlewares/validators
parentbadacdbb4a3e4a1aae4d324abc496be8e261b2ef (diff)
downloadPeerTube-8d8a037e3fe9b1d2ccbc4169ce59b13000b59cb0.tar.gz
PeerTube-8d8a037e3fe9b1d2ccbc4169ce59b13000b59cb0.tar.zst
PeerTube-8d8a037e3fe9b1d2ccbc4169ce59b13000b59cb0.zip
Allow configuration to be static/readonly (#4315)
* Allow configuration to be static/readonly * Make all components disableable * Improve disabled component styling * Rename edits allowed field in configuration * Fix CI
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r--server/middlewares/validators/config.ts16
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 @@
1import express from 'express' 1import express from 'express'
2import { body } from 'express-validator' 2import { body } from 'express-validator'
3import { isIntOrNull } from '@server/helpers/custom-validators/misc' 3import { isIntOrNull } from '@server/helpers/custom-validators/misc'
4import { isEmailEnabled } from '@server/initializers/config' 4import { CONFIG, isEmailEnabled } from '@server/initializers/config'
5import { CustomConfig } from '../../../shared/models/server/custom-config.model' 5import { CustomConfig } from '../../../shared/models/server/custom-config.model'
6import { isThemeNameValid } from '../../helpers/custom-validators/plugins' 6import { isThemeNameValid } from '../../helpers/custom-validators/plugins'
7import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users' 7import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users'
8import { logger } from '../../helpers/logger' 8import { logger } from '../../helpers/logger'
9import { isThemeRegistered } from '../../lib/plugins/theme-utils' 9import { isThemeRegistered } from '../../lib/plugins/theme-utils'
10import { areValidationErrors } from './shared' 10import { areValidationErrors } from './shared'
11import { HttpStatusCode } from '@shared/models/http/http-error-codes'
11 12
12const customConfigUpdateValidator = [ 13const 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
108function 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
109export { 120export {
110 customConfigUpdateValidator 121 customConfigUpdateValidator,
122 ensureConfigIsEditable
111} 123}
112 124
113function checkInvalidConfigIfEmailDisabled (customConfig: CustomConfig, res: express.Response) { 125function checkInvalidConfigIfEmailDisabled (customConfig: CustomConfig, res: express.Response) {