FIX: Ensure invalid timezone does not block critical emails (#26607)
See https://meta.discourse.org/t/invalid-user-timezone-jams-up-their-mail/303306 This ensures that "account silenced" and "account suspended" emails don't fail to send if the user has an invalid timezone.
This commit is contained in:
parent
380e5ca6cb
commit
8f52fd1051
|
@ -167,7 +167,7 @@ class UserNotifications < ActionMailer::Base
|
||||||
reason: user_history.details,
|
reason: user_history.details,
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
silenced_till = user.silenced_till.in_time_zone(user.user_option.timezone)
|
silenced_till = user.silenced_till.in_time_zone(user.user_option.timezone.presence || "UTC")
|
||||||
build_email(
|
build_email(
|
||||||
user.email,
|
user.email,
|
||||||
template: "user_notifications.account_silenced",
|
template: "user_notifications.account_silenced",
|
||||||
|
@ -191,7 +191,7 @@ class UserNotifications < ActionMailer::Base
|
||||||
reason: user_history.details,
|
reason: user_history.details,
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
suspended_till = user.suspended_till.in_time_zone(user.user_option.timezone)
|
suspended_till = user.suspended_till.in_time_zone(user.user_option.timezone.presence || "UTC")
|
||||||
build_email(
|
build_email(
|
||||||
user.email,
|
user.email,
|
||||||
template: "user_notifications.account_suspended",
|
template: "user_notifications.account_suspended",
|
||||||
|
|
|
@ -1471,6 +1471,23 @@ RSpec.describe UserNotifications do
|
||||||
expect(mail.body).to include(date)
|
expect(mail.body).to include(date)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when user timezone is invalid" do
|
||||||
|
before { user.user_option.timezone = "" }
|
||||||
|
|
||||||
|
it "doesn't raise error" do
|
||||||
|
expect { UserNotifications.account_silenced(user) }.not_to raise_error
|
||||||
|
end
|
||||||
|
|
||||||
|
it "adds the silenced_till date in UTC" do
|
||||||
|
date = "May 25, 2020, 12:00pm"
|
||||||
|
user.silenced_till = DateTime.parse(date)
|
||||||
|
|
||||||
|
mail = UserNotifications.account_silenced(user, { user_history: user_history })
|
||||||
|
|
||||||
|
expect(mail.body).to include(date)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".account_suspended" do
|
describe ".account_suspended" do
|
||||||
|
@ -1501,5 +1518,22 @@ RSpec.describe UserNotifications do
|
||||||
expect(mail.body).to include(date)
|
expect(mail.body).to include(date)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when user timezone is invalid" do
|
||||||
|
before { user.user_option.timezone = "" }
|
||||||
|
|
||||||
|
it "doesn't raise error" do
|
||||||
|
expect { UserNotifications.account_suspended(user) }.not_to raise_error
|
||||||
|
end
|
||||||
|
|
||||||
|
it "adds the suspended_till date in UTC" do
|
||||||
|
date = "May 25, 2020, 12:00pm"
|
||||||
|
user.suspended_till = DateTime.parse(date)
|
||||||
|
|
||||||
|
mail = UserNotifications.account_suspended(user, { user_history: user_history })
|
||||||
|
|
||||||
|
expect(mail.body).to include(date)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue