From 02ef7e8822a8b9e2680423fdebf5f03a2c51262f Mon Sep 17 00:00:00 2001 From: CuriousMagpie Date: Tue, 12 Dec 2023 17:22:29 -0500 Subject: [PATCH] feat(slur blocker): arghhhhhh --- website/server/libs/slack.js | 20 ++--------- website/server/libs/user/index.js | 58 +++++++++++++------------------ 2 files changed, 27 insertions(+), 51 deletions(-) diff --git a/website/server/libs/slack.js b/website/server/libs/slack.js index f8f2be0113..4e814645c1 100644 --- a/website/server/libs/slack.js +++ b/website/server/libs/slack.js @@ -231,11 +231,8 @@ function sendProfileFlagNotification ({ text += ` and commented: ${userComment}`; } let profileData = `Display Name: ${flaggedUser.profile.displayName}`; - // if (flaggedUser.profile.imageUrl) { - // profileData += `\n\nImage URL: ${flaggedUser.profile.imageUrl}`; - // } if (flaggedUser.profile.blurb) { - profileData += `\n\nAbout: ${flaggedUser.profile.blurb}`; + profileData += `\n\nAbout: ${flaggedUser.profile.newBlurb}`; } flagSlack @@ -385,10 +382,7 @@ function sendProfileSlurNotification ({ author, uuid, language, - displayName, - // userBlurb, - // imageUrl, - body, + problemContent, }) { if (SKIP_FLAG_METHODS) { return; @@ -399,17 +393,9 @@ function sendProfileSlurNotification ({ const text = `@${author} (${uuid}, ${language}) tried to post a slur in their Profile.`; const authorName = formatUser({ name: author, - displayName, email: authorEmail, uuid, }); - let profileData = `Display Name: ${displayName}`; - if (body) { - profileData += `\n\n${body.userBlurb}`; - } - if (body) { - profileData += `\n\n${body.imageUrl}`; - } flagSlack .send({ @@ -420,7 +406,7 @@ function sendProfileSlurNotification ({ author_name: authorName, title, title_link: titleLink, - text: profileData, + text: problemContent, mrkdwn_in: [ 'text', ], diff --git a/website/server/libs/user/index.js b/website/server/libs/user/index.js index 954d2b71ae..27b343d63e 100644 --- a/website/server/libs/user/index.js +++ b/website/server/libs/user/index.js @@ -113,8 +113,9 @@ async function checkNewInputForProfanity (user, res, newValue) { if (containsSlur) { user.flags.chatRevoked = true; await user.save(); - // return true; // this makes the function sad and claim it's not returning a value + return true; } + return false; } export async function update (req, res, { isV3 = false }) { @@ -133,48 +134,37 @@ export async function update (req, res, { isV3 = false }) { }); } + let slurWasUsed = false; + let problemContent = ''; + if (req.body['profile.name'] !== undefined) { const newName = req.body['profile.name']; if (newName === null) throw new BadRequest(res.t('invalidReqParams')); if (newName.length > 30) throw new BadRequest(res.t('displaynameIssueLength')); if (nameContainsNewline(newName)) throw new BadRequest(res.t('displaynameIssueNewline')); - if (req.body['profile.blurb'] !== undefined) { - const newBlurb = req.body['profile.blurb']; - await checkNewInputForProfanity(user, res, newName); - await checkNewInputForProfanity(user, res, newBlurb); - // slack info for flagged-posts - const authorEmail = getUserInfo(user, ['email']).email; - slack.sendProfileSlurNotification({ - authorEmail, - author: user.auth.local.username, - uuid: user.id, - language: user.preferences.language, - displayName: newName, - userBlurb: newBlurb, - // imageUrl: res.profile.imageUrl, - }); + if (checkNewInputForProfanity(user, res, newName)) { + slurWasUsed = true; + problemContent += `\n\nProfile Name: ${newName}\n\n` } - // hard stop error & message + } + + if (req.body['profile.blurb'] !== undefined) { + const newBlurb = req.body['profile.blurb']; + if (checkNewInputForProfanity(user, res, newBlurb)) { + slurWasUsed = true; + problemContent += `Profile Name: ${newBlurb}` + } + const authorEmail = getUserInfo(user, ['email']).email; + await slack.sendProfileSlurNotification({ + authorEmail, + author: user.auth.local.username, + uuid: user.id, + language: user.preferences.language, + problemContent, + }); throw new BadRequest(res.t('bannedSlurUsedInProfile')); } - // if (req.body['profile.blurb'] !== undefined) { - // const newBlurb = req.body['profile.blurb']; - // await checkNewInputForProfanity(user, res, newBlurb); - // // slack info for flagged-posts - // const authorEmail = getUserInfo(user, ['email']).email; - // slack.sendProfileSlurNotification({ - // authorEmail, - // author: user.auth.local.username, - // uuid: user.id, - // language: user.preferences.language, - // displayName: user.profile.name, - // userBlurb: newBlurb, - // // imageUrl: res.profile.imageUrl, - // }); - // // hard stop error & message - // throw new BadRequest(res.t('bannedSlurUsedInProfile')); - // } if (req.body['preferences.tasks.mirrorGroupTasks'] !== undefined) { const groupsToMirror = req.body['preferences.tasks.mirrorGroupTasks'];