mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
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:
@ -60,8 +60,15 @@ class Validators::PostValidator < ActiveModel::Validator
|
||||
end
|
||||
|
||||
def watched_words(post)
|
||||
if !post.acting_user&.staged && matches = WordWatcher.new(post.raw).should_block?
|
||||
post.errors.add(:base, I18n.t('contains_blocked_words', word: matches[0]))
|
||||
if !post.acting_user&.staged && matches = WordWatcher.new(post.raw).should_block?.presence
|
||||
if matches.size == 1
|
||||
key = 'contains_blocked_word'
|
||||
translation_args = { word: matches[0] }
|
||||
else
|
||||
key = 'contains_blocked_words'
|
||||
translation_args = { words: matches.join(', ') }
|
||||
end
|
||||
post.errors.add(:base, I18n.t(key, translation_args))
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user