UX: when a post is blocked due to a watched word, message includes the word being blocked

This commit is contained in:
Neil Lalonde 2018-02-28 11:22:04 -05:00
parent e7a7356986
commit baf1c385eb
4 changed files with 6 additions and 6 deletions

View File

@ -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."

View File

@ -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

View File

@ -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

View File

@ -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