mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Frontend support and adjustments of current banned words blocking code to support new implementation (Fixes #12405) (#12496)
* Added the "Allow banned words" checkbox to create/update guild forms Added the "Allow banned words" checkbox to guild create/update forms which are only visible to Admins * Updated create/update group API to include bannedWordsAllowed property Added logic to set bannedWordsAllowed depending on conditions * Updated word banning logic to use bannedWordsAllowed guild value instead Updated word banning logic to use bannedWordsAllowed guild value and deleted hardcoded guild file & import * Updated banned words test * Pull Request amends Removed the setting of bannedWordsAllowed during group creation Added v-once to elements Updated existing test and added tests related to bannedWordsAllowed functionality * Small amend * Small amend Removed leftover code that was left during testing
This commit is contained in:
@@ -18,7 +18,6 @@ import * as slack from '../../libs/slack';
|
||||
import { chatReporterFactory } from '../../libs/chatReporting/chatReporterFactory';
|
||||
import { getAuthorEmailFromMessage } from '../../libs/chat';
|
||||
import bannedWords from '../../libs/bannedWords';
|
||||
import guildsAllowingBannedWords from '../../libs/guildsAllowingBannedWords';
|
||||
import { getMatchesByWordArray } from '../../libs/stringUtils';
|
||||
import bannedSlurs from '../../libs/bannedSlurs';
|
||||
import apiError from '../../libs/apiError';
|
||||
@@ -172,7 +171,7 @@ api.postChat = {
|
||||
|
||||
// prevent banned words being posted, except in private guilds/parties
|
||||
// and in certain public guilds with specific topics
|
||||
if (group.privacy === 'public' && !guildsAllowingBannedWords[group._id]) {
|
||||
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(', ') }));
|
||||
|
||||
@@ -471,6 +471,14 @@ api.updateGroup = {
|
||||
|
||||
if (!group) throw new NotFound(res.t('groupNotFound'));
|
||||
|
||||
if (user.contributor.admin) {
|
||||
if (req.body.bannedWordsAllowed === true) {
|
||||
group.bannedWordsAllowed = true;
|
||||
} else {
|
||||
group.bannedWordsAllowed = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (group.leader !== user._id && group.type === 'party') throw new NotAuthorized(res.t('messageGroupOnlyLeaderCanUpdate'));
|
||||
else if (group.leader !== user._id && !user.contributor.admin) throw new NotAuthorized(res.t('messageGroupOnlyLeaderCanUpdate'));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user