From cf0c8ee588e37809d85ec1deec1e4fdfa0f122a5 Mon Sep 17 00:00:00 2001 From: Chocobozzz <me@florianbigard.com> Date: Thu, 14 Oct 2021 11:35:43 +0200 Subject: Fix admin edition disabling feature --- server/initializers/config.ts | 6 +++--- server/lib/server-config-manager.ts | 10 +++++++++- server/middlewares/validators/config.ts | 3 ++- server/tests/api/server/auto-follows.ts | 4 ++++ server/tests/api/server/config.ts | 4 ++-- 5 files changed, 20 insertions(+), 7 deletions(-) (limited to 'server') diff --git a/server/initializers/config.ts b/server/initializers/config.ts index a37aae551..48bb5ab8e 100644 --- a/server/initializers/config.ts +++ b/server/initializers/config.ts @@ -206,8 +206,8 @@ const CONFIG = { }, WEBADMIN: { CONFIGURATION: { - EDITS: { - ALLOWED: config.get<boolean>('webadmin.configuration.edit.allowed') + EDITION: { + ALLOWED: config.get<boolean>('webadmin.configuration.edition.allowed') } } }, @@ -463,7 +463,7 @@ export function reloadConfig () { function getConfigDirectories () { if (process.env.NODE_CONFIG_DIR) { - return process.env.NODE_CONFIG_DIR.split(":") + return process.env.NODE_CONFIG_DIR.split(':') } return [ join(root(), 'config') ] diff --git a/server/lib/server-config-manager.ts b/server/lib/server-config-manager.ts index 58a37b56c..b78251e8c 100644 --- a/server/lib/server-config-manager.ts +++ b/server/lib/server-config-manager.ts @@ -42,7 +42,6 @@ class ServerConfigManager { const defaultTheme = getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME) return { - allowEdits: CONFIG.WEBADMIN.CONFIGURATION.EDITS.ALLOWED, client: { videos: { miniature: { @@ -50,6 +49,15 @@ class ServerConfigManager { } } }, + + webadmin: { + configuration: { + edition: { + allowed: CONFIG.WEBADMIN.CONFIGURATION.EDITION.ALLOWED + } + } + }, + instance: { name: CONFIG.INSTANCE.NAME, shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION, diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts index 5f1ac89bc..f0385ab44 100644 --- a/server/middlewares/validators/config.ts +++ b/server/middlewares/validators/config.ts @@ -106,12 +106,13 @@ const customConfigUpdateValidator = [ ] function ensureConfigIsEditable (req: express.Request, res: express.Response, next: express.NextFunction) { - if (!CONFIG.WEBADMIN.CONFIGURATION.EDITS.ALLOWED) { + if (!CONFIG.WEBADMIN.CONFIGURATION.EDITION.ALLOWED) { return res.fail({ status: HttpStatusCode.METHOD_NOT_ALLOWED_405, message: 'Server configuration is static and cannot be edited' }) } + return next() } diff --git a/server/tests/api/server/auto-follows.ts b/server/tests/api/server/auto-follows.ts index ca6475bd5..90a668edb 100644 --- a/server/tests/api/server/auto-follows.ts +++ b/server/tests/api/server/auto-follows.ts @@ -186,6 +186,10 @@ describe('Test auto follows', function () { await checkFollow(servers[0], servers[1], false) await checkFollow(servers[0], servers[2], true) }) + + after(async function () { + await instanceIndexServer.terminate() + }) }) after(async function () { diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index 8363318f6..1d996d454 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -379,14 +379,14 @@ describe('Test static config', function () { before(async function () { this.timeout(30000) - server = await createSingleServer(1, { webadmin: { configuration: { edit: { allowed: false } } } }) + server = await createSingleServer(1, { webadmin: { configuration: { edition: { allowed: false } } } }) await setAccessTokensToServers([ server ]) }) it('Should tell the client that edits are not allowed', async function () { const data = await server.config.getConfig() - expect(data.allowEdits).to.be.false + expect(data.webadmin.configuration.edition.allowed).to.be.false }) it('Should error when client tries to update', async function () { -- cgit v1.2.3