FIX: Do not send email when user of the post has been deleted. (#4228)

This commit is contained in:
Guo Xiang Tan 2016-05-17 23:42:15 +08:00 committed by Régis Hanol
parent e1061acd32
commit b68860ee28
3 changed files with 12 additions and 4 deletions

View File

@ -175,10 +175,11 @@ module Jobs
# If this email has a related post, don't send an email if it's been deleted or seen recently.
def skip_email_for_post(post, user)
if post
return I18n.t('email_log.topic_nil') if post.topic.blank?
return I18n.t('email_log.post_deleted') if post.user_deleted?
return I18n.t('email_log.user_suspended') if (user.suspended? && !post.user.try(:staff?))
return I18n.t('email_log.already_read') if PostTiming.where(topic_id: post.topic_id, post_number: post.post_number, user_id: user.id).present?
return I18n.t('email_log.topic_nil') if post.topic.blank?
return I18n.t('email_log.post_user_deleted') if post.user.blank?
return I18n.t('email_log.post_deleted') if post.user_deleted?
return I18n.t('email_log.user_suspended') if (user.suspended? && !post.user.try(:staff?))
return I18n.t('email_log.already_read') if PostTiming.where(topic_id: post.topic_id, post_number: post.post_number, user_id: user.id).present?
else
false
end

View File

@ -2413,6 +2413,7 @@ en:
spam_hosts: "This new user tried to create multiple posts with links to the same domain (%{domain}). See the <a href='/admin/site_settings/category/spam'>`newuser_spam_host_threshold`</a> site setting."
email_log:
post_user_deleted: "User of the post has been deleted."
no_user: "Can't find user with id %{user_id}"
anonymous_user: "User is anonymous"
suspended_not_pm: "User is suspended, not a message"

View File

@ -125,6 +125,12 @@ describe Jobs::UserEmail do
Jobs::UserEmail.new.execute(type: :private_message, user_id: user.id, post_id: post.id)
end
it "doesn't send the email if user of the post has been deleted" do
Email::Sender.any_instance.expects(:send).never
post.update_attributes!(user_id: nil)
Jobs::UserEmail.new.execute(type: :user_replied, user_id: user.id, post_id: post.id)
end
context 'user is suspended' do
it "doesn't send email for a pm from a regular user" do
Email::Sender.any_instance.expects(:send).never