mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
Don't allow sending private messages to suspended users. Emails to suspended users should tell them how to respond, since they can't.
This commit is contained in:
parent
ba68470d5a
commit
f44bd4ec28
5 changed files with 37 additions and 9 deletions
|
@ -157,7 +157,7 @@ class UserNotifications < ActionMailer::Base
|
|||
["replied", "mentioned", "quoted", "posted"].include?(notification_type)
|
||||
|
||||
title = @notification.data_hash[:topic_title]
|
||||
allow_reply_by_email = opts[:allow_reply_by_email]
|
||||
allow_reply_by_email = opts[:allow_reply_by_email] unless user.suspended?
|
||||
|
||||
send_notification_email(
|
||||
title: title,
|
||||
|
@ -213,6 +213,7 @@ class UserNotifications < ActionMailer::Base
|
|||
username: from_alias,
|
||||
add_unsubscribe_link: true,
|
||||
allow_reply_by_email: allow_reply_by_email,
|
||||
include_respond_instructions: !user.suspended?,
|
||||
template: template,
|
||||
html_override: html,
|
||||
style: :notification
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Builds a Mail::Mesage we can use for sending. Optionally supports using a template
|
||||
# Builds a Mail::Message we can use for sending. Optionally supports using a template
|
||||
# for the body and subject
|
||||
module Email
|
||||
|
||||
|
@ -26,6 +26,9 @@ module Email
|
|||
user_preferences_url: "#{Discourse.base_url}/my/preferences" }.merge!(@opts)
|
||||
|
||||
if @template_args[:url].present?
|
||||
if @opts[:include_respond_instructions] == false
|
||||
@template_args[:respond_instructions] = ''
|
||||
else
|
||||
@template_args[:respond_instructions] =
|
||||
if allow_reply_by_email?
|
||||
I18n.t('user_notifications.reply_by_email', @template_args)
|
||||
|
@ -34,6 +37,7 @@ module Email
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def subject
|
||||
subject = @opts[:subject]
|
||||
|
|
|
@ -215,7 +215,9 @@ class Guardian
|
|||
# PMs are enabled
|
||||
(SiteSetting.enable_private_messages ||
|
||||
@user.username == SiteSetting.site_contact_username ||
|
||||
@user == Discourse.system_user)
|
||||
@user == Discourse.system_user) &&
|
||||
# Can't send PMs to suspended users
|
||||
(is_staff? || target.is_a?(Group) || !target.suspended?)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -107,6 +107,7 @@ describe Guardian do
|
|||
describe 'can_send_private_message' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:another_user) { Fabricate(:user) }
|
||||
let(:suspended_user) { Fabricate(:user, suspended_till: 1.week.from_now, suspended_at: 1.day.ago) }
|
||||
|
||||
it "returns false when the user is nil" do
|
||||
Guardian.new(nil).can_send_private_message?(user).should be_false
|
||||
|
@ -142,6 +143,17 @@ describe Guardian do
|
|||
Guardian.new(Discourse.system_user).can_send_private_message?(another_user).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "target user is suspended" do
|
||||
it "returns true for staff" do
|
||||
Guardian.new(admin).can_send_private_message?(suspended_user).should be_true
|
||||
Guardian.new(moderator).can_send_private_message?(suspended_user).should be_true
|
||||
end
|
||||
|
||||
it "returns false for regular users" do
|
||||
Guardian.new(user).can_send_private_message?(suspended_user).should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'can_reply_as_new_topic' do
|
||||
|
|
|
@ -176,6 +176,15 @@ describe UserNotifications do
|
|||
it "has a from alias" do
|
||||
expects_build_with(has_entry(:from_alias, "#{username}"))
|
||||
end
|
||||
|
||||
it "should explain how to respond" do
|
||||
expects_build_with(Not(has_entry(:include_respond_instructions, false)))
|
||||
end
|
||||
|
||||
it "should not explain how to respond if the user is suspended" do
|
||||
User.any_instance.stubs(:suspended?).returns(true)
|
||||
expects_build_with(has_entry(:include_respond_instructions, false))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue