Skip to content

Commit

Permalink
make premoderate email address "too many periods" an Admin > Config
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-funk committed Aug 31, 2023
1 parent 733b613 commit da1bb5f
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import EmailDomainConfigContainer from "./EmailDomainConfigContainer";
import ExternalLinksConfigContainer from "./ExternalLinksConfigContainer";
import NewCommentersConfigContainer from "./NewCommentersConfigContainer";
import PerspectiveConfig from "./PerspectiveConfig";
import PremoderateEmailAddressConfig from "./PremoderateEmailAddressConfig";
import PreModerationConfigContainer from "./PreModerationConfigContainer";
import RecentCommentHistoryConfig from "./RecentCommentHistoryConfig";

Expand Down Expand Up @@ -50,6 +51,7 @@ export const ModerationConfigContainer: React.FunctionComponent<Props> = ({
<RecentCommentHistoryConfig disabled={submitting} />
<ExternalLinksConfigContainer disabled={submitting} settings={settings} />
<EmailDomainConfigContainer settings={settings} />
<PremoderateEmailAddressConfig disabled={submitting} />
</HorizontalGutter>
);
};
Expand All @@ -67,6 +69,7 @@ const enhanced = withFragmentContainer<Props>({
...EmailDomainConfigContainer_settings
...ExternalLinksConfigContainer_formValues @relay(mask: false)
...ExternalLinksConfigContainer_settings
...PremoderateEmailAddressConfig_formValues @relay(mask: false)
}
`,
})(ModerationConfigContainer);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Localized } from "@fluent/react/compat";
import React, { FunctionComponent } from "react";
import { graphql } from "react-relay";

import {
FieldSet,
FormField,
FormFieldHeader,
Label,
} from "coral-ui/components/v2";

import ConfigBox from "../../ConfigBox";
import Header from "../../Header";
import HelperText from "../../HelperText";
import OnOffField from "../../OnOffField";

// eslint-disable-next-line no-unused-expressions
graphql`
fragment PremoderateEmailAddressConfig_formValues on Settings {
premoderateEmailAddress {
tooManyPeriods {
enabled
}
}
}
`;

interface Props {
disabled: boolean;
}

const PremoderateEmailAddressConfig: FunctionComponent<Props> = ({
disabled,
}) => {
return (
<ConfigBox
title={
<Localized id="configure-moderation-premoderateEmailAddress-title">
<Header container={<legend />}>Email address</Header>
</Localized>
}
container={<FieldSet />}
>
<FormField container={<FieldSet />}>
<FormFieldHeader>
<Localized id="configure-moderation-premoderateEmailAddress-enabled">
<Label component="legend">
Premoderate users with too many periods
</Label>
</Localized>
<Localized id="configure-moderation-premoderateEmailAddress-enabled">
<HelperText>
If a users has three or more periods in the first part of their
email address (before the @), set their status to pre-moderate all
comments. This is often used because emails with more than 3
periods can have a very high spam correlation.
</HelperText>
</Localized>
</FormFieldHeader>
<OnOffField
name="premoderateEmailAddress.tooManyPeriods.enabled"
disabled={disabled}
/>
</FormField>
</ConfigBox>
);
};

export default PremoderateEmailAddressConfig;
12 changes: 12 additions & 0 deletions src/core/server/graph/resolvers/PremoderateEmailAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {
GQLPremoderateEmailAddressConfig,
GQLPremoderateEmailAddressConfigTypeResolver,
} from "coral-server/graph/schema/__generated__/types";

export const SlackConfiguration: GQLPremoderateEmailAddressConfigTypeResolver<GQLPremoderateEmailAddressConfig> =
{
tooManyPeriods: (config) =>
config && config.tooManyPeriods
? config.tooManyPeriods
: { enabled: false },
};
26 changes: 20 additions & 6 deletions src/core/server/graph/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,6 @@ enum FEATURE_FLAG {
users, and commentActions more quickly. It is disabled by default.
"""
DATA_CACHE

"""
EMAIL_PREMOD_FILTER enables the feature to premoderate accounts whose emails
match patterns that are common with spam accounts.
"""
EMAIL_PREMOD_FILTER
}

# The moderation mode of the site.
Expand Down Expand Up @@ -1934,6 +1928,22 @@ type RTEConfiguration {
sarcasm: Boolean!
}

type TooManyPeriodsConfig {
enabled: Boolean!
}

type PremoderateEmailAddressConfig {
tooManyPeriods: TooManyPeriodsConfig
}

input TooManyPeriodsConfigInput {
enabled: Boolean
}

input PremoderateEmailAddressConfigInput {
tooManyPeriods: TooManyPeriodsConfigInput
}

"""
Settings stores the global settings for a given Tenant.
"""
Expand Down Expand Up @@ -2228,6 +2238,8 @@ type Settings @cacheControl(maxAge: 30) {
they are enabled and any configured image urls
"""
flairBadges: FlairBadgeConfiguration

premoderateEmailAddress: PremoderateEmailAddressConfig
}

################################################################################
Expand Down Expand Up @@ -5808,6 +5820,8 @@ input SettingsInput {
they are enabled and any configured image urls
"""
flairBadges: FlairBadgeConfigurationInput

premoderateEmailAddress: PremoderateEmailAddressConfigInput
}

"""
Expand Down
8 changes: 8 additions & 0 deletions src/core/server/models/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ export interface FlairBadgeConfig {
badges?: FlairBadge[];
}

export interface PremoderateEmailAddressConfig {
tooManyPeriods?: {
enabled?: boolean;
};
}

export type Settings = GlobalModerationSettings &
Pick<
GQLSettings,
Expand Down Expand Up @@ -410,6 +416,8 @@ export type Settings = GlobalModerationSettings &
forReviewQueue?: boolean;

flairBadges?: FlairBadgeConfig;

premoderateEmailAddress?: PremoderateEmailAddressConfig;
};

export const defaultRTEConfiguration: RTEConfiguration = {
Expand Down
6 changes: 2 additions & 4 deletions src/core/server/services/users/emailPremodFilter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { hasFeatureFlag, Tenant } from "coral-server/models/tenant";

import { GQLFEATURE_FLAG } from "coral-server/graph/schema/__generated__/types";
import { Tenant } from "coral-server/models/tenant";
import { User } from "coral-server/models/user";

export const EMAIL_PREMOD_FILTER_PERIOD_LIMIT = 3;
Expand Down Expand Up @@ -32,7 +30,7 @@ export const shouldPremodDueToLikelySpamEmail = (
user: Readonly<User>
) => {
// don't premod check unless the filter is enabled
if (!hasFeatureFlag(tenant, GQLFEATURE_FLAG.EMAIL_PREMOD_FILTER)) {
if (!tenant?.premoderateEmailAddress?.tooManyPeriods?.enabled) {
return false;
}

Expand Down
11 changes: 11 additions & 0 deletions src/locales/en-US/admin.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,17 @@ configure-moderation-emailDomains-confirmDelete = Deleting this email domain wil
configure-moderation-emailDomains-form-description-add = Add a domain and select the action that should be taken when on every new account created using the specified domain.
configure-moderation-emailDomains-form-description-edit = Update the domain or action that should be taken when on every new account using the specified domain.
#### Premoderate Email Address Configuration

configure-moderation-premoderateEmailAddress-title = Email address
configure-moderation-premoderateEmailAddress-enabled =
Premoderate users with too many periods
configure-moderation-premoderateEmailAddress-enabled =
If a users has three or more periods in the first part of their
email address (before the @), set their status to pre-moderate all
comments. This is often used because emails with more than 3
periods can have a very high spam correlation.
#### Banned Words Configuration
configure-wordList-banned-bannedWordsAndPhrases = Banned words and phrases
configure-wordList-banned-explanation =
Expand Down

0 comments on commit da1bb5f

Please sign in to comment.