diff --git a/src/core/server/services/tenant/index.ts b/src/core/server/services/tenant/index.ts index 8b3fe203b..b0eb33d66 100644 --- a/src/core/server/services/tenant/index.ts +++ b/src/core/server/services/tenant/index.ts @@ -6,7 +6,10 @@ import { URL } from "url"; import { discover } from "coral-server/app/middleware/passport/strategies/oidc/discover"; import { Config } from "coral-server/config"; import { TenantInstalledAlreadyError } from "coral-server/errors"; -import { GQLSettingsInput } from "coral-server/graph/tenant/schema/__generated__/types"; +import { + GQLSettingsInput, + GQLSettingsWordListInput, +} from "coral-server/graph/tenant/schema/__generated__/types"; import logger from "coral-server/logger"; import { createTenant, @@ -21,6 +24,20 @@ import TenantCache from "./cache"; export type UpdateTenant = GQLSettingsInput; +function cleanWordList( + list: GQLSettingsWordListInput +): GQLSettingsWordListInput { + if (list.banned) { + list.banned = list.banned.filter(Boolean); + } + + if (list.suspect) { + list.suspect = list.suspect.filter(Boolean); + } + + return list; +} + export async function update( mongo: Db, redis: Redis, @@ -39,6 +56,12 @@ export async function update( delete input.live.enabled; } + // If the word list was specified, we should validate it to ensure there isn't + // any empty spaces. + if (input.wordList) { + input.wordList = cleanWordList(input.wordList); + } + const updatedTenant = await updateTenant(mongo, tenant.id, input); if (!updatedTenant) { return null;