diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 49372b3fa43..04e179adc11 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -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." diff --git a/lib/new_post_manager.rb b/lib/new_post_manager.rb index 39cf75cfaff..8eb03d32b6e 100644 --- a/lib/new_post_manager.rb +++ b/lib/new_post_manager.rb @@ -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 diff --git a/lib/validators/post_validator.rb b/lib/validators/post_validator.rb index 076dd2d086c..397a30b1761 100644 --- a/lib/validators/post_validator.rb +++ b/lib/validators/post_validator.rb @@ -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 diff --git a/spec/integration/watched_words_spec.rb b/spec/integration/watched_words_spec.rb index 03034e9b441..4aa7c267210 100644 --- a/spec/integration/watched_words_spec.rb +++ b/spec/integration/watched_words_spec.rb @@ -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