Skip to content

Commit

Permalink
feat(condo): DOMA-7635 updated bad words exclusions (#4453)
Browse files Browse the repository at this point in the history
* feat(condo): DOMA-7635 updated exclusions filter to check for bad words - added support masks. Added new words to exclusion list

* refactor(condo): DOMA-7635 reused bad-words-next for bad words exclusions

* chore(condo): DOMA-7635 removed comments

* fix(condo): DOMA-7635 fixed import
  • Loading branch information
Alllex202 authored Mar 7, 2024
1 parent 4530ebb commit 4d21924
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 65 deletions.
17 changes: 17 additions & 0 deletions apps/condo/domains/news/constants/badWordsExclusions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const BAD_WORDS_EXCLUSIONS = [
'дебиторск*',
'ипу',
'*канал*',
'муниципал*',
'потребител*',
]

const BAD_WORDS_EXCLUSIONS_CONFIG = {
id: 'exclusions',
words: BAD_WORDS_EXCLUSIONS,
lookalike: {},
}

module.exports = {
BAD_WORDS_EXCLUSIONS_CONFIG,
}
11 changes: 7 additions & 4 deletions apps/condo/domains/news/schema/NewsItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const { itemsQuery } = require('@open-condo/keystone/schema')
const { GQLListSchema } = require('@open-condo/keystone/schema')

const access = require('@condo/domains/news/access/NewsItem')
const { BAD_WORDS_EXCLUSIONS_CONFIG } = require('@condo/domains/news/constants/badWordsExclusions')
const {
EMPTY_VALID_BEFORE_DATE,
VALIDITY_DATE_LESS_THAN_SEND_DATE,
Expand All @@ -26,14 +27,16 @@ const {
NO_NEWS_ITEM_SCOPES,
} = require('@condo/domains/news/constants/errors')
const { NEWS_TYPES, NEWS_TYPE_EMERGENCY, NEWS_TYPE_COMMON } = require('@condo/domains/news/constants/newsTypes')
const { notifyResidentsAboutNewsItem, publishSharedNewsItemsByNewsItem } = require('@condo/domains/news/tasks')
const { notifyResidentsAboutNewsItem } = require('@condo/domains/news/tasks')
const { NewsItemScope } = require('@condo/domains/news/utils/serverSchema')
const { checkBadWordsExclusions } = require('@condo/domains/news/utils/serverSchema/badWords')
const { ORGANIZATION_OWNED_FIELD } = require('@condo/domains/organization/schema/fields')


const badWords = new BadWordsNext()
badWords.add(badWordsRu)
badWords.add(badWordsRuLat)
const badWordsExclusions = new BadWordsNext()
badWordsExclusions.add(BAD_WORDS_EXCLUSIONS_CONFIG)

const ERRORS = {
EMPTY_VALID_BEFORE_DATE: {
Expand Down Expand Up @@ -268,7 +271,7 @@ const NewsItem = new GQLListSchema('NewsItem', {
const nextTitle = get(resolvedData, 'title')
if (nextTitle) {
badWords.filter(nextTitle, (badWord) => {
if (checkBadWordsExclusions(badWord)) return
if (badWordsExclusions.check(badWord)) return
titleBadWords.push(badWord)
})
}
Expand All @@ -277,7 +280,7 @@ const NewsItem = new GQLListSchema('NewsItem', {
const nextBody = get(resolvedData, 'body')
if (nextBody) {
badWords.filter(nextBody, (badWord) => {
if (checkBadWordsExclusions(badWord)) return
if (badWordsExclusions.check(badWord)) return
bodyBadWords.push(badWord)
})
}
Expand Down
14 changes: 14 additions & 0 deletions apps/condo/domains/news/schema/NewsItem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,13 @@ describe('NewsItems', () => {
)
})

test('must create news item if profanity exclusion detected within title', async () => {
const [newsItem, attrs] = await createTestNewsItem(adminClient, dummyO10n, {
title: 'ИПУ муниципальная потребители',
})
expect(newsItem).toHaveProperty('title', attrs.title)
})

test('must throw an error if profanity detected within body', async () => {
await expectToThrowGQLError(
async () => await createTestNewsItem(adminClient, dummyO10n, {
Expand All @@ -888,6 +895,13 @@ describe('NewsItems', () => {
)
})

test('must create news item if profanity exclusion detected within body', async () => {
const [newsItem, attrs] = await createTestNewsItem(adminClient, dummyO10n, {
body: 'ИПУ муниципальная потребители',
})
expect(newsItem).toHaveProperty('body', attrs.body)
})

test('should create news if exceptions of profanity are detected within title or body (case insensitive)', async () => {
const [newsItem, attrs] = await createTestNewsItem(adminClient, dummyO10n, {
title: 'Сдача ИПУ!',
Expand Down
36 changes: 0 additions & 36 deletions apps/condo/domains/news/utils/serverSchema/badWords.js

This file was deleted.

25 changes: 0 additions & 25 deletions apps/condo/domains/news/utils/serverSchema/badWords.spec.js

This file was deleted.

0 comments on commit 4d21924

Please sign in to comment.