From 4d0178deab8533e6ad25b94d8a61bbfe5bc8948b Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Mon, 28 Jun 2021 13:19:17 +1000 Subject: [PATCH] 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. --- app/mailers/group_smtp_mailer.rb | 6 +++--- spec/jobs/regular/group_smtp_email_spec.rb | 24 +++++++++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/app/mailers/group_smtp_mailer.rb b/app/mailers/group_smtp_mailer.rb index 045f669ec03..9107101792f 100644 --- a/app/mailers/group_smtp_mailer.rb +++ b/app/mailers/group_smtp_mailer.rb @@ -64,7 +64,7 @@ class GroupSmtpMailer < ActionMailer::Base context_posts: nil, reached_limit: nil, post: post, - in_reply_to_post: post.reply_to_post, + in_reply_to_post: nil, classes: Rtl.new(nil).css_class, first_footer_classes: '', reply_above_line: true @@ -82,13 +82,13 @@ class GroupSmtpMailer < ActionMailer::Base post.topic.allowed_users.each do |u| if SiteSetting.prioritize_username_in_ux? if u.staged? - list.push("[#{u.email}](#{Discourse.base_url}/u/#{u.username_lower})") + list.push("#{u.email}") else list.push("[#{u.username}](#{Discourse.base_url}/u/#{u.username_lower})") end else if u.staged? - list.push("[#{u.email}](#{Discourse.base_url}/u/#{u.username_lower})") + list.push("#{u.email}") else list.push("[#{u.name.blank? ? u.username : u.name}](#{Discourse.base_url}/u/#{u.username_lower})") end diff --git a/spec/jobs/regular/group_smtp_email_spec.rb b/spec/jobs/regular/group_smtp_email_spec.rb index 1bcae95af06..8e24ac7eeff 100644 --- a/spec/jobs/regular/group_smtp_email_spec.rb +++ b/spec/jobs/regular/group_smtp_email_spec.rb @@ -6,6 +6,7 @@ RSpec.describe Jobs::GroupSmtpEmail do fab!(:topic) { Fabricate(:private_message_topic, title: "Help I need support") } fab!(:post) do 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") end 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") 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) 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.as_mail_message.text_part.to_s).to include("otherguy@test.com") - expect(email_log.as_mail_message.text_part.to_s).to include("cormac@lit.com") - expect(email_log.as_mail_message.text_part.to_s).to include("normaluser") + expect(email_log.raw_headers).to include("In-Reply-To: ") + expect(email_log.as_mail_message.html_part.to_s).not_to include(I18n.t("user_notifications.in_reply_to")) + end + + 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 it "creates an EmailLog record with the correct details" do