From ee8bbadfe8e4a3fcaf962b668ed2a7a7d195acfc Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Wed, 23 Apr 2014 17:00:22 -0400 Subject: [PATCH] Allow contact user to send private messages even if enable_private_messages is false --- lib/guardian.rb | 2 +- spec/components/guardian_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/guardian.rb b/lib/guardian.rb index 94456170791..8a04667df31 100644 --- a/lib/guardian.rb +++ b/lib/guardian.rb @@ -210,7 +210,7 @@ class Guardian # Have to be a basic level at least @user.has_trust_level?(:basic) && # PMs are enabled - SiteSetting.enable_private_messages + (SiteSetting.enable_private_messages || @user.username == SiteSetting.site_contact_username) end private diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rb index 50092b41976..5952bd75980 100644 --- a/spec/components/guardian_spec.rb +++ b/spec/components/guardian_spec.rb @@ -128,6 +128,19 @@ describe Guardian do it "returns true to another user" do Guardian.new(user).can_send_private_message?(another_user).should be_true end + + context "enable_private_messages is false" do + before { SiteSetting.stubs(:enable_private_messages).returns(false) } + + it "returns false if user is not the contact user" do + Guardian.new(user).can_send_private_message?(another_user).should be_false + end + + it "returns true for the contact user" do + SiteSetting.stubs(:site_contact_username).returns(user.username) + Guardian.new(user).can_send_private_message?(another_user).should be_true + end + end end describe 'can_reply_as_new_topic' do