Skip to content

Commit

Permalink
preliminarily format legal grounds/explanation into notifications
Browse files Browse the repository at this point in the history
shows that we can process these fields, translate, and format
them nicely on the notification components stream side.
  • Loading branch information
nick-funk committed Nov 9, 2023
1 parent 9912155 commit 766a332
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { FunctionComponent, useMemo } from "react";
import { graphql } from "react-relay";

import { withFragmentContainer } from "coral-framework/lib/relay";
import HTMLContent from "coral-stream/common/HTMLContent";
import { CheckCircleIcon, SvgIcon } from "coral-ui/components/icons";
import { Timestamp } from "coral-ui/components/v2";

Expand Down Expand Up @@ -35,6 +36,9 @@ const NotificationContainer: FunctionComponent<Props> = ({
return createdAtDate.getTime() <= lastSeenDate.getTime();
}, [createdAt, viewer]);

// eslint-disable-next-line no-console
console.log(body);

return (
<>
<div
Expand All @@ -49,7 +53,11 @@ const NotificationContainer: FunctionComponent<Props> = ({
<div className={styles.titleText}>{title}</div>
</div>
)}
{body && <div className={cn(styles.body)}>{body}</div>}
{body && (
<div className={cn(styles.body)}>
<HTMLContent>{body || ""}</HTMLContent>
</div>
)}
{comment && (
<div className={styles.contextItem}>
<NotificationCommentContainer
Expand Down
14 changes: 12 additions & 2 deletions server/src/core/server/locales/en-US/common.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,15 @@ notifications-commentWasRejected-body = The comment { $commentID } was rejected.
notifications-commentWasRejectedAndIllegal-title = Comment was deemed to contain illegal content and was rejected
notifications-commentWasRejectedAndIllegal-body =
The comment { $commentID } was rejected for containing illegal content.
The reason of which was: { $reason }
notifications-rejectedReason-illegal-fraud = Comment contained fraudulent information.
The reason of which was:
<br/>
{ $reason }
notifications-dsaIllegalRejectedReason-information =
Grounds:
<br/>
{ $grounds }
<br/>
Explanation:
<br/>
{ $explanation }
notifications-dsaIllegalRejectedReason-informationNotFound = The reasoning for this decision cannot be found.
8 changes: 6 additions & 2 deletions server/src/core/server/services/dsaReports/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ export async function makeDSAReportDecision(
commentID,
commentRevisionID,
userID,
// legalGrounds,
// detailedExplanation,
legalGrounds,
detailedExplanation,
} = input;

// REJECT if ILLEGAL
Expand All @@ -215,6 +215,10 @@ export async function makeDSAReportDecision(
targetUserID: comment.authorID,
type: NotificationType.ILLEGAL_REJECTED,
comment,
legal: {
grounds: legalGrounds,
explanation: detailedExplanation,
},
});
}
}
Expand Down
56 changes: 40 additions & 16 deletions server/src/core/server/services/notifications/internal/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ export enum NotificationType {
ILLEGAL_REJECTED = "ILLEGAL_REJECTED",
}

export interface LegalExplanation {
grounds?: string;
explanation?: string;
}

export interface CreateNotificationInput {
targetUserID: string;
type: NotificationType;

comment?: Readonly<Comment>;
report?: Readonly<DSAReport>;

legal?: LegalExplanation;
}

interface CreationResult {
Expand All @@ -48,7 +55,7 @@ export class InternalNotificationContext {
lang: LanguageCode,
input: CreateNotificationInput
) {
const { type, targetUserID, comment } = input;
const { type, targetUserID, comment, legal } = input;

const existingUser = retrieveUser(this.mongo, tenantID, targetUserID);
if (!existingUser) {
Expand Down Expand Up @@ -141,6 +148,7 @@ export class InternalNotificationContext {
tenantID,
targetUserID,
comment,
legal,
now
);
result.attempted = true;
Expand All @@ -156,13 +164,39 @@ export class InternalNotificationContext {
tenantID: string,
targetUserID: string,
comment: Readonly<Comment>,
legal: LegalExplanation | undefined,
now: Date
) {
const reason = this.translatePhrase(
const reason = legal
? this.translatePhrase(
lang,
"notifications-dsaIllegalRejectedReason-information",
`Grounds:
${legal?.grounds}
Explanation:
${legal?.explanation}`,
{
grounds: legal.grounds,
explanation: legal.explanation,
}
)
: this.translatePhrase(
lang,
"notifications-dsaIllegalRejectedReason-informationNotFound",
"The reasoning for this decision cannot be found."
);

const body = this.translatePhrase(
lang,
"notifications-rejectedReason-illegal-fraud",
"Comment contained fraudulent information."
);
"notifications-commentWasRejectedAndIllegal-body",
`The comment ${comment.id} was rejected for containing illegal content.
The reason of which was: ${reason}
`,
{
commentID: comment.id,
reason,
}
).replace("\n", "<br/>");

const notification = await createNotification(this.mongo, {
id: uuid(),
Expand All @@ -174,17 +208,7 @@ export class InternalNotificationContext {
"notifications-commentWasRejectedAndIllegal-title",
"Comment was deemed to contain illegal content and was rejected"
),
body: this.translatePhrase(
lang,
"notifications-commentWasRejectedAndIllegal-body",
`The comment ${comment.id} was rejected for containing illegal content.
The reason of which was: ${reason}
`,
{
commentID: comment.id,
reason,
}
),
body,
commentID: comment.id,
commentStatus: comment.status,
});
Expand Down

0 comments on commit 766a332

Please sign in to comment.