From fb5b9b6d060925f363ded9418ba0aa82a79c473e Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Tue, 24 Oct 2017 11:47:41 -0400 Subject: [PATCH] FIX: don't offer the "Something Else" flag reason to TL0 users since they don't have permission to send private messages --- lib/guardian/post_guardian.rb | 5 +++-- spec/components/guardian_spec.rb | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/guardian/post_guardian.rb b/lib/guardian/post_guardian.rb index 83139fc8519..b5d4c43f671 100644 --- a/lib/guardian/post_guardian.rb +++ b/lib/guardian/post_guardian.rb @@ -35,8 +35,9 @@ module PostGuardian # don't like your own stuff not(action_key == :like && is_my_own?(post)) && - # new users can't notify_user because they are not allowed to send private messages - not(action_key == :notify_user && !@user.has_trust_level?(SiteSetting.min_trust_to_send_messages)) && + # new users can't notify_user or notify_moderators because they are not allowed to send private messages + not((action_key == :notify_user || action_key == :notify_moderators) && + !@user.has_trust_level?(SiteSetting.min_trust_to_send_messages)) && # no voting more than once on single vote topics not(action_key == :vote && opts[:voted_in_topic] && post.topic.has_meta_data_boolean?(:single_vote)) diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rb index d1374d38473..692fa1ad892 100644 --- a/spec/components/guardian_spec.rb +++ b/spec/components/guardian_spec.rb @@ -75,12 +75,12 @@ describe Guardian do expect(Guardian.new(user).post_can_act?(post, :notify_moderators)).to be_falsey end - it "returns false for notify_user if private messages are enabled but threshold not met" do + it "returns false for notify_user and notify_moderators if private messages are enabled but threshold not met" do SiteSetting.enable_private_messages = true SiteSetting.min_trust_to_send_messages = 2 user.trust_level = TrustLevel[1] expect(Guardian.new(user).post_can_act?(post, :notify_user)).to be_falsey - expect(Guardian.new(user).post_can_act?(post, :notify_moderators)).to be_truthy + expect(Guardian.new(user).post_can_act?(post, :notify_moderators)).to be_falsey end describe "trust levels" do