From 5373fb15706cd5360c761c02b5aeb0a04706f124 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Wed, 6 Sep 2023 15:23:39 +0200 Subject: [PATCH] Renaming 'moderation' pages to 'configuration'. --- client/@types/global.d.ts | 20 +++---- client/common-client-plugin.ts | 4 +- .../logic/channel.ts | 20 +++---- .../{moderation => configuration}/register.ts | 30 +++++------ .../templates/channel.ts | 52 ++++++++++--------- .../templates/home.ts | 16 +++--- languages/en.yml | 20 +++---- .../channel/sanitize.ts | 14 ++--- .../channel/storage.ts | 38 +++++++------- .../{moderation => configuration}/channel.ts | 8 +-- server/lib/routers/api.ts | 4 +- .../api/{moderation.ts => configuration.ts} | 26 +++++----- shared/lib/types.ts | 10 ++-- 13 files changed, 132 insertions(+), 130 deletions(-) rename client/common/{moderation => configuration}/logic/channel.ts (76%) rename client/common/{moderation => configuration}/register.ts (59%) rename client/common/{moderation => configuration}/templates/channel.ts (52%) rename client/common/{moderation => configuration}/templates/home.ts (76%) rename server/lib/{moderation => configuration}/channel/sanitize.ts (78%) rename server/lib/{moderation => configuration}/channel/storage.ts (62%) rename server/lib/middlewares/{moderation => configuration}/channel.ts (85%) rename server/lib/routers/api/{moderation.ts => configuration.ts} (62%) diff --git a/client/@types/global.d.ts b/client/@types/global.d.ts index d00586ef..9f36709e 100644 --- a/client/@types/global.d.ts +++ b/client/@types/global.d.ts @@ -34,13 +34,13 @@ declare const LOC_CONNECT_USING_XMPP_HELP: string declare const LOC_SAVE: string declare const LOC_CANCEL: string declare const LOC_SUCCESSFULLY_SAVED: string -declare const LOC_MENU_MODERATION_LABEL: string -declare const LOC_LIVECHAT_MODERATION_TITLE: string -declare const LOC_LIVECHAT_MODERATION_DESC: string -declare const LOC_LIVECHAT_MODERATION_PLEASE_SELECT: string -declare const LOC_LIVECHAT_MODERATION_CHANNEL_TITLE: string -declare const LOC_LIVECHAT_MODERATION_CHANNEL_DESC: string -declare const LOC_LIVECHAT_MODERATION_CHANNEL_ENABLE_BOT_LABEL: string -declare const LOC_LIVECHAT_MODERATION_CHANNEL_BOT_OPTIONS_TITLE: string -declare const LOC_LIVECHAT_MODERATION_CHANNEL_FORBIDDEN_WORDS_LABEL: string -declare const LOC_LIVECHAT_MODERATION_CHANNEL_BANNED_JIDS_LABEL: string +declare const LOC_MENU_CONFIGURATION_LABEL: string +declare const LOC_LIVECHAT_CONFIGURATION_TITLE: string +declare const LOC_LIVECHAT_CONFIGURATION_DESC: string +declare const LOC_LIVECHAT_CONFIGURATION_PLEASE_SELECT: string +declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_TITLE: string +declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_DESC: string +declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_ENABLE_BOT_LABEL: string +declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_BOT_OPTIONS_TITLE: string +declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_LABEL: string +declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_BANNED_JIDS_LABEL: string diff --git a/client/common-client-plugin.ts b/client/common-client-plugin.ts index b72d0582..874c5f52 100644 --- a/client/common-client-plugin.ts +++ b/client/common-client-plugin.ts @@ -1,6 +1,6 @@ import type { RegisterClientOptions } from '@peertube/peertube-types/client' import type { RegisterClientFormFieldOptions } from '@peertube/peertube-types' -import { registerModeration } from './common/moderation/register' +import { registerConfiguration } from './common/configuration/register' async function register (clientOptions: RegisterClientOptions): Promise { const { peertubeHelpers, registerHook, registerVideoField } = clientOptions @@ -52,7 +52,7 @@ async function register (clientOptions: RegisterClientOptions): Promise { registerVideoField(webchatFieldOptions, { type: 'update' }) registerVideoField(webchatFieldOptions, { type: 'go-live' }) - await registerModeration(clientOptions) + await registerConfiguration(clientOptions) } export { diff --git a/client/common/moderation/logic/channel.ts b/client/common/configuration/logic/channel.ts similarity index 76% rename from client/common/moderation/logic/channel.ts rename to client/common/configuration/logic/channel.ts index 6fe3dbaa..feafa6b7 100644 --- a/client/common/moderation/logic/channel.ts +++ b/client/common/configuration/logic/channel.ts @@ -1,23 +1,23 @@ import type { RegisterClientOptions } from '@peertube/peertube-types/client' -import type { ChannelModerationOptions } from 'shared/lib/types' +import type { ChannelConfigurationOptions } from 'shared/lib/types' import { getBaseRoute } from '../../../videowatch/uri' /** - * Adds the front-end logic on the generated html for the channel moderation options. + * Adds the front-end logic on the generated html for the channel configuration options. * @param clientOptions Peertube client options * @param rootEl The root element in which the template was rendered */ -async function vivifyModerationChannel ( +async function vivifyConfigurationChannel ( clientOptions: RegisterClientOptions, rootEl: HTMLElement, channelId: string ): Promise { - const form = rootEl.querySelector('form[livechat-moderation-channel-options]') as HTMLFormElement + const form = rootEl.querySelector('form[livechat-configuration-channel-options]') as HTMLFormElement if (!form) { return } const labelSaved = await clientOptions.peertubeHelpers.translate(LOC_SUCCESSFULLY_SAVED) const labelError = await clientOptions.peertubeHelpers.translate(LOC_ERROR) const enableBotCB = form.querySelector('input[name=bot]') as HTMLInputElement - const botEnabledEl = form.querySelector('[livechat-moderation-channel-options-bot-enabled]') as HTMLElement + const botEnabledEl = form.querySelector('[livechat-configuration-channel-options-bot-enabled]') as HTMLElement const refresh: Function = () => { botEnabledEl.style.display = enableBotCB.checked ? 'initial' : 'none' @@ -25,7 +25,7 @@ async function vivifyModerationChannel ( const submitForm: Function = async () => { const data = new FormData(form) - const channelModerationOptions: ChannelModerationOptions = { + const channelConfigurationOptions: ChannelConfigurationOptions = { bot: data.get('bot') === '1', bannedJIDs: (data.get('banned_jids')?.toString() ?? '').split(/\r?\n|\r|\n/g), forbiddenWords: (data.get('forbidden_words')?.toString() ?? '').split(/\r?\n|\r|\n/g) @@ -35,16 +35,16 @@ async function vivifyModerationChannel ( headers['content-type'] = 'application/json;charset=UTF-8' const response = await fetch( - getBaseRoute(clientOptions) + '/api/moderation/channel/' + encodeURIComponent(channelId), + getBaseRoute(clientOptions) + '/api/configuration/channel/' + encodeURIComponent(channelId), { method: 'POST', headers, - body: JSON.stringify(channelModerationOptions) + body: JSON.stringify(channelConfigurationOptions) } ) if (!response.ok) { - throw new Error('Failed to save moderation options.') + throw new Error('Failed to save configuration options.') } } const toggleSubmit: Function = (disabled: boolean) => { @@ -80,5 +80,5 @@ async function vivifyModerationChannel ( } export { - vivifyModerationChannel + vivifyConfigurationChannel } diff --git a/client/common/moderation/register.ts b/client/common/configuration/register.ts similarity index 59% rename from client/common/moderation/register.ts rename to client/common/configuration/register.ts index 9c6fea32..1e969c6a 100644 --- a/client/common/moderation/register.ts +++ b/client/common/configuration/register.ts @@ -1,42 +1,42 @@ import type { RegisterClientOptions } from '@peertube/peertube-types/client' -import { renderModerationHome } from './templates/home' -import { renderModerationChannel } from './templates/channel' -import { vivifyModerationChannel } from './logic/channel' +import { renderConfigurationHome } from './templates/home' +import { renderConfigurationChannel } from './templates/channel' +import { vivifyConfigurationChannel } from './logic/channel' /** - * Registers stuff related to the moderation settings. + * Registers stuff related to the user's configuration pages. * @param clientOptions Peertube client options */ -async function registerModeration (clientOptions: RegisterClientOptions): Promise { +async function registerConfiguration (clientOptions: RegisterClientOptions): Promise { const { peertubeHelpers, registerClientRoute, registerHook } = clientOptions registerClientRoute({ - route: 'livechat/moderation', + route: 'livechat/configuration', onMount: async ({ rootEl }) => { - rootEl.innerHTML = await renderModerationHome(clientOptions) + rootEl.innerHTML = await renderConfigurationHome(clientOptions) } }) registerClientRoute({ - route: 'livechat/moderation/channel', + route: 'livechat/configuration/channel', onMount: async ({ rootEl }) => { const urlParams = new URLSearchParams(window.location.search) const channelId = urlParams.get('channelId') ?? '' - const html = await renderModerationChannel(clientOptions, channelId) + const html = await renderConfigurationChannel(clientOptions, channelId) if (!html) { - // renderModerationChannel has already used the notifier to display an error + // renderConfigurationChannel has already used the notifier to display an error rootEl.innerHTML = '' return } rootEl.innerHTML = html - await vivifyModerationChannel(clientOptions, rootEl, channelId) + await vivifyConfigurationChannel(clientOptions, rootEl, channelId) } }) registerHook({ target: 'filter:left-menu.links.create.result', handler: async (links: any) => { - // Adding the links to livechat/moderation for logged users. + // Adding the links to livechat/configuration for logged users. if (!peertubeHelpers.isLoggedIn()) { return links } if (!Array.isArray(links)) { return links } @@ -52,11 +52,11 @@ async function registerModeration (clientOptions: RegisterClientOptions): Promis if (!myLibraryLinks) { return links } if (!Array.isArray(myLibraryLinks.links)) { return links } - const label = await peertubeHelpers.translate(LOC_MENU_MODERATION_LABEL) + const label = await peertubeHelpers.translate(LOC_MENU_CONFIGURATION_LABEL) myLibraryLinks.links.push({ label, shortLabel: label, - path: '/p/livechat/moderation', + path: '/p/livechat/configuration', icon: 'live' }) return links @@ -65,5 +65,5 @@ async function registerModeration (clientOptions: RegisterClientOptions): Promis } export { - registerModeration + registerConfiguration } diff --git a/client/common/moderation/templates/channel.ts b/client/common/configuration/templates/channel.ts similarity index 52% rename from client/common/moderation/templates/channel.ts rename to client/common/configuration/templates/channel.ts index 5532366d..43d47b4d 100644 --- a/client/common/moderation/templates/channel.ts +++ b/client/common/configuration/templates/channel.ts @@ -1,16 +1,16 @@ import type { RegisterClientOptions } from '@peertube/peertube-types/client' -import type { ChannelModeration } from 'shared/lib/types' +import type { ChannelConfiguration } from 'shared/lib/types' import { getBaseRoute } from '../../../videowatch/uri' // Must use require for mustache, import seems buggy. const Mustache = require('mustache') /** - * Renders the moderation settings page for a given channel. + * Renders the configuration settings page for a given channel. * @param registerClientOptions Peertube client options * @param channelId The channel id * @returns The page content */ -async function renderModerationChannel ( +async function renderConfigurationChannel ( registerClientOptions: RegisterClientOptions, channelId: string ): Promise { @@ -22,63 +22,65 @@ async function renderModerationChannel ( } const response = await fetch( - getBaseRoute(registerClientOptions) + '/api/moderation/channel/' + encodeURIComponent(channelId), + getBaseRoute(registerClientOptions) + '/api/configuration/channel/' + encodeURIComponent(channelId), { method: 'GET', headers: peertubeHelpers.getAuthHeader() } ) if (!response.ok) { - throw new Error('Can\'t get channel moderation options.') + throw new Error('Can\'t get channel configuration options.') } - const channelModeration: ChannelModeration = await (response).json() + const channelConfiguration: ChannelConfiguration = await (response).json() - // Basic testing that channelModeration has the correct format - if ((typeof channelModeration !== 'object') || !channelModeration.channel) { - throw new Error('Invalid channel moderation options.') + // Basic testing that channelConfiguration has the correct format + if ((typeof channelConfiguration !== 'object') || !channelConfiguration.channel) { + throw new Error('Invalid channel configuration options.') } const view = { - title: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_CHANNEL_TITLE), - description: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_CHANNEL_DESC), - enableBot: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_CHANNEL_ENABLE_BOT_LABEL), - botOptions: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_CHANNEL_BOT_OPTIONS_TITLE), - forbiddenWords: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_CHANNEL_FORBIDDEN_WORDS_LABEL), - bannedJIDs: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_CHANNEL_BANNED_JIDS_LABEL), + title: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_TITLE), + description: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_DESC), + enableBot: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_ENABLE_BOT_LABEL), + botOptions: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_BOT_OPTIONS_TITLE), + forbiddenWords: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_LABEL), + bannedJIDs: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_BANNED_JIDS_LABEL), save: await peertubeHelpers.translate(LOC_SAVE), cancel: await peertubeHelpers.translate(LOC_CANCEL), - channelModeration + channelConfiguration } return Mustache.render(`
-

{{title}} {{channelModeration.channel.displayName}}

+

{{title}} {{channelConfiguration.channel.displayName}}

{{description}}

-
+
-
+
{{botOptions}}
@@ -94,5 +96,5 @@ async function renderModerationChannel ( } export { - renderModerationChannel + renderConfigurationChannel } diff --git a/client/common/moderation/templates/home.ts b/client/common/configuration/templates/home.ts similarity index 76% rename from client/common/moderation/templates/home.ts rename to client/common/configuration/templates/home.ts index 251a68e0..a86095bb 100644 --- a/client/common/moderation/templates/home.ts +++ b/client/common/configuration/templates/home.ts @@ -3,11 +3,11 @@ import type { RegisterClientOptions } from '@peertube/peertube-types/client' const Mustache = require('mustache') /** - * Renders the livechat moderation setup home page. + * Renders the livechat configuration setup home page. * @param registerClientOptions Peertube client options * @returns The page content */ -async function renderModerationHome (registerClientOptions: RegisterClientOptions): Promise { +async function renderConfigurationHome (registerClientOptions: RegisterClientOptions): Promise { const { peertubeHelpers } = registerClientOptions try { @@ -29,13 +29,13 @@ async function renderModerationHome (registerClientOptions: RegisterClientOption } for (const channel of channels.data) { - channel.livechatModerationUri = '/p/livechat/moderation/channel?channelId=' + encodeURIComponent(channel.id) + channel.livechatConfigurationUri = '/p/livechat/configuration/channel?channelId=' + encodeURIComponent(channel.id) } const view = { - title: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_TITLE), - description: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_DESC), - please_select: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_PLEASE_SELECT), + title: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_TITLE), + description: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_DESC), + please_select: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_PLEASE_SELECT), channels: channels.data } @@ -47,7 +47,7 @@ async function renderModerationHome (registerClientOptions: RegisterClientOption
    {{#channels}}
  • - + {{displayName}}
  • @@ -62,5 +62,5 @@ async function renderModerationHome (registerClientOptions: RegisterClientOption } export { - renderModerationHome + renderConfigurationHome } diff --git a/languages/en.yml b/languages/en.yml index 39cdcabd..fb0dc17c 100644 --- a/languages/en.yml +++ b/languages/en.yml @@ -296,14 +296,14 @@ prosody_components_list_description: | save: "Save" cancel: "Cancel" successfully_saved: "Successfully saved" -menu_moderation_label: "Chatrooms" -livechat_moderation_title: "Configure your live's chatrooms moderation policies" -livechat_moderation_desc: "Here you can configure some advanced options for chatrooms associated to your live streams." -livechat_moderation_please_select: "Please select bellow one of your channel, to setup its chatting options." -livechat_moderation_channel_title: "Moderation policies for channel:" -livechat_moderation_channel_desc: "You can setup here your moderation policies for this channel." -livechat_moderation_channel_enable_bot_label: "Enable moderation bot" -livechat_moderation_channel_bot_options_title: "Moderation bot options" -livechat_moderation_channel_forbidden_words_label: "Forbidden words or expressions" -livechat_moderation_channel_banned_jids_label: "Banned users and patterns" +menu_configuration_label: "Chatrooms" +livechat_configuration_title: "Configure your live's chatrooms" +livechat_configuration_desc: "Here you can configure some advanced options for chatrooms associated to your live streams." +livechat_configuration_please_select: "Please select bellow one of your channel, to setup its chatting options." +livechat_configuration_channel_title: "Moderation policies for channel:" +livechat_configuration_channel_desc: "You can setup here your moderation policies for this channel." +livechat_configuration_channel_enable_bot_label: "Enable moderation bot" +livechat_configuration_channel_bot_options_title: "Moderation bot options" +livechat_configuration_channel_forbidden_words_label: "Forbidden words or expressions" +livechat_configuration_channel_banned_jids_label: "Banned users and patterns" diff --git a/server/lib/moderation/channel/sanitize.ts b/server/lib/configuration/channel/sanitize.ts similarity index 78% rename from server/lib/moderation/channel/sanitize.ts rename to server/lib/configuration/channel/sanitize.ts index 699b81bf..39d12710 100644 --- a/server/lib/moderation/channel/sanitize.ts +++ b/server/lib/configuration/channel/sanitize.ts @@ -1,19 +1,19 @@ import type { RegisterServerOptions } from '@peertube/peertube-types' -import type { ChannelModerationOptions, ChannelInfos } from '../../../../shared/lib/types' +import type { ChannelConfigurationOptions, ChannelInfos } from '../../../../shared/lib/types' /** - * Sanitize data so that they can safely be used/stored for channel moderation configuration. + * Sanitize data so that they can safely be used/stored for channel configuration configuration. * Throw an error if the format is obviously wrong. * Cleans data (removing empty values, ...) * @param options Peertube server options * @param _channelInfos Channel infos * @param data Input data */ -async function sanitizeChannelModerationOptions ( +async function sanitizeChannelConfigurationOptions ( _options: RegisterServerOptions, _channelInfos: ChannelInfos, data: any -): Promise { +): Promise { const result = { bot: false, bannedJIDs: [], @@ -28,7 +28,7 @@ async function sanitizeChannelModerationOptions ( if (!(f in data) || (typeof data[f] !== 'boolean')) { throw new Error('Invalid data type for field ' + f) } - result[f as keyof ChannelModerationOptions] = data[f] + result[f as keyof ChannelConfigurationOptions] = data[f] } // value/regexp array fields for (const f of ['bannedJIDs', 'forbiddenWords']) { @@ -50,7 +50,7 @@ async function sanitizeChannelModerationOptions ( } catch (_err) { throw new Error('Invalid value in field ' + f) } - (result[f as keyof ChannelModerationOptions] as string[]).push(v) + (result[f as keyof ChannelConfigurationOptions] as string[]).push(v) } } @@ -58,5 +58,5 @@ async function sanitizeChannelModerationOptions ( } export { - sanitizeChannelModerationOptions + sanitizeChannelConfigurationOptions } diff --git a/server/lib/moderation/channel/storage.ts b/server/lib/configuration/channel/storage.ts similarity index 62% rename from server/lib/moderation/channel/storage.ts rename to server/lib/configuration/channel/storage.ts index a3a798b2..be20711f 100644 --- a/server/lib/moderation/channel/storage.ts +++ b/server/lib/configuration/channel/storage.ts @@ -1,27 +1,27 @@ import type { RegisterServerOptions } from '@peertube/peertube-types' -import type { ChannelModeration, ChannelInfos } from '../../../../shared/lib/types' -import { sanitizeChannelModerationOptions } from '../../moderation/channel/sanitize' +import type { ChannelConfiguration, ChannelInfos } from '../../../../shared/lib/types' +import { sanitizeChannelConfigurationOptions } from '../../configuration/channel/sanitize' import * as fs from 'fs' import * as path from 'path' /** - * Get saved moderation options for the given channel. + * Get saved configuration options for the given channel. * Can throw an exception. * @param options Peertube server options * @param channelInfos Info from channel from which we want to get infos - * @returns Channel moderation data + * @returns Channel configuration data */ -async function getChannelModerationOptions ( +async function getChannelConfigurationOptions ( options: RegisterServerOptions, channelInfos: ChannelInfos -): Promise { +): Promise { const logger = options.peertubeHelpers.logger const filePath = _getFilePath(options, channelInfos) if (!fs.existsSync(filePath)) { logger.debug('No stored data for channel, returning default values') return { channel: channelInfos, - moderation: { + configuration: { bot: false, bannedJIDs: [], forbiddenWords: [] @@ -31,24 +31,24 @@ async function getChannelModerationOptions ( const content = await fs.promises.readFile(filePath, { encoding: 'utf-8' }) - const sanitized = await sanitizeChannelModerationOptions(options, channelInfos, JSON.parse(content)) + const sanitized = await sanitizeChannelConfigurationOptions(options, channelInfos, JSON.parse(content)) return { channel: channelInfos, - moderation: sanitized + configuration: sanitized } } /** - * Save channel moderation options. + * Save channel configuration options. * Can throw an exception. - * @param _options Peertube server options - * @param _channelModeration data to save + * @param options Peertube server options + * @param channelConfiguration data to save */ -async function storeChannelModerationOptions ( +async function storeChannelConfigurationOptions ( options: RegisterServerOptions, - channelModeration: ChannelModeration + channelConfiguration: ChannelConfiguration ): Promise { - const channelInfos = channelModeration.channel + const channelInfos = channelConfiguration.channel const filePath = _getFilePath(options, channelInfos) if (!fs.existsSync(filePath)) { @@ -58,7 +58,7 @@ async function storeChannelModerationOptions ( } } - const jsonContent = JSON.stringify(channelModeration.moderation) + const jsonContent = JSON.stringify(channelConfiguration.configuration) await fs.promises.writeFile(filePath, jsonContent, { encoding: 'utf-8' @@ -77,12 +77,12 @@ function _getFilePath ( return path.resolve( options.peertubeHelpers.plugin.getDataDirectoryPath(), - 'channelModerationOptions', + 'channelConfigurationOptions', channelId.toString() + '.json' ) } export { - getChannelModerationOptions, - storeChannelModerationOptions + getChannelConfigurationOptions, + storeChannelConfigurationOptions } diff --git a/server/lib/middlewares/moderation/channel.ts b/server/lib/middlewares/configuration/channel.ts similarity index 85% rename from server/lib/middlewares/moderation/channel.ts rename to server/lib/middlewares/configuration/channel.ts index 20cac27e..5331f3d3 100644 --- a/server/lib/middlewares/moderation/channel.ts +++ b/server/lib/middlewares/configuration/channel.ts @@ -6,11 +6,11 @@ import { isUserAdminOrModerator } from '../../helpers' /** * Returns a middleware handler to get the channelInfos from the channel parameter. - * This is used in api related to channel moderation options. + * This is used in api related to channel configuration options. * @param options Peertube server options * @returns middleware function */ -function getCheckModerationChannelMiddleware (options: RegisterServerOptions): RequestPromiseHandler { +function getCheckConfigurationChannelMiddleware (options: RegisterServerOptions): RequestPromiseHandler { return async (req: Request, res: Response, next: NextFunction) => { const logger = options.peertubeHelpers.logger const channelId = req.params.channelId @@ -42,12 +42,12 @@ function getCheckModerationChannelMiddleware (options: RegisterServerOptions): R return } - logger.debug('User can access the moderation channel api.') + logger.debug('User can access the configuration channel api.') res.locals.channelInfos = channelInfos next() } } export { - getCheckModerationChannelMiddleware + getCheckConfigurationChannelMiddleware } diff --git a/server/lib/routers/api.ts b/server/lib/routers/api.ts index 4bed1709..ba04c6bd 100644 --- a/server/lib/routers/api.ts +++ b/server/lib/routers/api.ts @@ -7,7 +7,7 @@ import { isDebugMode } from '../debug' import { initRoomApiRouter } from './api/room' import { initAuthApiRouter, initUserAuthApiRouter } from './api/auth' import { initFederationServerInfosApiRouter } from './api/federation-server-infos' -import { initModerationApiRouter } from './api/moderation' +import { initConfigurationApiRouter } from './api/configuration' /** * Initiate API routes @@ -53,7 +53,7 @@ async function initApiRouter (options: RegisterServerOptions): Promise { )) } - router.use('/moderation', await initModerationApiRouter(options)) + router.use('/configuration', await initConfigurationApiRouter(options)) return router } diff --git a/server/lib/routers/api/moderation.ts b/server/lib/routers/api/configuration.ts similarity index 62% rename from server/lib/routers/api/moderation.ts rename to server/lib/routers/api/configuration.ts index 57ddbfde..4d36e342 100644 --- a/server/lib/routers/api/moderation.ts +++ b/server/lib/routers/api/configuration.ts @@ -2,16 +2,16 @@ import type { RegisterServerOptions } from '@peertube/peertube-types' import type { Router, Request, Response, NextFunction } from 'express' import type { ChannelInfos } from '../../../../shared/lib/types' import { asyncMiddleware } from '../../middlewares/async' -import { getCheckModerationChannelMiddleware } from '../../middlewares/moderation/channel' -import { getChannelModerationOptions, storeChannelModerationOptions } from '../../moderation/channel/storage' -import { sanitizeChannelModerationOptions } from '../../moderation/channel/sanitize' +import { getCheckConfigurationChannelMiddleware } from '../../middlewares/configuration/channel' +import { getChannelConfigurationOptions, storeChannelConfigurationOptions } from '../../configuration/channel/storage' +import { sanitizeChannelConfigurationOptions } from '../../configuration/channel/sanitize' -async function initModerationApiRouter (options: RegisterServerOptions): Promise { +async function initConfigurationApiRouter (options: RegisterServerOptions): Promise { const router = options.getRouter() const logger = options.peertubeHelpers.logger router.get('/channel/:channelId', asyncMiddleware([ - getCheckModerationChannelMiddleware(options), + getCheckConfigurationChannelMiddleware(options), async (req: Request, res: Response, _next: NextFunction): Promise => { if (!res.locals.channelInfos) { logger.error('Missing channelInfos in res.locals, should not happen') @@ -20,14 +20,14 @@ async function initModerationApiRouter (options: RegisterServerOptions): Promise } const channelInfos = res.locals.channelInfos as ChannelInfos - const result = await getChannelModerationOptions(options, channelInfos) + const result = await getChannelConfigurationOptions(options, channelInfos) res.status(200) res.json(result) } ])) router.post('/channel/:channelId', asyncMiddleware([ - getCheckModerationChannelMiddleware(options), + getCheckConfigurationChannelMiddleware(options), async (req: Request, res: Response, _next: NextFunction): Promise => { if (!res.locals.channelInfos) { logger.error('Missing channelInfos in res.locals, should not happen') @@ -35,11 +35,11 @@ async function initModerationApiRouter (options: RegisterServerOptions): Promise return } const channelInfos = res.locals.channelInfos as ChannelInfos - logger.debug('Trying to save ChannelModerationOptions') + logger.debug('Trying to save ChannelConfigurationOptions') - let moderation + let configuration try { - moderation = await sanitizeChannelModerationOptions(options, channelInfos, req.body) + configuration = await sanitizeChannelConfigurationOptions(options, channelInfos, req.body) } catch (err) { logger.warn(err) res.sendStatus(400) @@ -49,9 +49,9 @@ async function initModerationApiRouter (options: RegisterServerOptions): Promise logger.debug('Data seems ok, storing them.') const result = { channel: channelInfos, - moderation + configuration } - await storeChannelModerationOptions(options, result) + await storeChannelConfigurationOptions(options, result) res.status(200) res.json(result) } @@ -61,5 +61,5 @@ async function initModerationApiRouter (options: RegisterServerOptions): Promise } export { - initModerationApiRouter + initConfigurationApiRouter } diff --git a/shared/lib/types.ts b/shared/lib/types.ts index 14bfb888..3939ecbf 100644 --- a/shared/lib/types.ts +++ b/shared/lib/types.ts @@ -52,15 +52,15 @@ interface ChannelInfos { displayName: string } -interface ChannelModerationOptions { +interface ChannelConfigurationOptions { bot: boolean forbiddenWords: string[] bannedJIDs: string[] } -interface ChannelModeration { +interface ChannelConfiguration { channel: ChannelInfos - moderation: ChannelModerationOptions + configuration: ChannelConfigurationOptions } export type { @@ -69,6 +69,6 @@ export type { ProsodyListRoomsResult, ProsodyListRoomsResultRoom, ChannelInfos, - ChannelModerationOptions, - ChannelModeration + ChannelConfigurationOptions, + ChannelConfiguration }