mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: email customizations now apply to both html and text parts
This commit is contained in:
parent
15adbdcdd5
commit
402ddb810c
@ -357,6 +357,12 @@ class UserNotifications < ActionMailer::Base
|
|||||||
user = opts[:user]
|
user = opts[:user]
|
||||||
locale = user_locale(user)
|
locale = user_locale(user)
|
||||||
|
|
||||||
|
template = "user_notifications.user_#{notification_type}"
|
||||||
|
if post.topic.private_message?
|
||||||
|
template << "_pm"
|
||||||
|
template << "_staged" if user.staged?
|
||||||
|
end
|
||||||
|
|
||||||
# category name
|
# category name
|
||||||
category = Topic.find_by(id: post.topic_id).category
|
category = Topic.find_by(id: post.topic_id).category
|
||||||
if opts[:show_category_in_subject] && post.topic_id && category && !category.uncategorized?
|
if opts[:show_category_in_subject] && post.topic_id && category && !category.uncategorized?
|
||||||
@ -384,10 +390,7 @@ class UserNotifications < ActionMailer::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
reached_limit = SiteSetting.max_emails_per_day_per_user > 0
|
translation_override_exists = TranslationOverride.where(locale: SiteSetting.default_locale, translation_key: "#{template}.text_body_template").exists?
|
||||||
reached_limit &&= (EmailLog.where(user_id: user.id, skipped: false)
|
|
||||||
.where('created_at > ?', 1.day.ago)
|
|
||||||
.count) >= (SiteSetting.max_emails_per_day_per_user-1)
|
|
||||||
|
|
||||||
if opts[:use_invite_template]
|
if opts[:use_invite_template]
|
||||||
if post.topic.private_message?
|
if post.topic.private_message?
|
||||||
@ -397,6 +400,8 @@ class UserNotifications < ActionMailer::Base
|
|||||||
end
|
end
|
||||||
topic_excerpt = post.excerpt.tr("\n", " ") if post.is_first_post? && post.excerpt
|
topic_excerpt = post.excerpt.tr("\n", " ") if post.is_first_post? && post.excerpt
|
||||||
message = I18n.t(invite_template, username: username, topic_title: title, topic_excerpt: topic_excerpt, site_title: SiteSetting.title, site_description: SiteSetting.site_description)
|
message = I18n.t(invite_template, username: username, topic_title: title, topic_excerpt: topic_excerpt, site_title: SiteSetting.title, site_description: SiteSetting.site_description)
|
||||||
|
|
||||||
|
unless translation_override_exists
|
||||||
html = UserNotificationRenderer.new(Rails.configuration.paths["app/views"]).render(
|
html = UserNotificationRenderer.new(Rails.configuration.paths["app/views"]).render(
|
||||||
template: 'email/invite',
|
template: 'email/invite',
|
||||||
format: :html,
|
format: :html,
|
||||||
@ -404,8 +409,17 @@ class UserNotifications < ActionMailer::Base
|
|||||||
classes: RTL.new(user).css_class
|
classes: RTL.new(user).css_class
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
|
reached_limit = SiteSetting.max_emails_per_day_per_user > 0
|
||||||
|
reached_limit &&= (EmailLog.where(user_id: user.id, skipped: false)
|
||||||
|
.where('created_at > ?', 1.day.ago)
|
||||||
|
.count) >= (SiteSetting.max_emails_per_day_per_user-1)
|
||||||
|
|
||||||
in_reply_to_post = post.reply_to_post if user.user_option.email_in_reply_to
|
in_reply_to_post = post.reply_to_post if user.user_option.email_in_reply_to
|
||||||
|
message = email_post_markdown(post) + (reached_limit ? "\n\n#{I18n.t "user_notifications.reached_limit", count: SiteSetting.max_emails_per_day_per_user}" : "");
|
||||||
|
|
||||||
|
unless translation_override_exists
|
||||||
html = UserNotificationRenderer.new(Rails.configuration.paths["app/views"]).render(
|
html = UserNotificationRenderer.new(Rails.configuration.paths["app/views"]).render(
|
||||||
template: 'email/notification',
|
template: 'email/notification',
|
||||||
format: :html,
|
format: :html,
|
||||||
@ -416,18 +430,12 @@ class UserNotifications < ActionMailer::Base
|
|||||||
classes: RTL.new(user).css_class
|
classes: RTL.new(user).css_class
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
message = email_post_markdown(post) + (reached_limit ? "\n\n#{I18n.t "user_notifications.reached_limit", count: SiteSetting.max_emails_per_day_per_user}" : "");
|
|
||||||
end
|
end
|
||||||
|
|
||||||
template = "user_notifications.user_#{notification_type}"
|
|
||||||
if post.topic.private_message?
|
|
||||||
template << "_pm"
|
|
||||||
template << "_staged" if user.staged?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
email_opts = {
|
email_opts = {
|
||||||
topic_title: title,
|
topic_title: title,
|
||||||
topic_title_url_encoded: URI.encode(title),
|
topic_title_url_encoded: title ? URI.encode(title) : title,
|
||||||
message: message,
|
message: message,
|
||||||
url: post.url,
|
url: post.url,
|
||||||
post_id: post.id,
|
post_id: post.id,
|
||||||
@ -445,7 +453,6 @@ class UserNotifications < ActionMailer::Base
|
|||||||
private_reply: post.topic.private_message?,
|
private_reply: post.topic.private_message?,
|
||||||
include_respond_instructions: !(user.suspended? || user.staged?),
|
include_respond_instructions: !(user.suspended? || user.staged?),
|
||||||
template: template,
|
template: template,
|
||||||
html_override: html,
|
|
||||||
site_description: SiteSetting.site_description,
|
site_description: SiteSetting.site_description,
|
||||||
site_title: SiteSetting.title,
|
site_title: SiteSetting.title,
|
||||||
site_title_url_encoded: URI.encode(SiteSetting.title),
|
site_title_url_encoded: URI.encode(SiteSetting.title),
|
||||||
@ -453,6 +460,10 @@ class UserNotifications < ActionMailer::Base
|
|||||||
locale: locale
|
locale: locale
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unless translation_override_exists
|
||||||
|
email_opts[:html_override] = html
|
||||||
|
end
|
||||||
|
|
||||||
# If we have a display name, change the from address
|
# If we have a display name, change the from address
|
||||||
email_opts[:from_alias] = from_alias if from_alias.present?
|
email_opts[:from_alias] = from_alias if from_alias.present?
|
||||||
|
|
||||||
|
@ -471,7 +471,7 @@ describe UserNotifications do
|
|||||||
data: {original_username: username}.to_json )
|
data: {original_username: username}.to_json )
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.user_mentioned' do
|
describe 'email building' do
|
||||||
it "has a username" do
|
it "has a username" do
|
||||||
expects_build_with(has_entry(:username, username))
|
expects_build_with(has_entry(:username, username))
|
||||||
end
|
end
|
||||||
@ -484,6 +484,10 @@ describe UserNotifications do
|
|||||||
expects_build_with(has_entry(:template, "user_notifications.#{mail_type}"))
|
expects_build_with(has_entry(:template, "user_notifications.#{mail_type}"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "overrides the html part" do
|
||||||
|
expects_build_with(has_key(:html_override))
|
||||||
|
end
|
||||||
|
|
||||||
it "has a message" do
|
it "has a message" do
|
||||||
expects_build_with(has_key(:message))
|
expects_build_with(has_key(:message))
|
||||||
end
|
end
|
||||||
@ -524,6 +528,18 @@ describe UserNotifications do
|
|||||||
User.any_instance.stubs(:suspended?).returns(true)
|
User.any_instance.stubs(:suspended?).returns(true)
|
||||||
expects_build_with(has_entry(:include_respond_instructions, false))
|
expects_build_with(has_entry(:include_respond_instructions, false))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when customized" do
|
||||||
|
let(:custom_body) { "You are now officially notified." }
|
||||||
|
|
||||||
|
before do
|
||||||
|
TranslationOverride.upsert!("en", "user_notifications.user_#{notification_type}.text_body_template", custom_body)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "shouldn't use the default html_override" do
|
||||||
|
expects_build_with(Not(has_key(:html_override)))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user