Skip to content

A platform for community discussion. Free, open, simple.

FIX: Do not show recipient user in email participants list (#14642)

Martin Brennand3678f693014
diff --git a/app/mailers/group_smtp_mailer.rb b/app/mailers/group_smtp_mailer.rb
index cc9d17f8a93..ce12e4b0cc2 100644
--- a/app/mailers/group_smtp_mailer.rb
+++ b/app/mailers/group_smtp_mailer.rb
@@ -9,6 +9,7 @@ class GroupSmtpMailer < ActionMailer::Base
raise 'SMTP is disabled' if !SiteSetting.enable_smtp
op_incoming_email = post.topic.first_post.incoming_email
+ recipient_user = User.find_by_email(to_address, primary: true)
delivery_options = {
address: from_group.smtp_server,
@@ -39,7 +40,7 @@ class GroupSmtpMailer < ActionMailer::Base
only_reply_by_email: true,
use_from_address_for_reply_to: SiteSetting.enable_smtp && from_group.smtp_enabled?,
private_reply: post.topic.private_message?,
- participants: participants(post),
+ participants: participants(post, recipient_user),
include_respond_instructions: true,
template: 'user_notifications.user_posted_pm',
use_topic_title_subject: true,
@@ -72,7 +73,7 @@ class GroupSmtpMailer < ActionMailer::Base
)
end
- def participants(post)
+ def participants(post, recipient_user)
list = []
post.topic.allowed_groups.each do |g|
@@ -80,6 +81,8 @@ class GroupSmtpMailer < ActionMailer::Base
end
post.topic.allowed_users.each do |u|
+ next if u.id == recipient_user.id
+
if SiteSetting.prioritize_username_in_ux?
if u.staged?
list.push("#{u.email}")
diff --git a/app/mailers/user_notifications.rb b/app/mailers/user_notifications.rb
index 87703304dd3..5cca25310fd 100644
--- a/app/mailers/user_notifications.rb
+++ b/app/mailers/user_notifications.rb
@@ -560,6 +560,8 @@ class UserNotifications < ActionMailer::Base
end
post.topic.allowed_users.each do |u|
+ next if u.id == user.id
+
if SiteSetting.prioritize_username_in_ux?
participant_list.push "[#{u.username}](#{Discourse.base_url}/u/#{u.username_lower})"
else
diff --git a/spec/jobs/regular/group_smtp_email_spec.rb b/spec/jobs/regular/group_smtp_email_spec.rb
index 59fc8d06c8a..8923ab43818 100644
--- a/spec/jobs/regular/group_smtp_email_spec.rb
+++ b/spec/jobs/regular/group_smtp_email_spec.rb
@@ -30,6 +30,7 @@ RSpec.describe Jobs::GroupSmtpEmail do
SiteSetting.reply_by_email_address = "test+%{reply_key}@test.com"
SiteSetting.reply_by_email_enabled = true
TopicAllowedGroup.create(group: group, topic: topic)
+ TopicAllowedUser.create(user: recipient_user, topic: topic)
TopicAllowedUser.create(user: staged1, topic: topic)
TopicAllowedUser.create(user: staged2, topic: topic)
TopicAllowedUser.create(user: normaluser, topic: topic)
@@ -64,7 +65,7 @@ RSpec.describe Jobs::GroupSmtpEmail do
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
+ it "includes the participants in the correct format (but not the recipient user), 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
@@ -74,6 +75,7 @@ RSpec.describe Jobs::GroupSmtpEmail do
expect(email_text).to include("[email protected]")
expect(email_text).not_to include("[[email protected]]")
expect(email_text).to include("normaluser")
+ expect(email_text).not_to include(recipient_user.username)
end
it "creates an EmailLog record with the correct details" do
diff --git a/spec/mailers/user_notifications_spec.rb b/spec/mailers/user_notifications_spec.rb
index 3a1bc521a02..e186b8d6d23 100644
--- a/spec/mailers/user_notifications_spec.rb
+++ b/spec/mailers/user_notifications_spec.rb
@@ -591,14 +591,14 @@ describe UserNotifications do
expect(mail.subject).to include("[PM] ")
end
- it "includes a list of participants, groups first with member lists" do
+ it "includes a list of participants (except for the destination user), groups first with member lists" do
group1 = Fabricate(:group, name: "group1")
group2 = Fabricate(:group, name: "group2")
user1 = Fabricate(:user, username: "one", groups: [group1, group2])
user2 = Fabricate(:user, username: "two", groups: [group1])
- topic.allowed_users = [user1, user2]
+ topic.allowed_users = [user, user1, user2]
topic.allowed_groups = [group1, group2]
mail = UserNotifications.user_private_message(