FIX: allow staff members to send PMs when enable_private_messages is disabled

This commit is contained in:
Arpit Jalan 2017-02-22 11:32:09 +05:30
parent c191e2e84c
commit b32f33b3f0
2 changed files with 6 additions and 9 deletions

View File

@ -279,9 +279,7 @@ class Guardian
# Have to be a basic level at least # Have to be a basic level at least
@user.has_trust_level?(SiteSetting.min_trust_to_send_messages) && @user.has_trust_level?(SiteSetting.min_trust_to_send_messages) &&
# PMs are enabled # PMs are enabled
(SiteSetting.enable_private_messages || (is_staff? || SiteSetting.enable_private_messages) &&
@user.username == SiteSetting.site_contact_username ||
@user == Discourse.system_user) &&
# Can't send PMs to suspended users # Can't send PMs to suspended users
(is_staff? || target.is_a?(Group) || !target.suspended?) && (is_staff? || target.is_a?(Group) || !target.suspended?) &&
# Blocked users can only send PM to staff # Blocked users can only send PM to staff

View File

@ -168,14 +168,13 @@ describe Guardian do
context "enable_private_messages is false" do context "enable_private_messages is false" do
before { SiteSetting.enable_private_messages = false } before { SiteSetting.enable_private_messages = false }
it "returns false if user is not the contact user" do it "returns false if user is not staff member" do
expect(Guardian.new(user).can_send_private_message?(another_user)).to be_falsey expect(Guardian.new(trust_level_4).can_send_private_message?(another_user)).to be_falsey
end end
it "returns true for the contact user and system user" do it "returns true for staff member" do
SiteSetting.site_contact_username = user.username expect(Guardian.new(moderator).can_send_private_message?(another_user)).to be_truthy
expect(Guardian.new(user).can_send_private_message?(another_user)).to be_truthy expect(Guardian.new(admin).can_send_private_message?(another_user)).to be_truthy
expect(Guardian.new(Discourse.system_user).can_send_private_message?(another_user)).to be_truthy
end end
end end