mirror of
https://github.com/wassname/talk.git
synced 2026-07-24 13:20:47 +08:00
[CORL-571] Filter empty strings from banned and suspect word lists (#2521)
* Filter empty strings from banned and suspect word lists CORL-571 * fix: changed form
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user