mirror of
https://github.com/discourse/discourse.git
synced 2025-09-07 12:02:53 +08:00
FIX: don't send email when the post was deleted
This commit is contained in:
parent
774e6bc795
commit
f01169d6ff
3 changed files with 28 additions and 5 deletions
|
@ -31,7 +31,8 @@ class SkippedEmailLog < ActiveRecord::Base
|
||||||
sender_message_blank: 16,
|
sender_message_blank: 16,
|
||||||
sender_message_to_blank: 17,
|
sender_message_to_blank: 17,
|
||||||
sender_text_part_body_blank: 18,
|
sender_text_part_body_blank: 18,
|
||||||
sender_body_blank: 19
|
sender_body_blank: 19,
|
||||||
|
sender_post_deleted: 20
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -87,6 +87,10 @@ module Email
|
||||||
|
|
||||||
if topic_id.present? && post_id.present?
|
if topic_id.present? && post_id.present?
|
||||||
post = Post.find_by(id: post_id, topic_id: topic_id)
|
post = Post.find_by(id: post_id, topic_id: topic_id)
|
||||||
|
|
||||||
|
# guards against deleted posts
|
||||||
|
return skip(SkippedEmailLog.reason_types[:sender_post_deleted]) unless post
|
||||||
|
|
||||||
topic = post.topic
|
topic = post.topic
|
||||||
first_post = topic.ordered_posts.first
|
first_post = topic.ordered_posts.first
|
||||||
|
|
||||||
|
@ -124,7 +128,7 @@ module Email
|
||||||
end
|
end
|
||||||
|
|
||||||
# https://www.ietf.org/rfc/rfc2919.txt
|
# https://www.ietf.org/rfc/rfc2919.txt
|
||||||
if topic && topic.category && !topic.category.uncategorized?
|
if topic&.category && !topic.category.uncategorized?
|
||||||
list_id = "#{SiteSetting.title} | #{topic.category.name} <#{topic.category.name.downcase.tr(' ', '-')}.#{host}>"
|
list_id = "#{SiteSetting.title} | #{topic.category.name} <#{topic.category.name.downcase.tr(' ', '-')}.#{host}>"
|
||||||
|
|
||||||
# subcategory case
|
# subcategory case
|
||||||
|
@ -199,7 +203,6 @@ module Email
|
||||||
return skip(SkippedEmailLog.reason_types[:custom], custom_reason: e.message)
|
return skip(SkippedEmailLog.reason_types[:custom], custom_reason: e.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Save and return the email log
|
|
||||||
email_log.save!
|
email_log.save!
|
||||||
email_log
|
email_log
|
||||||
end
|
end
|
||||||
|
|
|
@ -333,6 +333,25 @@ describe Email::Sender do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with a deleted post' do
|
||||||
|
|
||||||
|
it 'should skip sending the email' do
|
||||||
|
post = Fabricate(:post, deleted_at: 1.day.ago)
|
||||||
|
|
||||||
|
message = Mail::Message.new to: 'disc@ourse.org', body: 'some content'
|
||||||
|
message.header['X-Discourse-Post-Id'] = post.id
|
||||||
|
message.header['X-Discourse-Topic-Id'] = post.topic_id
|
||||||
|
message.expects(:deliver_now).never
|
||||||
|
|
||||||
|
email_sender = Email::Sender.new(message, :valid_type)
|
||||||
|
expect { email_sender.send }.to change { SkippedEmailLog.count }
|
||||||
|
|
||||||
|
log = SkippedEmailLog.last
|
||||||
|
expect(log.reason_type).to eq(SkippedEmailLog.reason_types[:sender_post_deleted])
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
context 'with a user' do
|
context 'with a user' do
|
||||||
let(:message) do
|
let(:message) do
|
||||||
message = Mail::Message.new to: 'eviltrout@test.domain', body: 'test body'
|
message = Mail::Message.new to: 'eviltrout@test.domain', body: 'test body'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue