FIX: Notifications shouldn't use user locale unless allow_user_locale is enabled

This commit is contained in:
Gerhard Schlager 2018-09-05 11:44:26 +02:00
parent 72834f19ff
commit 2c5d9269a0
2 changed files with 21 additions and 23 deletions

View File

@ -20,10 +20,15 @@ class UserNotifications < ActionMailer::Base
end
def signup_after_approval(user, opts = {})
locale = user_locale(user)
tips = I18n.t('system_messages.usage_tips.text_body_template',
base_url: Discourse.base_url,
locale: locale)
build_email(user.email,
template: 'user_notifications.signup_after_approval',
locale: user_locale(user),
new_user_tips: I18n.t('system_messages.usage_tips.text_body_template', base_url: Discourse.base_url, locale: locale))
locale: locale,
new_user_tips: tips)
end
def notify_old_email(user, opts = {})
@ -320,7 +325,7 @@ class UserNotifications < ActionMailer::Base
protected
def user_locale(user)
(user.locale.present? && I18n.available_locales.include?(user.locale.to_sym)) ? user.locale : nil
user.effective_locale
end
def email_post_markdown(post, add_posted_by = false)

View File

@ -802,12 +802,15 @@ describe UserNotifications do
describe "notifications from template" do
context "user locale has been set" do
context "user locale is allowed" do
before do
SiteSetting.default_locale = "en"
SiteSetting.allow_user_locale = true
end
%w(signup signup_after_approval confirm_old_email notify_old_email confirm_new_email
forgot_password admin_login account_created).each do |mail_type|
include_examples "notification derived from template" do
SiteSetting.default_locale = "en"
let(:locale) { "fr" }
let(:mail_type) { mail_type }
it "sets the locale" do
@ -817,29 +820,19 @@ describe UserNotifications do
end
end
context "user locale has not been set" do
context "user locale is not allowed" do
before do
SiteSetting.default_locale = "en"
SiteSetting.allow_user_locale = false
end
%w(signup signup_after_approval notify_old_email confirm_old_email confirm_new_email
forgot_password admin_login account_created).each do |mail_type|
include_examples "notification derived from template" do
SiteSetting.default_locale = "en"
let(:locale) { nil }
let(:locale) { "fr" }
let(:mail_type) { mail_type }
it "sets the locale" do
expects_build_with(has_entry(:locale, nil))
end
end
end
end
context "user locale is an empty string" do
%w(signup signup_after_approval notify_old_email confirm_new_email confirm_old_email
forgot_password admin_login account_created).each do |mail_type|
include_examples "notification derived from template" do
SiteSetting.default_locale = "en"
let(:locale) { "" }
let(:mail_type) { mail_type }
it "sets the locale" do
expects_build_with(has_entry(:locale, nil))
expects_build_with(has_entry(:locale, "en"))
end
end
end