From 8d8a037e3fe9b1d2ccbc4169ce59b13000b59cb0 Mon Sep 17 00:00:00 2001 From: Jelle Besseling Date: Tue, 12 Oct 2021 13:33:44 +0200 Subject: 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 --- server/middlewares/validators/config.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'server/middlewares/validators') 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 @@ import express from 'express' import { body } from 'express-validator' import { isIntOrNull } from '@server/helpers/custom-validators/misc' -import { isEmailEnabled } from '@server/initializers/config' +import { CONFIG, isEmailEnabled } from '@server/initializers/config' import { CustomConfig } from '../../../shared/models/server/custom-config.model' import { isThemeNameValid } from '../../helpers/custom-validators/plugins' import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users' import { logger } from '../../helpers/logger' import { isThemeRegistered } from '../../lib/plugins/theme-utils' import { areValidationErrors } from './shared' +import { HttpStatusCode } from '@shared/models/http/http-error-codes' const customConfigUpdateValidator = [ body('instance.name').exists().withMessage('Should have a valid instance name'), @@ -104,10 +105,21 @@ const customConfigUpdateValidator = [ } ] +function ensureConfigIsEditable (req: express.Request, res: express.Response, next: express.NextFunction) { + if (!CONFIG.WEBADMIN.CONFIGURATION.EDITS.ALLOWED) { + return res.fail({ + status: HttpStatusCode.METHOD_NOT_ALLOWED_405, + message: 'Server configuration is static and cannot be edited' + }) + } + return next() +} + // --------------------------------------------------------------------------- export { - customConfigUpdateValidator + customConfigUpdateValidator, + ensureConfigIsEditable } function checkInvalidConfigIfEmailDisabled (customConfig: CustomConfig, res: express.Response) { -- cgit v1.2.3