mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 01:16:38 -06:00
UX: when a post is blocked due to a watched word, message includes the word being blocked
This commit is contained in:
parent
e7a7356986
commit
baf1c385eb
@ -221,7 +221,7 @@ en:
|
||||
too_many_links:
|
||||
one: "Sorry, new users can only put one link in a post."
|
||||
other: "Sorry, new users can only put %{count} links in a post."
|
||||
contains_blocked_words: "Your post contains words that aren't allowed."
|
||||
contains_blocked_words: "Your post contains a word that's not allowed: %{word}"
|
||||
|
||||
spamming_host: "Sorry you cannot post a link to that host."
|
||||
user_is_suspended: "Suspended users are not allowed to post."
|
||||
|
@ -133,9 +133,9 @@ class NewPostManager
|
||||
end
|
||||
|
||||
def perform
|
||||
if !self.class.exempt_user?(@user) && WordWatcher.new("#{@args[:title]} #{@args[:raw]}").should_block?
|
||||
if !self.class.exempt_user?(@user) && matches = WordWatcher.new("#{@args[:title]} #{@args[:raw]}").should_block?
|
||||
result = NewPostResult.new(:created_post, false)
|
||||
result.errors[:base] << I18n.t('contains_blocked_words')
|
||||
result.errors[:base] << I18n.t('contains_blocked_words', word: matches[0])
|
||||
return result
|
||||
end
|
||||
|
||||
|
@ -58,8 +58,8 @@ class Validators::PostValidator < ActiveModel::Validator
|
||||
end
|
||||
|
||||
def watched_words(post)
|
||||
if !post.acting_user&.staff? && !post.acting_user&.staged && WordWatcher.new(post.raw).should_block?
|
||||
post.errors[:base] << I18n.t('contains_blocked_words')
|
||||
if !post.acting_user&.staff? && !post.acting_user&.staged && matches = WordWatcher.new(post.raw).should_block?
|
||||
post.errors[:base] << I18n.t('contains_blocked_words', word: matches[0])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -21,7 +21,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'))
|
||||
expect(result.errors[:base]&.first).to eq(I18n.t('contains_blocked_words', word: block_word.word))
|
||||
}.to_not change { Post.count }
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user