diff --git a/client/common/configuration/register.ts b/client/common/configuration/register.ts index 1e969c6a..b7fd2ed4 100644 --- a/client/common/configuration/register.ts +++ b/client/common/configuration/register.ts @@ -10,6 +10,9 @@ import { vivifyConfigurationChannel } from './logic/channel' async function registerConfiguration (clientOptions: RegisterClientOptions): Promise { const { peertubeHelpers, registerClientRoute, registerHook } = clientOptions + const settings = await peertubeHelpers.getSettings() + if (settings['disable-configuration']) { return } + registerClientRoute({ route: 'livechat/configuration', onMount: async ({ rootEl }) => { diff --git a/languages/en.yml b/languages/en.yml index fb0dc17c..bc0577e5 100644 --- a/languages/en.yml +++ b/languages/en.yml @@ -293,6 +293,17 @@ prosody_components_list_description: |
  • Only use alphanumeric characters in the secret passphrase (use at least 15 characters).
  • +experimental_warning: | + Experimental feature: this feature is still experimental. + +configuration_description: | +

    Channel advanced configuration

    + Following settings concern the advanced channel options: + users will be able to add some customization on their channels, + activate the moderation bot, ... + +disable_configuration_label: "Disable the advanced channel configuration and the chatbot" + save: "Save" cancel: "Cancel" successfully_saved: "Successfully saved" diff --git a/server/lib/middlewares/configuration/configuration.ts b/server/lib/middlewares/configuration/configuration.ts new file mode 100644 index 00000000..96cc18af --- /dev/null +++ b/server/lib/middlewares/configuration/configuration.ts @@ -0,0 +1,26 @@ +import type { RegisterServerOptions } from '@peertube/peertube-types' +import type { Request, Response, NextFunction } from 'express' +import type { RequestPromiseHandler } from '../async' + +/** + * Returns a middleware handler to check if advanced configuration is not disabled + * @param options Peertube server options + * @returns middleware function + */ +function checkConfigurationEnabledMiddleware (options: RegisterServerOptions): RequestPromiseHandler { + return async (req: Request, res: Response, next: NextFunction) => { + const settings = await options.settingsManager.getSettings([ + 'disable-configuration' + ]) + if (!settings['disable-configuration']) { + next() + return + } + options.peertubeHelpers.logger.info('Advanced Configuration is disabled, blocking the request.') + res.sendStatus(403) + } +} + +export { + checkConfigurationEnabledMiddleware +} diff --git a/server/lib/routers/api/configuration.ts b/server/lib/routers/api/configuration.ts index 4d36e342..e057127c 100644 --- a/server/lib/routers/api/configuration.ts +++ b/server/lib/routers/api/configuration.ts @@ -3,6 +3,7 @@ import type { Router, Request, Response, NextFunction } from 'express' import type { ChannelInfos } from '../../../../shared/lib/types' import { asyncMiddleware } from '../../middlewares/async' import { getCheckConfigurationChannelMiddleware } from '../../middlewares/configuration/channel' +import { checkConfigurationEnabledMiddleware } from '../../middlewares/configuration/configuration' import { getChannelConfigurationOptions, storeChannelConfigurationOptions } from '../../configuration/channel/storage' import { sanitizeChannelConfigurationOptions } from '../../configuration/channel/sanitize' @@ -11,6 +12,7 @@ async function initConfigurationApiRouter (options: RegisterServerOptions): Prom const logger = options.peertubeHelpers.logger router.get('/channel/:channelId', asyncMiddleware([ + checkConfigurationEnabledMiddleware(options), getCheckConfigurationChannelMiddleware(options), async (req: Request, res: Response, _next: NextFunction): Promise => { if (!res.locals.channelInfos) { @@ -27,6 +29,7 @@ async function initConfigurationApiRouter (options: RegisterServerOptions): Prom ])) router.post('/channel/:channelId', asyncMiddleware([ + checkConfigurationEnabledMiddleware(options), getCheckConfigurationChannelMiddleware(options), async (req: Request, res: Response, _next: NextFunction): Promise => { if (!res.locals.channelInfos) { diff --git a/server/lib/settings.ts b/server/lib/settings.ts index 62f23acb..16ccfc86 100644 --- a/server/lib/settings.ts +++ b/server/lib/settings.ts @@ -81,6 +81,26 @@ Please read private: true }) + // ********** Moderation and advances customization + registerSetting({ + type: 'html', + private: true, + descriptionHTML: loc('configuration_description') + }) + registerSetting({ + type: 'html', + private: true, + descriptionHTML: loc('experimental_warning') + }) + registerSetting({ + name: 'disable-configuration', + label: loc('disable_configuration_label'), + // descriptionHTML: loc('disable_configuration_description'), + type: 'input-checkbox', + default: false, + private: false + }) + // ********** Chat behaviour registerSetting({ type: 'html',