Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[34901] Set timezone when switching to user

Oliver Günther4fa5e38c3d37
diff --git a/app/models/user.rb b/app/models/user.rb
index ad33ae26a6d..7c4ab0170a4 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -543,10 +543,10 @@ class User < Principal
RequestStore[:current_user] || User.anonymous
end
- def self.execute_as(user)
+ def self.execute_as(user, &block)
previous_user = User.current
User.current = user
- yield
+ OpenProject::LocaleHelper.with_locale_for(user, &block)
ensure
User.current = previous_user
end
diff --git a/modules/meeting/app/mailers/meeting_mailer.rb b/modules/meeting/app/mailers/meeting_mailer.rb
index 9bd6e1358c5..48f1e0b62ea 100644
--- a/modules/meeting/app/mailers/meeting_mailer.rb
+++ b/modules/meeting/app/mailers/meeting_mailer.rb
@@ -37,7 +37,7 @@ class MeetingMailer < UserMailer
open_project_headers 'Project' => @meeting.project.identifier,
'Meeting-Id' => @meeting.id
- with_locale_for(user) do
+ User.execute_as(user) do
subject = "[#{@meeting.project.name}] #{I18n.t(:"label_#{content_type}")}: #{@meeting.title}"
mail to: user.mail, subject: subject
end
@@ -58,7 +58,7 @@ class MeetingMailer < UserMailer
# Create a calendar with an event (standard method)
entry = ::Icalendar::Calendar.new
- with_locale_for(user) do
+ User.execute_as(user) do
subject = "[#{@meeting.project.name}] #{I18n.t(:"label_#{@content_type}")}: #{@meeting.title}"
tzid = @meeting.start_time.zone
tz = TZInfo::Timezone.get tzid
diff --git a/modules/meeting/app/views/meeting_mailer/icalendar_notification.html.erb b/modules/meeting/app/views/meeting_mailer/icalendar_notification.html.erb
index 919f5c4dc07..d687dfbbb59 100644
--- a/modules/meeting/app/views/meeting_mailer/icalendar_notification.html.erb
+++ b/modules/meeting/app/views/meeting_mailer/icalendar_notification.html.erb
@@ -8,4 +8,4 @@
<li><%=Meeting.human_attribute_name(:location) %>: <%= @meeting.location %></li>
<li><%=Meeting.human_attribute_name(:participants_invited) %>: <%= @meeting.participants.invited.sort.join("; ") %></li>
<li><%=Meeting.human_attribute_name(:participants_attended) %>: <%= @meeting.participants.attended.sort.join("; ") %></li>
-</ul>
\ No newline at end of file
+</ul>