[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:
Nick Funk
2019-09-05 21:36:09 +00:00
committed by Wyatt Johnson
parent 15d41f1ae8
commit e49905c5ad
+24 -1
View File
@@ -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;