Skip to content

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

Fix missing topic link when private email enabled (#39667)

Juan David Martínez Cubillos1979c9ee1218
diff --git a/app/mailers/user_notifications.rb b/app/mailers/user_notifications.rb
index 97b3e0bfed0..fd002cf48d1 100644
--- a/app/mailers/user_notifications.rb
+++ b/app/mailers/user_notifications.rb
@@ -750,9 +750,7 @@ class UserNotifications < ActionMailer::Base
end
first_footer_classes = "highlight"
- if (allow_reply_by_email && user.staged) || (user.suspended? || user.staged?)
- first_footer_classes = ""
- end
+ first_footer_classes = "" if user.suspended? || (user.staged? && !SiteSetting.private_email?)
unless translation_override_exists
html =
@@ -786,7 +784,7 @@ class UserNotifications < ActionMailer::Base
mailing_list_mode: user.user_option.mailing_list_mode,
unsubscribe_url: post.unsubscribe_url(user),
allow_reply_by_email: allow_reply_by_email,
- only_reply_by_email: allow_reply_by_email && user.staged,
+ only_reply_by_email: allow_reply_by_email && user.staged? && !SiteSetting.private_email?,
use_site_subject: use_site_subject,
add_re_to_subject: add_re_to_subject,
show_category_in_subject: show_category_in_subject,
@@ -794,7 +792,8 @@ class UserNotifications < ActionMailer::Base
private_reply: post.topic.private_message?,
subject_pm: subject_pm,
participants: participants,
- include_respond_instructions: !(user.suspended? || user.staged?),
+ include_respond_instructions:
+ !(user.suspended? || (user.staged? && !SiteSetting.private_email?)),
notification_type: notification_type,
template: template,
use_topic_title_subject: use_topic_title_subject,
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 7d6ca4724e1..5005b65198e 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -4821,6 +4821,8 @@ en:
%{message}
+ %{respond_instructions}
+
account_suspended:
title: "Account Suspended"
subject_template: "[%{email_prefix}] Your account has been suspended"
diff --git a/spec/mailers/user_notifications_spec.rb b/spec/mailers/user_notifications_spec.rb
index 8c186b43dd5..3069521f7d7 100644
--- a/spec/mailers/user_notifications_spec.rb
+++ b/spec/mailers/user_notifications_spec.rb
@@ -1158,7 +1158,7 @@ RSpec.describe UserNotifications do
shared_examples "respect for private_email" do
context "with private_email" do
- it "doesn't support reply by email" do
+ it "doesn't include topic title or slug for regular users" do
SiteSetting.private_email = true
mailer =
@@ -1177,6 +1177,35 @@ RSpec.describe UserNotifications do
expect(message.text_part.body.to_s).not_to include(topic.title)
expect(message.text_part.body.to_s).not_to include(topic.slug)
end
+
+ it "still links back to the topic for staged users" do
+ skip_types = %i[linked quoted mentioned group_mentioned]
+ if skip_types.include?(notification_type)
+ skip "Staged users don't receive #{notification_type} emails"
+ end
+
+ invite_types = %i[invited_to_private_message invited_to_topic watching_first_post]
+ if invite_types.include?(notification_type)
+ skip "Invite-type emails use a different template structure"
+ end
+
+ SiteSetting.private_email = true
+ user.update!(staged: true)
+
+ mailer =
+ UserNotifications.public_send(
+ mail_type,
+ user,
+ notification_type: Notification.types[notification.notification_type],
+ notification_data_hash: notification.data_hash,
+ post: notification.post,
+ )
+ message = mailer.message
+
+ slugless_path = notification.post.topic.slugless_url
+ expect(message.html_part.body.to_s).to include(slugless_path)
+ expect(message.text_part.body.to_s).to include(slugless_path)
+ end
end
end