FIX: Do not show In Reply To for group SMTP emails (#13541)

We do not want to show the In Reply To section of the
group SMTP email template, it is similar to Context Posts
which we removed and is unnecessary.

This PR also removes the link to staged user profiles in
the email; their email addresses will just be converted
to regular mailto: links.
This commit is contained in:
Martin Brennan
2021-06-28 13:19:17 +10:00
committed by GitHub
parent fd8016d678
commit 4d0178deab
2 changed files with 22 additions and 8 deletions

View File

@ -64,7 +64,7 @@ class GroupSmtpMailer < ActionMailer::Base
context_posts: nil, context_posts: nil,
reached_limit: nil, reached_limit: nil,
post: post, post: post,
in_reply_to_post: post.reply_to_post, in_reply_to_post: nil,
classes: Rtl.new(nil).css_class, classes: Rtl.new(nil).css_class,
first_footer_classes: '', first_footer_classes: '',
reply_above_line: true reply_above_line: true
@ -82,13 +82,13 @@ class GroupSmtpMailer < ActionMailer::Base
post.topic.allowed_users.each do |u| post.topic.allowed_users.each do |u|
if SiteSetting.prioritize_username_in_ux? if SiteSetting.prioritize_username_in_ux?
if u.staged? if u.staged?
list.push("[#{u.email}](#{Discourse.base_url}/u/#{u.username_lower})") list.push("#{u.email}")
else else
list.push("[#{u.username}](#{Discourse.base_url}/u/#{u.username_lower})") list.push("[#{u.username}](#{Discourse.base_url}/u/#{u.username_lower})")
end end
else else
if u.staged? if u.staged?
list.push("[#{u.email}](#{Discourse.base_url}/u/#{u.username_lower})") list.push("#{u.email}")
else else
list.push("[#{u.name.blank? ? u.username : u.name}](#{Discourse.base_url}/u/#{u.username_lower})") list.push("[#{u.name.blank? ? u.username : u.name}](#{Discourse.base_url}/u/#{u.username_lower})")
end end

View File

@ -6,6 +6,7 @@ RSpec.describe Jobs::GroupSmtpEmail do
fab!(:topic) { Fabricate(:private_message_topic, title: "Help I need support") } fab!(:topic) { Fabricate(:private_message_topic, title: "Help I need support") }
fab!(:post) do fab!(:post) do
Fabricate(:post, topic: topic, raw: "some first post content") Fabricate(:post, topic: topic, raw: "some first post content")
Fabricate(:post, topic: topic, raw: "some intermediate content")
Fabricate(:post, topic: topic, raw: "this is the second post reply") Fabricate(:post, topic: topic, raw: "this is the second post reply")
end end
fab!(:group) { Fabricate(:smtp_group, name: "support-group", full_name: "Support Group") } fab!(:group) { Fabricate(:smtp_group, name: "support-group", full_name: "Support Group") }
@ -53,13 +54,26 @@ RSpec.describe Jobs::GroupSmtpEmail do
expect(email_log.as_mail_message.text_part.to_s).not_to include("some first post content") expect(email_log.as_mail_message.text_part.to_s).not_to include("some first post content")
end end
it "includes the participants in the correct format" do it "does not include in reply to post in email but still has the header" do
second_post = topic.posts.find_by(post_number: 2)
post.update!(reply_to_post_number: 1, reply_to_user: second_post.user)
PostReply.create(post: second_post, reply: post)
subject.execute(args) subject.execute(args)
email_log = EmailLog.find_by(post_id: post.id, topic_id: post.topic_id, user_id: recipient_user.id) email_log = EmailLog.find_by(post_id: post.id, topic_id: post.topic_id, user_id: recipient_user.id)
expect(email_log.as_mail_message.text_part.to_s).to include("Support Group") expect(email_log.raw_headers).to include("In-Reply-To: <topic/#{post.topic_id}/#{second_post.id}@#{Email::Sender.host_for(Discourse.base_url)}>")
expect(email_log.as_mail_message.text_part.to_s).to include("otherguy@test.com") expect(email_log.as_mail_message.html_part.to_s).not_to include(I18n.t("user_notifications.in_reply_to"))
expect(email_log.as_mail_message.text_part.to_s).to include("cormac@lit.com") end
expect(email_log.as_mail_message.text_part.to_s).to include("normaluser")
it "includes the participants in the correct format, and does not have links for the staged users" do
subject.execute(args)
email_log = EmailLog.find_by(post_id: post.id, topic_id: post.topic_id, user_id: recipient_user.id)
email_text = email_log.as_mail_message.text_part.to_s
expect(email_text).to include("Support Group")
expect(email_text).to include("otherguy@test.com")
expect(email_text).not_to include("[otherguy@test.com]")
expect(email_text).to include("cormac@lit.com")
expect(email_text).not_to include("[cormac@lit.com]")
expect(email_text).to include("normaluser")
end end
it "creates an EmailLog record with the correct details" do it "creates an EmailLog record with the correct details" do