diff --git a/lib/guardian/post_guardian.rb b/lib/guardian/post_guardian.rb index 114bb1412..06ab6a4fc 100644 --- a/lib/guardian/post_guardian.rb +++ b/lib/guardian/post_guardian.rb @@ -9,6 +9,9 @@ module PostGuardian already_did_flagging = taken.any? && (taken & PostActionType.flag_types.values).any? if authenticated? && post + + return false if action_key == :notify_moderators && !SiteSetting.enable_private_messages + # we allow flagging for trust level 1 and higher (is_flag && @user.has_trust_level?(TrustLevel[1]) && not(already_did_flagging)) || @@ -27,6 +30,9 @@ module PostGuardian # new users can't notify_user because they are not allowed to send private messages not(action_key == :notify_user && !@user.has_trust_level?(TrustLevel[1])) && + # can't send private messages if they're disabled globally + not(action_key == :notify_user && !SiteSetting.enable_private_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)) end diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rb index d5ec6ccf4..cd0cc20aa 100644 --- a/spec/components/guardian_spec.rb +++ b/spec/components/guardian_spec.rb @@ -62,6 +62,13 @@ describe Guardian do Guardian.new(user).post_can_act?(post, :off_topic, taken_actions: {PostActionType.types[:spam] => 1}).should be_falsey end + it "returns false for notify_user if private messages are disabled" do + SiteSetting.stubs(:enable_private_messages).returns(false) + user.trust_level = TrustLevel[2] + Guardian.new(user).post_can_act?(post, :notify_user).should be_falsey + Guardian.new(user).post_can_act?(post, :notify_moderators).should be_falsey + end + describe "trust levels" do it "returns true for a new user liking something" do user.trust_level = TrustLevel[0]