diff --git a/website/common/locales/en/groups.json b/website/common/locales/en/groups.json index 89f3f443da..d12ec31ebe 100644 --- a/website/common/locales/en/groups.json +++ b/website/common/locales/en/groups.json @@ -18,6 +18,7 @@ "communityGuidelines": "Community Guidelines", "bannedWordUsed": "Oops! Looks like this post contains a swearword or reference to an addictive substance or adult topic (<%= swearWordsUsed %>). Habitica keeps our chat very clean. Feel free to edit your message so you can post it! You must remove the word, not just censor it.", "bannedSlurUsed": "Your post contained inappropriate language, and your chat privileges have been revoked.", + "challengeBannedWordsAndSlurs": "Your challenge contains either a swear word or other inappropriate language. Please remove in order to continue with your challenge creation.", "party": "Party", "usernameCopied": "Username copied to clipboard.", "create": "Create", diff --git a/website/server/controllers/api-v3/challenges.js b/website/server/controllers/api-v3/challenges.js index ff22bd4b24..3503545c97 100644 --- a/website/server/controllers/api-v3/challenges.js +++ b/website/server/controllers/api-v3/challenges.js @@ -225,7 +225,18 @@ api.createChallenge = { const validationErrors = req.validationErrors(); if (validationErrors) throw validationErrors; - const { savedChal, group } = await createChallenge(user, req, res); + const { group } = (user, req, req); + + // checks challenge for slurs and banned words + if (group.privacy === 'public' + && ((textContainsBannedSlur(req.body.name)) + || (textContainsBannedSlur(req.body.shortName)) + || (textContainsBannedSlur(req.body.summary)) + || (textContainsBannedSlur(req.body.description)))) { + throw new BadRequest(res.t('challengeBannedWordsAndSlurs')); + } + + const { savedChal } = await createChallenge(user, req, res); const response = savedChal.toJSON(); response.leader = { // the leader is the authenticated user @@ -246,55 +257,6 @@ api.createChallenge = { headers: req.headers, }); - // check challenge for slurs - if (group.privacy === 'public' - && ((textContainsBannedSlur(req.body.name)) - || (textContainsBannedSlur(req.body.shortName)) - || (textContainsBannedSlur(req.body.summary)) - || (textContainsBannedSlur(req.body.description)))) { - const { message } = req.body.name - && req.body.shortName - && req.body.summary - && req.body.description; - user.flags.chatRevoked = true; - await user.save(); - // note to Natalie: - // does this need to shadow-mute the user? And what about hiding the challenge - // until the language can be corrected? - - // email mods - const authorEmail = getUserInfo(user, ['email']).email; - - // send Slack message - slack.sendSlurNotification({ - authorEmail, - author: user, - group, - message, - }); - - throw new BadRequest(res.t('bannedSlurUsed')); - } - - // prevent banned words being posted, except in private challenges - if (group.privacy === 'public' && textContainsBannedWord(req.body.name)) { - const { message } = req.body; - await user.save(); - - // email mods - const authorEmail = getUserInfo(user, ['email']).email; - - // send Slack message - slack.sendSlurNotification({ - authorEmail, - author: user, - group, - message, - }); - - throw new BadRequest(res.t('bannedWordUsed')); - } - res.respond(201, response); }, };