diff --git a/lib/guardian.rb b/lib/guardian.rb index 48e0eda3983..abdd927dcfa 100644 --- a/lib/guardian.rb +++ b/lib/guardian.rb @@ -279,9 +279,7 @@ class Guardian # Have to be a basic level at least @user.has_trust_level?(SiteSetting.min_trust_to_send_messages) && # PMs are enabled - (SiteSetting.enable_private_messages || - @user.username == SiteSetting.site_contact_username || - @user == Discourse.system_user) && + (is_staff? || SiteSetting.enable_private_messages) && # Can't send PMs to suspended users (is_staff? || target.is_a?(Group) || !target.suspended?) && # Blocked users can only send PM to staff diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rb index dc4b640f7ad..370e61ce2bc 100644 --- a/spec/components/guardian_spec.rb +++ b/spec/components/guardian_spec.rb @@ -168,14 +168,13 @@ describe Guardian do context "enable_private_messages is false" do before { SiteSetting.enable_private_messages = false } - it "returns false if user is not the contact user" do - expect(Guardian.new(user).can_send_private_message?(another_user)).to be_falsey + it "returns false if user is not staff member" do + expect(Guardian.new(trust_level_4).can_send_private_message?(another_user)).to be_falsey end - it "returns true for the contact user and system user" do - SiteSetting.site_contact_username = user.username - expect(Guardian.new(user).can_send_private_message?(another_user)).to be_truthy - expect(Guardian.new(Discourse.system_user).can_send_private_message?(another_user)).to be_truthy + it "returns true for staff member" do + expect(Guardian.new(moderator).can_send_private_message?(another_user)).to be_truthy + expect(Guardian.new(admin).can_send_private_message?(another_user)).to be_truthy end end