FIX: respect user timezone in emails about silencing and suspending (#16918)
This commit is contained in:
parent
0c590963c3
commit
25e4095c9c
|
@ -161,12 +161,13 @@ 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)
|
||||||
build_email(
|
build_email(
|
||||||
user.email,
|
user.email,
|
||||||
template: "user_notifications.account_silenced",
|
template: "user_notifications.account_silenced",
|
||||||
locale: user_locale(user),
|
locale: user_locale(user),
|
||||||
reason: user_history.details,
|
reason: user_history.details,
|
||||||
silenced_till: I18n.l(user.silenced_till, format: :long)
|
silenced_till: I18n.l(silenced_till, format: :long)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -184,12 +185,13 @@ 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)
|
||||||
build_email(
|
build_email(
|
||||||
user.email,
|
user.email,
|
||||||
template: "user_notifications.account_suspended",
|
template: "user_notifications.account_suspended",
|
||||||
locale: user_locale(user),
|
locale: user_locale(user),
|
||||||
reason: user_history.details,
|
reason: user_history.details,
|
||||||
suspended_till: I18n.l(user.suspended_till, format: :long)
|
suspended_till: I18n.l(suspended_till, format: :long)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
Fabricator(:user_history) do
|
||||||
|
end
|
|
@ -1184,4 +1184,68 @@ describe UserNotifications do
|
||||||
"[admin](http://test.localhost/u/admin)")
|
"[admin](http://test.localhost/u/admin)")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe ".account_silenced" do
|
||||||
|
fab!(:user_history) { Fabricate(:user_history, action: UserHistory.actions[:silence_user]) }
|
||||||
|
|
||||||
|
it "adds the silenced_till date in user's timezone" do
|
||||||
|
user.user_option.timezone = "Asia/Tbilisi" # GMT+4
|
||||||
|
user.silenced_till = DateTime.parse("May 25, 2020, 12:00pm")
|
||||||
|
|
||||||
|
mail = UserNotifications.account_silenced(user, { user_history: user_history })
|
||||||
|
|
||||||
|
expect(mail.body).to include("May 25, 2020, 4:00pm")
|
||||||
|
end
|
||||||
|
|
||||||
|
context "user doesn't have timezone set" do
|
||||||
|
before do
|
||||||
|
user.user_option.timezone = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
describe ".account_suspended" do
|
||||||
|
fab!(:user_history) { Fabricate(:user_history, action: UserHistory.actions[:suspend_user]) }
|
||||||
|
|
||||||
|
it "adds the suspended_till date in user's timezone" do
|
||||||
|
user.user_option.timezone = "Asia/Tbilisi" # GMT+4
|
||||||
|
user.suspended_till = DateTime.parse("May 25, 2020, 12:00pm")
|
||||||
|
|
||||||
|
mail = UserNotifications.account_suspended(user, { user_history: user_history })
|
||||||
|
|
||||||
|
expect(mail.body).to include("May 25, 2020, 4:00pm")
|
||||||
|
end
|
||||||
|
|
||||||
|
context "user doesn't have timezone set" do
|
||||||
|
before do
|
||||||
|
user.user_option.timezone = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
Loading…
Reference in New Issue