fix(profiles): restore reporting functionality
Also remove unused and/or unrelated code and clean up comments
This commit is contained in:
@@ -2,12 +2,6 @@ import _ from 'lodash';
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import { authWithHeaders, authWithSession } from '../../middlewares/auth';
|
||||
import { model as Challenge } from '../../models/challenge';
|
||||
import bannedWords from '../../libs/bannedWords';
|
||||
import bannedSlurs from '../../libs/bannedSlurs';
|
||||
import { getMatchesByWordArray } from '../../libs/stringUtils';
|
||||
import { stringContainsProfanity } from '../../libs/user/validation';
|
||||
import * as slack from '../../libs/slack';
|
||||
import { getUserInfo } from '../../libs/email';
|
||||
import {
|
||||
model as Group,
|
||||
basicFields as basicGroupFields,
|
||||
@@ -18,7 +12,6 @@ import {
|
||||
nameFields,
|
||||
} from '../../models/user';
|
||||
import {
|
||||
BadRequest,
|
||||
NotFound,
|
||||
NotAuthorized,
|
||||
} from '../../libs/errors';
|
||||
@@ -46,16 +39,6 @@ const { MAX_SUMMARY_SIZE_FOR_CHALLENGES } = common.constants;
|
||||
|
||||
const api = {};
|
||||
|
||||
function textContainsBannedWord (message) {
|
||||
const bannedWordsMatched = getMatchesByWordArray(message, bannedWords);
|
||||
return bannedWordsMatched.length > 0;
|
||||
}
|
||||
|
||||
function textContainsBannedSlur (message) {
|
||||
const bannedSlursMatched = getMatchesByWordArray(message, bannedSlurs);
|
||||
return bannedSlursMatched.length > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @apiDefine ChallengeLeader Challenge Leader
|
||||
* The leader of the challenge can use this route.
|
||||
@@ -229,53 +212,7 @@ api.createChallenge = {
|
||||
const validationErrors = req.validationErrors();
|
||||
if (validationErrors) throw validationErrors;
|
||||
|
||||
const group = await Group.getGroup({
|
||||
user, groupId: req.body.group, fields: basicGroupFields, optionalMembership: true,
|
||||
});
|
||||
|
||||
// checks public challenge for slurs
|
||||
|
||||
if (group.privacy === 'public'
|
||||
&& ((textContainsBannedSlur(req.body.name))
|
||||
|| (textContainsBannedSlur(req.body.shortName))
|
||||
|| (textContainsBannedSlur(req.body.summary))
|
||||
|| (textContainsBannedSlur(req.body.description)))) {
|
||||
// slack flagged-posts
|
||||
const authorEmail = getUserInfo(user, ['email']).email;
|
||||
slack.sendChallengeSlurNotification({
|
||||
authorEmail,
|
||||
author: user,
|
||||
uuid: user.id,
|
||||
language: user.preferences.language,
|
||||
problemContent: [
|
||||
req.body.name,
|
||||
req.body.shortName,
|
||||
req.body.summary,
|
||||
req.body.description,
|
||||
],
|
||||
});
|
||||
|
||||
// user flags
|
||||
user.flags.chatRevoked = true;
|
||||
await user.save();
|
||||
|
||||
// toast notification
|
||||
throw new BadRequest(res.t('challengeBannedSlurs'));
|
||||
}
|
||||
|
||||
// checks public challenges for banned words
|
||||
if (group.privacy === 'public'
|
||||
&& ((textContainsBannedWord(req.body.name))
|
||||
|| (textContainsBannedWord(req.body.shortName))
|
||||
|| (textContainsBannedWord(req.body.summary))
|
||||
|| (textContainsBannedWord(req.body.description)))) {
|
||||
// toast error
|
||||
throw new BadRequest(res.t('challengeBannedWords'));
|
||||
}
|
||||
|
||||
const { savedChal } = await createChallenge(user, req, res);
|
||||
|
||||
await user.save();
|
||||
const { savedChal, group } = await createChallenge(user, req, res);
|
||||
|
||||
const response = savedChal.toJSON();
|
||||
response.leader = { // the leader is the authenticated user
|
||||
|
||||
@@ -137,39 +137,6 @@ api.postChat = {
|
||||
throw new BadRequest(res.t('featureRetired'));
|
||||
}
|
||||
|
||||
// Check message for banned slurs
|
||||
if (group && group.privacy !== 'private' && textContainsBannedSlur(req.body.message)) {
|
||||
const { message } = req.body;
|
||||
user.flags.chatRevoked = true;
|
||||
await user.save();
|
||||
|
||||
// Email the mods
|
||||
const authorEmail = getUserInfo(user, ['email']).email;
|
||||
|
||||
// Slack the mods
|
||||
slack.sendSlurNotification({
|
||||
authorEmail,
|
||||
author: user,
|
||||
group,
|
||||
message,
|
||||
});
|
||||
|
||||
throw new BadRequest(res.t('bannedSlurUsed'));
|
||||
}
|
||||
|
||||
if (group.privacy === 'public' && user.flags.chatRevoked) {
|
||||
throw new NotAuthorized(res.t('chatPrivilegesRevoked'));
|
||||
}
|
||||
|
||||
// prevent banned words being posted, except in private guilds/parties
|
||||
// and in certain public guilds with specific topics
|
||||
if (group.privacy === 'public' && !group.bannedWordsAllowed) {
|
||||
const matchedBadWords = getBannedWordsFromText(req.body.message);
|
||||
if (matchedBadWords.length > 0) {
|
||||
throw new BadRequest(res.t('bannedWordUsed', { swearWordsUsed: matchedBadWords.join(', ') }));
|
||||
}
|
||||
}
|
||||
|
||||
const chatRes = await Group.toJSONCleanChat(group, user);
|
||||
const lastClientMsg = req.query.previousMsg;
|
||||
const chatUpdated = !!(
|
||||
|
||||
@@ -5,13 +5,6 @@ import moment from 'moment';
|
||||
import logger from './logger';
|
||||
import { getCurrentEvent } from './worldState'; // eslint-disable-line import/no-cycle
|
||||
import { TAVERN_ID } from '../models/group'; // eslint-disable-line import/no-cycle
|
||||
// import bannedSlurs from './bannedSlurs';
|
||||
// import { getMatchesByWordArray } from '../../libs/stringUtils';
|
||||
|
||||
// function textContainsBannedSlur (message) {
|
||||
// const bannedSlursMatched = getMatchesByWordArray(message, bannedSlurs);
|
||||
// return bannedSlursMatched.length > 0;
|
||||
// }
|
||||
|
||||
const SLACK_FLAGGING_URL = nconf.get('SLACK_FLAGGING_URL');
|
||||
const SLACK_FLAGGING_FOOTER_LINK = nconf.get('SLACK_FLAGGING_FOOTER_LINK');
|
||||
@@ -230,9 +223,12 @@ function sendProfileFlagNotification ({
|
||||
if (userComment) {
|
||||
text += ` and commented: ${userComment}`;
|
||||
}
|
||||
let profileData = `Display Name: ${flaggedUser.profile.displayName}`;
|
||||
let profileData = `Display Name: ${flaggedUser.profile.name}`;
|
||||
if (flaggedUser.profile.imageUrl) {
|
||||
profileData += `\n\nImage URL: ${flaggedUser.profile.imageUrl}`;
|
||||
}
|
||||
if (flaggedUser.profile.blurb) {
|
||||
profileData += `\n\nAbout: ${flaggedUser.profile.newBlurb}`;
|
||||
profileData += `\n\nAbout: ${flaggedUser.profile.blurb}`;
|
||||
}
|
||||
|
||||
flagSlack
|
||||
@@ -243,7 +239,7 @@ function sendProfileFlagNotification ({
|
||||
color: 'danger',
|
||||
title,
|
||||
title_link: titleLink,
|
||||
body: profileData,
|
||||
text: profileData,
|
||||
mrkdwn_in: [
|
||||
'text',
|
||||
],
|
||||
@@ -328,54 +324,6 @@ function sendShadowMutedPostNotification ({
|
||||
.catch(err => logger.error(err, 'Error while sending flag data to Slack.'));
|
||||
}
|
||||
|
||||
// slack slur notification for Parties/Groups
|
||||
function sendGroupSlurNotification ({
|
||||
authorEmail,
|
||||
author,
|
||||
group,
|
||||
message,
|
||||
}) {
|
||||
if (SKIP_FLAG_METHODS) {
|
||||
return;
|
||||
}
|
||||
const text = `${author.profile.name} (${author._id}) tried to post a slur,`;
|
||||
|
||||
let titleLink;
|
||||
let title;
|
||||
|
||||
if (group.type === 'party') {
|
||||
titleLink = `${BASE_URL}/party/${group._id}`;
|
||||
} else if (group.type === 'group-plans') {
|
||||
titleLink = `${BASE_URL}/group-plans/${group._id}`;
|
||||
} else {
|
||||
title += ` - (${group.type})`;
|
||||
}
|
||||
|
||||
const authorName = formatUser({
|
||||
name: author.auth.local.username,
|
||||
displayName: author.profile.name,
|
||||
email: authorEmail,
|
||||
uuid: author.id,
|
||||
});
|
||||
|
||||
flagSlack
|
||||
.send({
|
||||
text,
|
||||
attachments: [{
|
||||
fallback: 'Slur Message',
|
||||
color: 'danger',
|
||||
author_name: authorName,
|
||||
title,
|
||||
title_link: titleLink,
|
||||
text: message,
|
||||
mrkdwn_in: [
|
||||
'text',
|
||||
],
|
||||
}],
|
||||
})
|
||||
.catch(err => logger.error(err, 'Error while sending flag data to Slack.'));
|
||||
}
|
||||
|
||||
// slack slur notification for Profiles
|
||||
function sendProfileSlurNotification ({
|
||||
authorEmail,
|
||||
@@ -410,44 +358,6 @@ function sendProfileSlurNotification ({
|
||||
.catch(err => logger.error(err, 'Error while sending flag data to Slack.'));
|
||||
}
|
||||
|
||||
function sendChallengeSlurNotification ({
|
||||
authorEmail,
|
||||
author,
|
||||
language,
|
||||
problemContent,
|
||||
uuid,
|
||||
}) {
|
||||
if (SKIP_FLAG_METHODS) {
|
||||
return;
|
||||
}
|
||||
const text = `${author.profile.name} ${authorEmail} (${uuid}, ${language}) tried to create a Challenge with a slur or banned word.`;
|
||||
const title = 'Challenge Report: Slur/Banned Word';
|
||||
|
||||
const authorName = formatUser({
|
||||
name: author.auth.local.username,
|
||||
displayName: author.profile.name,
|
||||
email: authorEmail,
|
||||
language,
|
||||
uuid,
|
||||
});
|
||||
|
||||
flagSlack
|
||||
.send({
|
||||
text,
|
||||
attachments: [{
|
||||
fallback: 'Slur Message',
|
||||
color: 'danger',
|
||||
title,
|
||||
author_name: authorName,
|
||||
text: problemContent,
|
||||
mrkdwn_in: [
|
||||
'text',
|
||||
],
|
||||
}],
|
||||
})
|
||||
.catch(err => logger.error(err, 'Error while sending flag data to Slack.'));
|
||||
}
|
||||
|
||||
export {
|
||||
sendFlagNotification,
|
||||
sendInboxFlagNotification,
|
||||
@@ -455,8 +365,6 @@ export {
|
||||
sendProfileFlagNotification,
|
||||
sendSubscriptionNotification,
|
||||
sendShadowMutedPostNotification,
|
||||
sendGroupSlurNotification,
|
||||
sendProfileSlurNotification,
|
||||
sendChallengeSlurNotification,
|
||||
formatUser,
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import bannedSlurs from '../bannedSlurs';
|
||||
// import bannedWords from '../bannedWords';
|
||||
import bannedWords from '../bannedWords';
|
||||
import {
|
||||
getMatchesByWordArray,
|
||||
normalizeUnicodeString,
|
||||
@@ -8,13 +8,10 @@ import {
|
||||
import forbiddenUsernames from '../forbiddenUsernames';
|
||||
|
||||
const bannedSlurRegexes = bannedSlurs.map(word => new RegExp(`\\b([^a-z]+)?${word}([^a-z]+)?\\b`, 'i'));
|
||||
// const bannedWordRegexes = bannedWords.map(word =>
|
||||
// new RegExp(`\\b([^a-z]+)?${word}([^a-z]+)?\\b`, 'i'));
|
||||
const bannedWordRegexes = bannedWords.map(word => new RegExp(`\\b([^a-z]+)?${word}([^a-z]+)?\\b`, 'i'));
|
||||
|
||||
export function stringContainsProfanity (str, profanityType = 'bannedWord') {
|
||||
const bannedRegexes = profanityType === 'slur'
|
||||
&& bannedSlurRegexes;
|
||||
// : bannedWordRegexes;
|
||||
const bannedRegexes = profanityType === 'slur' ? bannedSlurRegexes : bannedWordRegexes;
|
||||
|
||||
for (let i = 0; i < bannedRegexes.length; i += 1) {
|
||||
const regEx = bannedRegexes[i];
|
||||
@@ -44,7 +41,6 @@ function usernameContainsInvalidCharacters (username) {
|
||||
export function verifyDisplayName (displayName, res) {
|
||||
const issues = [];
|
||||
if (displayName.length < 1 || displayName.length > 30) issues.push(res.t('displaynameIssueLength'));
|
||||
if (stringContainsProfanity(displayName)) issues.push(res.t('bannedWordUsedInProfile'));
|
||||
if (stringContainsProfanity(displayName, 'slur')) issues.push(res.t('bannedSlurUsedInProfile'));
|
||||
if (nameContainsNewline(displayName)) issues.push(res.t('displaynameIssueNewline'));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user