FEATURE: Watched words improvements (#7899)

This commit contains 3 features:

- FEATURE: Allow downloading watched words
This introduces a button that allows admins to download watched words per action in a `.txt` file.

- FEATURE: Allow clearing watched words in bulk
This adds a "Clear All" button that clears all deleted words per action (e.g. block, flag etc.)

- FEATURE: List all blocked words contained in the post when it's blocked
When a post is rejected because it contains one or more blocked words, the error message now lists all the blocked words contained in the post.

-------

This also changes the format of the file for importing watched words from `.csv` to `.txt` so it becomes inconsistent with the extension of the file when watched words are exported.
This commit is contained in:
Osama Sayegh
2019-07-22 14:59:56 +03:00
committed by GitHub
parent 67650328b4
commit f14c6d81f4
17 changed files with 331 additions and 57 deletions

View File

@@ -13,6 +13,7 @@ describe WatchedWord do
let(:require_approval_word) { Fabricate(:watched_word, action: WatchedWord.actions[:require_approval]) }
let(:flag_word) { Fabricate(:watched_word, action: WatchedWord.actions[:flag]) }
let(:block_word) { Fabricate(:watched_word, action: WatchedWord.actions[:block]) }
let(:another_block_word) { Fabricate(:watched_word, action: WatchedWord.actions[:block]) }
before_all do
WordWatcher.clear_cache!
@@ -27,7 +28,7 @@ describe WatchedWord do
expect {
result = manager.perform
expect(result).to_not be_success
expect(result.errors[:base]&.first).to eq(I18n.t('contains_blocked_words', word: block_word.word))
expect(result.errors[:base]&.first).to eq(I18n.t('contains_blocked_word', word: block_word.word))
}.to_not change { Post.count }
end
@@ -51,6 +52,15 @@ describe WatchedWord do
should_block_post(manager)
end
it "should block the post if it contains multiple blocked words" do
manager = NewPostManager.new(moderator, raw: "Want some #{block_word.word} #{another_block_word.word} for cheap?", topic_id: topic.id)
expect {
result = manager.perform
expect(result).to_not be_success
expect(result.errors[:base]&.first).to eq(I18n.t('contains_blocked_words', words: [block_word.word, another_block_word.word].join(', ')))
}.to_not change { Post.count }
end
it "should block in a private message too" do
manager = NewPostManager.new(
tl2_user,