mirror of
https://github.com/wassname/talk.git
synced 2026-06-27 20:54:05 +08:00
[CORL-882] option to reject all a user's comments when banning (#2827)
* show comment counts for stories in story table * remove debug code * add rejector task * connect comment rejection job to user banning * localize strings * remove debug code * remove debug code * resolve merge conflicts * add documentation to rejectExistingComments * clean up rejector task * add TODO about broker * make rejectExistingComments nullable
This commit is contained in:
@@ -191,9 +191,13 @@ const ModerateCardContainer: FunctionComponent<Props> = ({
|
||||
}, [comment]);
|
||||
|
||||
const handleBanConfirm = useCallback(
|
||||
async (message: string) => {
|
||||
async (rejectExistingComments: boolean, message: string) => {
|
||||
if (comment.author) {
|
||||
await banUser({ userID: comment.author.id, message });
|
||||
await banUser({
|
||||
userID: comment.author.id,
|
||||
message,
|
||||
rejectExistingComments,
|
||||
});
|
||||
}
|
||||
setShowBanModal(false);
|
||||
},
|
||||
|
||||
@@ -22,7 +22,7 @@ interface Props {
|
||||
username: string | null;
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
onConfirm: (message?: string) => void;
|
||||
onConfirm: (rejectExistingComments: boolean, message?: string) => void;
|
||||
getMessage: GetMessage;
|
||||
}
|
||||
|
||||
@@ -44,8 +44,8 @@ const BanModal: FunctionComponent<Props> = ({
|
||||
}, [getMessage, username]);
|
||||
|
||||
const onFormSubmit = useCallback(
|
||||
({ emailMessage }) => {
|
||||
onConfirm(emailMessage);
|
||||
({ emailMessage, rejectExistingComments }) => {
|
||||
onConfirm(rejectExistingComments, emailMessage);
|
||||
},
|
||||
[onConfirm]
|
||||
);
|
||||
@@ -83,12 +83,22 @@ const BanModal: FunctionComponent<Props> = ({
|
||||
onSubmit={onFormSubmit}
|
||||
initialValues={{
|
||||
showMessage: false,
|
||||
rejectExistingComments: false,
|
||||
emailMessage: getDefaultMessage,
|
||||
}}
|
||||
>
|
||||
{({ handleSubmit }) => (
|
||||
<form onSubmit={handleSubmit}>
|
||||
<HorizontalGutter spacing={3}>
|
||||
<Field type="checkbox" name="rejectExistingComments">
|
||||
{({ input }) => (
|
||||
<Localized id="community-banModal-reject-existing">
|
||||
<CheckBox {...input} id="banModal-rejectExisting">
|
||||
Reject all comments by this user
|
||||
</CheckBox>
|
||||
</Localized>
|
||||
)}
|
||||
</Field>
|
||||
<Field type="checkbox" name="showMessage">
|
||||
{({ input }) => (
|
||||
<Localized id="community-banModal-customize">
|
||||
|
||||
@@ -111,8 +111,8 @@ const UserStatusChangeContainer: FunctionComponent<Props> = props => {
|
||||
);
|
||||
|
||||
const handleBanConfirm = useCallback(
|
||||
message => {
|
||||
banUser({ userID: user.id, message });
|
||||
(rejectExistingComments, message) => {
|
||||
banUser({ userID: user.id, message, rejectExistingComments });
|
||||
setShowBanned(false);
|
||||
},
|
||||
[user, setShowBanned]
|
||||
|
||||
@@ -4,18 +4,25 @@
|
||||
padding-top: 15px;
|
||||
padding-bottom: 15px;
|
||||
}
|
||||
.authorColumn {
|
||||
vertical-align: top;
|
||||
word-break: break-word;
|
||||
padding-top: 15px;
|
||||
padding-bottom: 15px;
|
||||
}
|
||||
.publishDateColumn {
|
||||
vertical-align: top;
|
||||
padding-top: 15px;
|
||||
padding-bottom: 15px;
|
||||
}
|
||||
.statusColumn {
|
||||
}
|
||||
.siteColumn {
|
||||
}
|
||||
|
||||
.meta {
|
||||
color: var(--v2-colors-mono-100);
|
||||
}
|
||||
|
||||
.authorName {
|
||||
font-weight: var(--v2-font-weight-primary-semi-bold);
|
||||
}
|
||||
|
||||
.reportedCountColumn,
|
||||
.pendingCountColumn,
|
||||
.totalCountColumn {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.boldColumn {
|
||||
font-weight: var(--v2-font-weight-primary-semi-bold);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import cn from "classnames";
|
||||
import { Link } from "found";
|
||||
import React, { FunctionComponent } from "react";
|
||||
|
||||
import NotAvailable from "coral-admin/components/NotAvailable";
|
||||
import { getModerationLink } from "coral-framework/helpers";
|
||||
import { PropTypesOf } from "coral-framework/types";
|
||||
import { TableCell, TableRow, TextLink } from "coral-ui/components/v2";
|
||||
import {
|
||||
HorizontalGutter,
|
||||
TableCell,
|
||||
TableRow,
|
||||
TextLink,
|
||||
} from "coral-ui/components/v2";
|
||||
|
||||
import StoryStatus from "./StoryStatus";
|
||||
|
||||
@@ -20,27 +26,51 @@ interface Props {
|
||||
siteName: string;
|
||||
siteID: string;
|
||||
multisite: boolean;
|
||||
reportedCount: number | null;
|
||||
pendingCount: number | null;
|
||||
totalCount: number;
|
||||
}
|
||||
|
||||
const UserRow: FunctionComponent<Props> = props => (
|
||||
<TableRow>
|
||||
<TableCell className={styles.titleColumn}>
|
||||
<Link to={getModerationLink({ storyID: props.storyID })} as={TextLink}>
|
||||
{props.title || <NotAvailable />}
|
||||
</Link>
|
||||
<HorizontalGutter>
|
||||
<p>
|
||||
<Link
|
||||
to={getModerationLink({ storyID: props.storyID })}
|
||||
as={TextLink}
|
||||
>
|
||||
{props.title || <NotAvailable />}
|
||||
</Link>
|
||||
</p>
|
||||
{(props.author || props.publishDate) && (
|
||||
<p className={styles.meta}>
|
||||
<span className={styles.authorName}>{props.author}</span>{" "}
|
||||
{props.publishDate}
|
||||
</p>
|
||||
)}
|
||||
</HorizontalGutter>
|
||||
</TableCell>
|
||||
<TableCell className={styles.authorColumn}>
|
||||
{props.author || <NotAvailable />}
|
||||
<TableCell
|
||||
className={cn(styles.reportedCountColumn, {
|
||||
[styles.boldColumn]: props.reportedCount && props.reportedCount > 0,
|
||||
})}
|
||||
>
|
||||
{props.reportedCount}
|
||||
</TableCell>
|
||||
{props.multisite && (
|
||||
<TableCell className={styles.siteColumn}>
|
||||
<Link to={getModerationLink({ siteID: props.siteID })} as={TextLink}>
|
||||
{props.siteName}
|
||||
</Link>
|
||||
</TableCell>
|
||||
)}
|
||||
<TableCell className={styles.publishDateColumn}>
|
||||
{props.publishDate || <NotAvailable />}
|
||||
<TableCell
|
||||
className={cn(styles.pendingCountColumn, {
|
||||
[styles.boldColumn]: props.pendingCount && props.pendingCount > 0,
|
||||
})}
|
||||
>
|
||||
{props.pendingCount}
|
||||
</TableCell>
|
||||
<TableCell
|
||||
className={cn(styles.totalCountColumn, {
|
||||
[styles.boldColumn]: props.totalCount && props.totalCount > 0,
|
||||
})}
|
||||
>
|
||||
{props.totalCount}
|
||||
</TableCell>
|
||||
<TableCell className={styles.statusColumn}>
|
||||
<StoryStatus story={props.story} viewer={props.viewer} />
|
||||
|
||||
@@ -30,6 +30,9 @@ const StoryRowContainer: FunctionComponent<Props> = props => {
|
||||
siteName={props.story.site.name}
|
||||
siteID={props.story.site.id}
|
||||
multisite={props.multisite}
|
||||
totalCount={props.story.commentCounts.totalPublished}
|
||||
reportedCount={props.story.moderationQueues.reported.count}
|
||||
pendingCount={props.story.moderationQueues.pending.count}
|
||||
publishDate={
|
||||
publishedAt
|
||||
? new Intl.DateTimeFormat(locales, {
|
||||
@@ -61,6 +64,17 @@ const enhanced = withFragmentContainer<Props>({
|
||||
author
|
||||
publishedAt
|
||||
}
|
||||
commentCounts {
|
||||
totalPublished
|
||||
}
|
||||
moderationQueues {
|
||||
reported {
|
||||
count
|
||||
}
|
||||
pending {
|
||||
count
|
||||
}
|
||||
}
|
||||
site {
|
||||
name
|
||||
id
|
||||
|
||||
@@ -1,25 +1,31 @@
|
||||
$tableHeaderAltTextColor: var(--v2-colors-mono-100);
|
||||
|
||||
.titleColumn {
|
||||
width: 50%;
|
||||
width: 60%;
|
||||
}
|
||||
.titleColumnNarrow {
|
||||
width: 32.5%;
|
||||
}
|
||||
.authorColumn {
|
||||
width: 17.5%;
|
||||
}
|
||||
.publishDateColumn {
|
||||
width: 17.5%;
|
||||
width: 42.5%;
|
||||
}
|
||||
.statusColumn {
|
||||
width: 15%;
|
||||
width: 14%;
|
||||
}
|
||||
.siteColumn {
|
||||
width: 17.5%;
|
||||
.reportedCountColumn {
|
||||
width: 9%;
|
||||
}
|
||||
.pendingCountColumn {
|
||||
width: 9%;
|
||||
}
|
||||
.totalCountColumn {
|
||||
width: 9%;
|
||||
}
|
||||
.clickToModerate {
|
||||
font-size: var(--v2-font-size-2);
|
||||
font-weight: var(--v2-font-weight-primary-semi-bold);
|
||||
color: $tableHeaderAltTextColor;
|
||||
}
|
||||
|
||||
.reportedCountColumn,
|
||||
.pendingCountColumn,
|
||||
.totalCountColumn {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Localized } from "@fluent/react/compat";
|
||||
import cn from "classnames";
|
||||
import React, { FunctionComponent } from "react";
|
||||
|
||||
import AutoLoadMore from "coral-admin/components/AutoLoadMore";
|
||||
@@ -38,11 +37,7 @@ const StoryTable: FunctionComponent<Props> = props => (
|
||||
<Table fullWidth>
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<TableCell
|
||||
className={cn(styles.titleColumn, {
|
||||
[styles.titleColumnNarrow]: props.multisite,
|
||||
})}
|
||||
>
|
||||
<TableCell className={styles.titleColumn}>
|
||||
<Localized id="stories-column-title">
|
||||
<span>Title</span>
|
||||
</Localized>{" "}
|
||||
@@ -55,19 +50,19 @@ const StoryTable: FunctionComponent<Props> = props => (
|
||||
</span>
|
||||
</TableCell>
|
||||
|
||||
<Localized id="stories-column-author">
|
||||
<TableCell className={styles.authorColumn}>Author</TableCell>
|
||||
</Localized>
|
||||
{props.multisite && (
|
||||
<Localized id="stories-column-site">
|
||||
<TableCell className={styles.siteColumn}>Site</TableCell>
|
||||
</Localized>
|
||||
)}
|
||||
<Localized id="stories-column-publishDate">
|
||||
<TableCell className={styles.publishDateColumn}>
|
||||
Publish Date
|
||||
<Localized id="stories-column-reportedCount">
|
||||
<TableCell className={styles.reportedCountColumn}>
|
||||
Reported
|
||||
</TableCell>
|
||||
</Localized>
|
||||
<Localized id="stories-column-pendingCount">
|
||||
<TableCell className={styles.pendingCountColumn}>
|
||||
Pending
|
||||
</TableCell>
|
||||
</Localized>
|
||||
<Localized id="stories-column-totalCount">
|
||||
<TableCell className={styles.totalCountColumn}>Total</TableCell>
|
||||
</Localized>
|
||||
<Localized id="stories-column-status">
|
||||
<TableCell className={styles.statusColumn}>Status</TableCell>
|
||||
</Localized>
|
||||
|
||||
@@ -492,6 +492,19 @@ export const stories = createFixtures<GQLStory>([
|
||||
title: "Finally a Cure for Cancer",
|
||||
publishedAt: "2018-11-29T16:01:51.897Z",
|
||||
},
|
||||
commentCounts: {
|
||||
totalPublished: 5,
|
||||
},
|
||||
moderationQueues: {
|
||||
reported: {
|
||||
id: "reported",
|
||||
count: 3,
|
||||
},
|
||||
pending: {
|
||||
id: "pending",
|
||||
count: 2,
|
||||
},
|
||||
},
|
||||
site: sites[0],
|
||||
},
|
||||
{
|
||||
@@ -506,6 +519,19 @@ export const stories = createFixtures<GQLStory>([
|
||||
title: "First Colony on Mars",
|
||||
publishedAt: "2018-11-29T16:01:51.897Z",
|
||||
},
|
||||
commentCounts: {
|
||||
totalPublished: 5,
|
||||
},
|
||||
moderationQueues: {
|
||||
reported: {
|
||||
id: "reported",
|
||||
count: 3,
|
||||
},
|
||||
pending: {
|
||||
id: "pending",
|
||||
count: 2,
|
||||
},
|
||||
},
|
||||
site: sites[1],
|
||||
},
|
||||
{
|
||||
@@ -515,6 +541,19 @@ export const stories = createFixtures<GQLStory>([
|
||||
isClosed: true,
|
||||
status: GQLSTORY_STATUS.CLOSED,
|
||||
url: "",
|
||||
commentCounts: {
|
||||
totalPublished: 5,
|
||||
},
|
||||
moderationQueues: {
|
||||
reported: {
|
||||
id: "reported",
|
||||
count: 3,
|
||||
},
|
||||
pending: {
|
||||
id: "pending",
|
||||
count: 2,
|
||||
},
|
||||
},
|
||||
metadata: {
|
||||
author: undefined,
|
||||
title: "World hunger has been defeated",
|
||||
|
||||
@@ -155,14 +155,19 @@ exports[`renders empty stories 1`] = `
|
||||
</span>
|
||||
</th>
|
||||
<th
|
||||
className="TableCell-root StoryTable-authorColumn TableCell-header"
|
||||
className="TableCell-root StoryTable-reportedCountColumn TableCell-header"
|
||||
>
|
||||
Author
|
||||
Reported
|
||||
</th>
|
||||
<th
|
||||
className="TableCell-root StoryTable-publishDateColumn TableCell-header"
|
||||
className="TableCell-root StoryTable-pendingCountColumn TableCell-header"
|
||||
>
|
||||
Publish Date
|
||||
Pending
|
||||
</th>
|
||||
<th
|
||||
className="TableCell-root StoryTable-totalCountColumn TableCell-header"
|
||||
>
|
||||
Total
|
||||
</th>
|
||||
<th
|
||||
className="TableCell-root StoryTable-statusColumn TableCell-header"
|
||||
@@ -180,23 +185,45 @@ exports[`renders empty stories 1`] = `
|
||||
<td
|
||||
className="TableCell-root StoryRow-titleColumn TableCell-body"
|
||||
>
|
||||
<a
|
||||
className="TextLink-root"
|
||||
href="/admin/moderate/stories/story-1"
|
||||
onClick={[Function]}
|
||||
<div
|
||||
className="Box-root HorizontalGutter-root HorizontalGutter-full"
|
||||
>
|
||||
Finally a Cure for Cancer
|
||||
</a>
|
||||
<p>
|
||||
<a
|
||||
className="TextLink-root"
|
||||
href="/admin/moderate/stories/story-1"
|
||||
onClick={[Function]}
|
||||
>
|
||||
Finally a Cure for Cancer
|
||||
</a>
|
||||
</p>
|
||||
<p
|
||||
className="StoryRow-meta"
|
||||
>
|
||||
<span
|
||||
className="StoryRow-authorName"
|
||||
>
|
||||
Vin Hoa
|
||||
</span>
|
||||
|
||||
11/29/2018, 4:01 PM
|
||||
</p>
|
||||
</div>
|
||||
</td>
|
||||
<td
|
||||
className="TableCell-root StoryRow-authorColumn TableCell-body"
|
||||
className="TableCell-root StoryRow-reportedCountColumn StoryRow-boldColumn TableCell-body"
|
||||
>
|
||||
Vin Hoa
|
||||
3
|
||||
</td>
|
||||
<td
|
||||
className="TableCell-root StoryRow-publishDateColumn TableCell-body"
|
||||
className="TableCell-root StoryRow-pendingCountColumn StoryRow-boldColumn TableCell-body"
|
||||
>
|
||||
11/29/2018, 4:01 PM
|
||||
2
|
||||
</td>
|
||||
<td
|
||||
className="TableCell-root StoryRow-totalCountColumn StoryRow-boldColumn TableCell-body"
|
||||
>
|
||||
5
|
||||
</td>
|
||||
<td
|
||||
className="TableCell-root StoryRow-statusColumn TableCell-body"
|
||||
@@ -251,23 +278,45 @@ exports[`renders empty stories 1`] = `
|
||||
<td
|
||||
className="TableCell-root StoryRow-titleColumn TableCell-body"
|
||||
>
|
||||
<a
|
||||
className="TextLink-root"
|
||||
href="/admin/moderate/stories/story-2"
|
||||
onClick={[Function]}
|
||||
<div
|
||||
className="Box-root HorizontalGutter-root HorizontalGutter-full"
|
||||
>
|
||||
First Colony on Mars
|
||||
</a>
|
||||
<p>
|
||||
<a
|
||||
className="TextLink-root"
|
||||
href="/admin/moderate/stories/story-2"
|
||||
onClick={[Function]}
|
||||
>
|
||||
First Colony on Mars
|
||||
</a>
|
||||
</p>
|
||||
<p
|
||||
className="StoryRow-meta"
|
||||
>
|
||||
<span
|
||||
className="StoryRow-authorName"
|
||||
>
|
||||
Linh Nguyen
|
||||
</span>
|
||||
|
||||
11/29/2018, 4:01 PM
|
||||
</p>
|
||||
</div>
|
||||
</td>
|
||||
<td
|
||||
className="TableCell-root StoryRow-authorColumn TableCell-body"
|
||||
className="TableCell-root StoryRow-reportedCountColumn StoryRow-boldColumn TableCell-body"
|
||||
>
|
||||
Linh Nguyen
|
||||
3
|
||||
</td>
|
||||
<td
|
||||
className="TableCell-root StoryRow-publishDateColumn TableCell-body"
|
||||
className="TableCell-root StoryRow-pendingCountColumn StoryRow-boldColumn TableCell-body"
|
||||
>
|
||||
11/29/2018, 4:01 PM
|
||||
2
|
||||
</td>
|
||||
<td
|
||||
className="TableCell-root StoryRow-totalCountColumn StoryRow-boldColumn TableCell-body"
|
||||
>
|
||||
5
|
||||
</td>
|
||||
<td
|
||||
className="TableCell-root StoryRow-statusColumn TableCell-body"
|
||||
@@ -478,14 +527,19 @@ exports[`renders stories 1`] = `
|
||||
</span>
|
||||
</th>
|
||||
<th
|
||||
className="TableCell-root StoryTable-authorColumn TableCell-header"
|
||||
className="TableCell-root StoryTable-reportedCountColumn TableCell-header"
|
||||
>
|
||||
Author
|
||||
Reported
|
||||
</th>
|
||||
<th
|
||||
className="TableCell-root StoryTable-publishDateColumn TableCell-header"
|
||||
className="TableCell-root StoryTable-pendingCountColumn TableCell-header"
|
||||
>
|
||||
Publish Date
|
||||
Pending
|
||||
</th>
|
||||
<th
|
||||
className="TableCell-root StoryTable-totalCountColumn TableCell-header"
|
||||
>
|
||||
Total
|
||||
</th>
|
||||
<th
|
||||
className="TableCell-root StoryTable-statusColumn TableCell-header"
|
||||
@@ -503,23 +557,45 @@ exports[`renders stories 1`] = `
|
||||
<td
|
||||
className="TableCell-root StoryRow-titleColumn TableCell-body"
|
||||
>
|
||||
<a
|
||||
className="TextLink-root"
|
||||
href="/admin/moderate/stories/story-1"
|
||||
onClick={[Function]}
|
||||
<div
|
||||
className="Box-root HorizontalGutter-root HorizontalGutter-full"
|
||||
>
|
||||
Finally a Cure for Cancer
|
||||
</a>
|
||||
<p>
|
||||
<a
|
||||
className="TextLink-root"
|
||||
href="/admin/moderate/stories/story-1"
|
||||
onClick={[Function]}
|
||||
>
|
||||
Finally a Cure for Cancer
|
||||
</a>
|
||||
</p>
|
||||
<p
|
||||
className="StoryRow-meta"
|
||||
>
|
||||
<span
|
||||
className="StoryRow-authorName"
|
||||
>
|
||||
Vin Hoa
|
||||
</span>
|
||||
|
||||
11/29/2018, 4:01 PM
|
||||
</p>
|
||||
</div>
|
||||
</td>
|
||||
<td
|
||||
className="TableCell-root StoryRow-authorColumn TableCell-body"
|
||||
className="TableCell-root StoryRow-reportedCountColumn StoryRow-boldColumn TableCell-body"
|
||||
>
|
||||
Vin Hoa
|
||||
3
|
||||
</td>
|
||||
<td
|
||||
className="TableCell-root StoryRow-publishDateColumn TableCell-body"
|
||||
className="TableCell-root StoryRow-pendingCountColumn StoryRow-boldColumn TableCell-body"
|
||||
>
|
||||
11/29/2018, 4:01 PM
|
||||
2
|
||||
</td>
|
||||
<td
|
||||
className="TableCell-root StoryRow-totalCountColumn StoryRow-boldColumn TableCell-body"
|
||||
>
|
||||
5
|
||||
</td>
|
||||
<td
|
||||
className="TableCell-root StoryRow-statusColumn TableCell-body"
|
||||
@@ -574,23 +650,45 @@ exports[`renders stories 1`] = `
|
||||
<td
|
||||
className="TableCell-root StoryRow-titleColumn TableCell-body"
|
||||
>
|
||||
<a
|
||||
className="TextLink-root"
|
||||
href="/admin/moderate/stories/story-2"
|
||||
onClick={[Function]}
|
||||
<div
|
||||
className="Box-root HorizontalGutter-root HorizontalGutter-full"
|
||||
>
|
||||
First Colony on Mars
|
||||
</a>
|
||||
<p>
|
||||
<a
|
||||
className="TextLink-root"
|
||||
href="/admin/moderate/stories/story-2"
|
||||
onClick={[Function]}
|
||||
>
|
||||
First Colony on Mars
|
||||
</a>
|
||||
</p>
|
||||
<p
|
||||
className="StoryRow-meta"
|
||||
>
|
||||
<span
|
||||
className="StoryRow-authorName"
|
||||
>
|
||||
Linh Nguyen
|
||||
</span>
|
||||
|
||||
11/29/2018, 4:01 PM
|
||||
</p>
|
||||
</div>
|
||||
</td>
|
||||
<td
|
||||
className="TableCell-root StoryRow-authorColumn TableCell-body"
|
||||
className="TableCell-root StoryRow-reportedCountColumn StoryRow-boldColumn TableCell-body"
|
||||
>
|
||||
Linh Nguyen
|
||||
3
|
||||
</td>
|
||||
<td
|
||||
className="TableCell-root StoryRow-publishDateColumn TableCell-body"
|
||||
className="TableCell-root StoryRow-pendingCountColumn StoryRow-boldColumn TableCell-body"
|
||||
>
|
||||
11/29/2018, 4:01 PM
|
||||
2
|
||||
</td>
|
||||
<td
|
||||
className="TableCell-root StoryRow-totalCountColumn StoryRow-boldColumn TableCell-body"
|
||||
>
|
||||
5
|
||||
</td>
|
||||
<td
|
||||
className="TableCell-root StoryRow-statusColumn TableCell-body"
|
||||
|
||||
@@ -45,8 +45,9 @@ const BanUserMutation = createMutation(
|
||||
`,
|
||||
variables: {
|
||||
input: {
|
||||
message: input.message,
|
||||
userID: input.userID,
|
||||
message: input.message,
|
||||
rejectExistingComments: input.rejectExistingComments,
|
||||
clientMutationId: clientMutationId.toString(),
|
||||
},
|
||||
},
|
||||
|
||||
+1
@@ -38,6 +38,7 @@ const UserBanPopoverContainer: FunctionComponent<Props> = ({
|
||||
banUser({
|
||||
userID: user.id,
|
||||
commentID: comment.id,
|
||||
rejectExistingComments: false,
|
||||
message: getMessage(
|
||||
localeBundles,
|
||||
"common-banEmailTemplate",
|
||||
|
||||
@@ -229,6 +229,7 @@ it("ban user", async () => {
|
||||
banUser: ({ variables }) => {
|
||||
expectAndFail(variables).toMatchObject({
|
||||
userID: firstComment.author!.id,
|
||||
rejectExistingComments: false,
|
||||
});
|
||||
return {
|
||||
user: pureMerge<typeof firstComment.author>(firstComment.author, {
|
||||
|
||||
@@ -18,6 +18,7 @@ export type GraphMiddlewareOptions = Pick<
|
||||
| "tenantCache"
|
||||
| "metrics"
|
||||
| "broker"
|
||||
| "rejectorQueue"
|
||||
>;
|
||||
|
||||
export const graphQLHandler = ({
|
||||
|
||||
@@ -18,6 +18,7 @@ import { Config } from "coral-server/config";
|
||||
import CoralEventListenerBroker from "coral-server/events/publisher";
|
||||
import logger from "coral-server/logger";
|
||||
import { MailerQueue } from "coral-server/queue/tasks/mailer";
|
||||
import { RejectorQueue } from "coral-server/queue/tasks/rejector";
|
||||
import { ScraperQueue } from "coral-server/queue/tasks/scraper";
|
||||
import { I18n } from "coral-server/services/i18n";
|
||||
import { JWTSigningConfig } from "coral-server/services/jwt";
|
||||
@@ -52,6 +53,7 @@ export interface AppOptions {
|
||||
tenantCache: TenantCache;
|
||||
migrationManager: MigrationManager;
|
||||
broker: CoralEventListenerBroker;
|
||||
rejectorQueue: RejectorQueue;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,7 @@ import { PersistedQuery } from "coral-server/models/queries";
|
||||
import { Tenant } from "coral-server/models/tenant";
|
||||
import { User } from "coral-server/models/user";
|
||||
import { MailerQueue } from "coral-server/queue/tasks/mailer";
|
||||
import { RejectorQueue } from "coral-server/queue/tasks/rejector";
|
||||
import { ScraperQueue } from "coral-server/queue/tasks/scraper";
|
||||
import { I18n } from "coral-server/services/i18n";
|
||||
import { JWTSigningConfig } from "coral-server/services/jwt";
|
||||
@@ -40,6 +41,7 @@ export interface GraphContextOptions {
|
||||
mongo: Db;
|
||||
pubsub: RedisPubSub;
|
||||
redis: AugmentedRedis;
|
||||
rejectorQueue: RejectorQueue;
|
||||
scraperQueue: ScraperQueue;
|
||||
tenant: Tenant;
|
||||
tenantCache: TenantCache;
|
||||
@@ -61,6 +63,7 @@ export default class GraphContext {
|
||||
public readonly now: Date;
|
||||
public readonly pubsub: RedisPubSub;
|
||||
public readonly redis: AugmentedRedis;
|
||||
public readonly rejectorQueue: RejectorQueue;
|
||||
public readonly scraperQueue: ScraperQueue;
|
||||
public readonly tenant: Tenant;
|
||||
public readonly tenantCache: TenantCache;
|
||||
@@ -94,6 +97,7 @@ export default class GraphContext {
|
||||
this.tenantCache = options.tenantCache;
|
||||
this.scraperQueue = options.scraperQueue;
|
||||
this.mailerQueue = options.mailerQueue;
|
||||
this.rejectorQueue = options.rejectorQueue;
|
||||
this.signingConfig = options.signingConfig;
|
||||
this.clientID = options.clientID;
|
||||
|
||||
|
||||
@@ -229,10 +229,12 @@ export const Users = (ctx: GraphContext) => ({
|
||||
ban(
|
||||
ctx.mongo,
|
||||
ctx.mailerQueue,
|
||||
ctx.rejectorQueue,
|
||||
ctx.tenant,
|
||||
ctx.user!,
|
||||
input.userID,
|
||||
input.message,
|
||||
input.rejectExistingComments || false,
|
||||
ctx.now
|
||||
),
|
||||
premodUser: async (input: GQLPremodUserInput) =>
|
||||
|
||||
@@ -5491,6 +5491,11 @@ input BanUserInput {
|
||||
message is sent to banned user via email.
|
||||
"""
|
||||
message: String!
|
||||
|
||||
"""
|
||||
whether or not to reject all the user's previous comments when banning them.
|
||||
"""
|
||||
rejectExistingComments: Boolean
|
||||
}
|
||||
|
||||
type BanUserPayload {
|
||||
|
||||
@@ -253,6 +253,7 @@ class Server {
|
||||
this.tasks.scraper.process();
|
||||
this.tasks.notifier.process();
|
||||
this.tasks.webhook.process();
|
||||
this.tasks.rejector.process();
|
||||
|
||||
// Start up the cron job processors.
|
||||
this.scheduledTasks = startScheduledTasks({
|
||||
@@ -354,6 +355,7 @@ class Server {
|
||||
i18n: this.i18n,
|
||||
mailerQueue: this.tasks.mailer,
|
||||
scraperQueue: this.tasks.scraper,
|
||||
rejectorQueue: this.tasks.rejector,
|
||||
disableClientRoutes,
|
||||
persistedQueryCache: this.persistedQueryCache,
|
||||
persistedQueriesRequired:
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import Queue from "bull";
|
||||
import { Redis } from "ioredis";
|
||||
import { Db } from "mongodb";
|
||||
|
||||
import { Config } from "coral-server/config";
|
||||
import { I18n } from "coral-server/services/i18n";
|
||||
import { JWTSigningConfig } from "coral-server/services/jwt";
|
||||
import { createRedisClient } from "coral-server/services/redis";
|
||||
import { AugmentedRedis, createRedisClient } from "coral-server/services/redis";
|
||||
import TenantCache from "coral-server/services/tenant/cache";
|
||||
|
||||
import { createMailerTask, MailerQueue } from "./tasks/mailer";
|
||||
import { createNotifierTask, NotifierQueue } from "./tasks/notifier";
|
||||
import { createRejectorTask, RejectorQueue } from "./tasks/rejector";
|
||||
import { createScraperTask, ScraperQueue } from "./tasks/scraper";
|
||||
import { createWebhookTask, WebhookQueue } from "./tasks/webhook";
|
||||
|
||||
@@ -49,7 +49,7 @@ export interface QueueOptions {
|
||||
tenantCache: TenantCache;
|
||||
i18n: I18n;
|
||||
signingConfig: JWTSigningConfig;
|
||||
redis: Redis;
|
||||
redis: AugmentedRedis;
|
||||
}
|
||||
|
||||
export interface TaskQueue {
|
||||
@@ -57,6 +57,7 @@ export interface TaskQueue {
|
||||
scraper: ScraperQueue;
|
||||
notifier: NotifierQueue;
|
||||
webhook: WebhookQueue;
|
||||
rejector: RejectorQueue;
|
||||
}
|
||||
|
||||
export async function createQueue(options: QueueOptions): Promise<TaskQueue> {
|
||||
@@ -73,11 +74,14 @@ export async function createQueue(options: QueueOptions): Promise<TaskQueue> {
|
||||
});
|
||||
const webhook = createWebhookTask(queueOptions, options);
|
||||
|
||||
const rejector = createRejectorTask(queueOptions, options);
|
||||
|
||||
// Return the tasks + client.
|
||||
return {
|
||||
mailer,
|
||||
scraper,
|
||||
notifier,
|
||||
webhook,
|
||||
rejector,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
import Queue, { Job } from "bull";
|
||||
import { Db } from "mongodb";
|
||||
import now from "performance-now";
|
||||
|
||||
import { Config } from "coral-server/config";
|
||||
import logger from "coral-server/logger";
|
||||
import {
|
||||
Comment,
|
||||
getLatestRevision,
|
||||
retrieveAllCommentsUserConnection,
|
||||
} from "coral-server/models/comment";
|
||||
import { Connection } from "coral-server/models/helpers";
|
||||
import Task from "coral-server/queue/Task";
|
||||
import { AugmentedRedis } from "coral-server/services/redis";
|
||||
import TenantCache from "coral-server/services/tenant/cache";
|
||||
import { rejectComment } from "coral-server/stacks";
|
||||
|
||||
import { GQLCOMMENT_SORT } from "coral-server/graph/schema/__generated__/types";
|
||||
|
||||
const JOB_NAME = "rejector";
|
||||
|
||||
export interface RejectorProcessorOptions {
|
||||
mongo: Db;
|
||||
redis: AugmentedRedis;
|
||||
config: Config;
|
||||
tenantCache: TenantCache;
|
||||
}
|
||||
|
||||
export interface RejectorData {
|
||||
authorID: string;
|
||||
moderatorID: string;
|
||||
tenantID: string;
|
||||
}
|
||||
|
||||
function getBatch(
|
||||
mongo: Db,
|
||||
tenantID: string,
|
||||
authorID: string,
|
||||
connection?: Readonly<Connection<Readonly<Comment>>>
|
||||
) {
|
||||
return retrieveAllCommentsUserConnection(mongo, tenantID, authorID, {
|
||||
orderBy: GQLCOMMENT_SORT.CREATED_AT_DESC,
|
||||
first: 100,
|
||||
after: connection ? connection.pageInfo.endCursor : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
const createJobProcessor = ({
|
||||
mongo,
|
||||
redis,
|
||||
tenantCache,
|
||||
config,
|
||||
}: RejectorProcessorOptions) => async (job: Job<RejectorData>) => {
|
||||
// Pull out the job data.
|
||||
const { authorID, moderatorID, tenantID } = job.data;
|
||||
const log = logger.child(
|
||||
{
|
||||
jobID: job.id,
|
||||
jobName: JOB_NAME,
|
||||
authorID,
|
||||
moderatorID,
|
||||
tenantID,
|
||||
},
|
||||
true
|
||||
);
|
||||
// Mark the start time.
|
||||
const startTime = now();
|
||||
log.debug("starting to reject author comments");
|
||||
// Get the tenant.
|
||||
const tenant = await tenantCache.retrieveByID(tenantID);
|
||||
if (!tenant) {
|
||||
log.error("referenced tenant was not found");
|
||||
return;
|
||||
}
|
||||
// Get the current time.
|
||||
const currentTime = new Date();
|
||||
try {
|
||||
// Find all comments written by the author that should be rejected.
|
||||
let connection = await getBatch(mongo, tenantID, authorID);
|
||||
while (connection.nodes.length > 0) {
|
||||
for (const comment of connection.nodes) {
|
||||
// Get the latest revision of the comment.
|
||||
const revision = getLatestRevision(comment);
|
||||
// Reject the comment.
|
||||
await rejectComment(
|
||||
mongo,
|
||||
redis,
|
||||
config,
|
||||
null,
|
||||
tenant,
|
||||
comment.id,
|
||||
revision.id,
|
||||
moderatorID,
|
||||
currentTime
|
||||
);
|
||||
}
|
||||
// If there was not another page, abort processing.
|
||||
if (!connection.pageInfo.hasNextPage) {
|
||||
break;
|
||||
}
|
||||
// Load the next page.
|
||||
connection = await getBatch(mongo, tenantID, authorID, connection);
|
||||
}
|
||||
} catch (err) {
|
||||
log.error({ err }, "could not reject the author's comments");
|
||||
throw err;
|
||||
}
|
||||
// Compute the end time.
|
||||
const took = Math.round(now() - startTime);
|
||||
log.debug({ took }, "rejected the author's comments");
|
||||
};
|
||||
|
||||
export type RejectorQueue = Task<RejectorData>;
|
||||
|
||||
export function createRejectorTask(
|
||||
queue: Queue.QueueOptions,
|
||||
options: RejectorProcessorOptions
|
||||
) {
|
||||
return new Task({
|
||||
jobName: JOB_NAME,
|
||||
jobProcessor: createJobProcessor(options),
|
||||
queue,
|
||||
});
|
||||
}
|
||||
@@ -71,6 +71,7 @@ import {
|
||||
hasStaffRole,
|
||||
} from "coral-server/models/user/helpers";
|
||||
import { MailerQueue } from "coral-server/queue/tasks/mailer";
|
||||
import { RejectorQueue } from "coral-server/queue/tasks/rejector";
|
||||
import { JWTSigningConfig, signPATString } from "coral-server/services/jwt";
|
||||
import { sendConfirmationEmail } from "coral-server/services/users/auth";
|
||||
|
||||
@@ -816,19 +817,23 @@ export async function destroyModeratorNote(
|
||||
*
|
||||
* @param mongo mongo database to interact with
|
||||
* @param mailer the mailer
|
||||
* @param rejector the comment rejector queue
|
||||
* @param tenant Tenant where the User will be banned on
|
||||
* @param banner the User that is banning the User
|
||||
* @param userID the ID of the User being banned
|
||||
* @param message message to banned user
|
||||
* @param rejectExistingComments whether all the authors previous comments should be rejected
|
||||
* @param now the current time that the ban took effect
|
||||
*/
|
||||
export async function ban(
|
||||
mongo: Db,
|
||||
mailer: MailerQueue,
|
||||
rejector: RejectorQueue,
|
||||
tenant: Tenant,
|
||||
banner: User,
|
||||
userID: string,
|
||||
message: string,
|
||||
rejectExistingComments: boolean,
|
||||
now = new Date()
|
||||
) {
|
||||
// Get the user being banned to check to see if the user already has an
|
||||
@@ -847,6 +852,14 @@ export async function ban(
|
||||
// Ban the user.
|
||||
const user = await banUser(mongo, tenant.id, userID, banner.id, message, now);
|
||||
|
||||
if (rejectExistingComments) {
|
||||
await rejector.add({
|
||||
tenantID: tenant.id,
|
||||
authorID: userID,
|
||||
moderatorID: banner.id,
|
||||
});
|
||||
}
|
||||
|
||||
// If the user has an email address associated with their account, send them
|
||||
// a ban notification email.
|
||||
if (user.email) {
|
||||
|
||||
@@ -20,7 +20,7 @@ const rejectComment = async (
|
||||
mongo: Db,
|
||||
redis: AugmentedRedis,
|
||||
config: Config,
|
||||
broker: CoralEventPublisherBroker,
|
||||
broker: CoralEventPublisherBroker | null,
|
||||
tenant: Tenant,
|
||||
commentID: string,
|
||||
commentRevisionID: string,
|
||||
@@ -48,12 +48,16 @@ const rejectComment = async (
|
||||
actionCounts: {},
|
||||
});
|
||||
|
||||
// Publish changes to the event publisher.
|
||||
await publishChanges(broker, {
|
||||
...result,
|
||||
...counts,
|
||||
moderatorID,
|
||||
});
|
||||
// TODO: (wyattjoh) (tessalt) broker cannot easily be passed to stack from tasks,
|
||||
// see CORL-935 in jira
|
||||
if (broker) {
|
||||
// Publish changes to the event publisher.
|
||||
await publishChanges(broker, {
|
||||
...result,
|
||||
...counts,
|
||||
moderatorID,
|
||||
});
|
||||
}
|
||||
|
||||
// If there was a featured tag on this comment, remove it.
|
||||
if (hasTag(result.after, GQLTAG.FEATURED)) {
|
||||
|
||||
@@ -833,6 +833,7 @@ community-banModal-consequence =
|
||||
community-banModal-cancel = Cancel
|
||||
community-banModal-banUser = Ban User
|
||||
community-banModal-customize = Customize ban email message
|
||||
community-banModal-reject-existing = Reject all comments by this user
|
||||
|
||||
community-suspendModal-areYouSure = Suspend <strong>{ $username }</strong>?
|
||||
community-suspendModal-consequence =
|
||||
@@ -916,6 +917,9 @@ stories-column-author = Author
|
||||
stories-column-publishDate = Publish Date
|
||||
stories-column-status = Status
|
||||
stories-column-clickToModerate = Click title to moderate story
|
||||
stories-column-reportedCount = Reported
|
||||
stories-column-pendingCount = Pending
|
||||
stories-column-totalCount = Total
|
||||
|
||||
stories-status-popover =
|
||||
.description = A dropdown to change the story status
|
||||
|
||||
Reference in New Issue
Block a user