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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[31127] Correct timezone in user and meeting mailer
Oliver Günther3001a93ee650
diff --git a/lib/open_project/locale_helper.rb b/lib/open_project/locale_helper.rbindex 81edcf781bb..8f6c87cd0e6 100644--- a/lib/open_project/locale_helper.rb+++ b/lib/open_project/locale_helper.rb@@ -31,10 +31,13 @@ module OpenProjectmodule LocaleHelperdef with_locale_for(user)previous_locale = I18n.locale+ previous_zone = Time.zone+ Time.zone = user.time_zone if user.time_zoneSetLocalizationService.new(user).callyieldensureI18n.locale = previous_locale+ Time.zone = previous_zoneendendenddiff --git a/modules/meeting/app/mailers/meeting_mailer.rb b/modules/meeting/app/mailers/meeting_mailer.rbindex e5597a6218c..d6b697a0ca7 100644--- a/modules/meeting/app/mailers/meeting_mailer.rb+++ b/modules/meeting/app/mailers/meeting_mailer.rb@@ -22,18 +22,20 @@ require 'icalendar'require 'icalendar/tzinfo'class MeetingMailer < UserMailer- def content_for_review(content, content_type, address)+ def content_for_review(content, content_type, user)@meeting = content.meeting@content_type = content_typeopen_project_headers 'Project' => @meeting.project.identifier,'Meeting-Id' => @meeting.id- subject = "[#{@meeting.project.name}] #{I18n.t(:"label_#{content_type}")}: #{@meeting.title}"- mail to: address, subject: subject+ with_locale_for(user) do+ subject = "[#{@meeting.project.name}] #{I18n.t(:"label_#{content_type}")}: #{@meeting.title}"+ mail to: user.mail, subject: subject+ endend- def icalendar_notification(content, content_type, address)+ def icalendar_notification(content, content_type, user)@meeting = content.meeting@content_type = content_type@@ -42,30 +44,31 @@ class MeetingMailer < UserMailerheaders['Content-Type'] = 'text/calendar; charset=utf-8; method="PUBLISH"; name="meeting.ics"'headers['Content-Transfer-Encoding'] = '8bit'- subject = "[#{@meeting.project.name}] #{I18n.t(:"label_#{@content_type}")}: #{@meeting.title}"-author = Icalendar::Values::CalAddress.new("mailto:#{@meeting.author.mail}",cn: @meeting.author.name)# Create a calendar with an event (standard method)entry = ::Icalendar::Calendar.new- tzid = @meeting.start_time.zone- tz = TZInfo::Timezone.get tzid- timezone = tz.ical_timezone @meeting.start_time- entry.add_timezone timezone+ with_locale_for(user) do+ subject = "[#{@meeting.project.name}] #{I18n.t(:"label_#{@content_type}")}: #{@meeting.title}"+ tzid = @meeting.start_time.zone+ tz = TZInfo::Timezone.get tzid+ timezone = tz.ical_timezone @meeting.start_time+ entry.add_timezone timezone- entry.event do |e|- e.dtstart = Icalendar::Values::DateTime.new @meeting.start_time, 'tzid' => tzid- e.dtend = Icalendar::Values::DateTime.new @meeting.end_time, 'tzid' => tzid- e.url = meeting_url(@meeting)- e.summary = "[#{@meeting.project.name}] #{@meeting.title}"- e.description = subject- e.uid = "#{@meeting.id}@#{@meeting.project.identifier}"- e.organizer = author- end+ entry.event do |e|+ e.dtstart = Icalendar::Values::DateTime.new @meeting.start_time, 'tzid' => tzid+ e.dtend = Icalendar::Values::DateTime.new @meeting.end_time, 'tzid' => tzid+ e.url = meeting_url(@meeting)+ e.summary = "[#{@meeting.project.name}] #{@meeting.title}"+ e.description = subject+ e.uid = "#{@meeting.id}@#{@meeting.project.identifier}"+ e.organizer = author+ end- attachments['meeting.ics'] = entry.to_ical- mail(to: address, subject: subject)+ attachments['meeting.ics'] = entry.to_ical+ mail(to: user.mail, subject: subject)+ endendenddiff --git a/modules/meeting/app/services/meeting_notification_service.rb b/modules/meeting/app/services/meeting_notification_service.rbindex 55b354d456c..059a71cae78 100644--- a/modules/meeting/app/services/meeting_notification_service.rb+++ b/modules/meeting/app/services/meeting_notification_service.rb@@ -19,10 +19,11 @@ class MeetingNotificationServicedo_not_notify_author = meeting.author.pref[:no_self_notified] && !include_authorrecipients_with_errors = []- meeting.participants.each do |recipient|+ meeting.participants.includes(:user).each do |recipient|beginnext if recipient.mail == author_mail && do_not_notify_author- MeetingMailer.send(action, content, content_type, recipient.mail).deliver_now++ MeetingMailer.send(action, content, content_type, recipient.user).deliver_nowrescue => eRails.logger.error {"Failed to deliver #{action} notification to #{recipient.mail}: #{e.message}"diff --git a/modules/meeting/spec/mailers/meeting_mailer_spec.rb b/modules/meeting/spec/mailers/meeting_mailer_spec.rbindex 2143b76605f..a52c78eaaab 100644--- a/modules/meeting/spec/mailers/meeting_mailer_spec.rb+++ b/modules/meeting/spec/mailers/meeting_mailer_spec.rb@@ -40,7 +40,7 @@ describe MeetingMailer, type: :mailer doenddescribe 'content_for_review' do- let(:mail) { MeetingMailer.content_for_review meeting_agenda, 'agenda', author.mail }+ let(:mail) { MeetingMailer.content_for_review meeting_agenda, 'agenda', author }# this is needed to call module functions from Redmine::I18nlet(:i18n) doclass A@@ -64,6 +64,20 @@ describe MeetingMailer, type: :mailer doit 'renders the html body' docheck_meeting_mail_content mail.html_part.bodyend++ context 'with a recipient with another time zone' do+ let!(:preference) { FactoryBot.create(:user_preference, user: watcher1, time_zone: 'Asia/Tokyo') }+ let(:mail) { MeetingMailer.content_for_review meeting_agenda, 'agenda', watcher1 }++ it 'renders the mail with the correcet locale' do+ expect(mail.text_part.body).to include('Tokyo')+ expect(mail.text_part.body).to include('GMT+09:00')+ expect(mail.html_part.body).to include('Tokyo')+ expect(mail.html_part.body).to include('GMT+09:00')++ expect(mail.to).to match_array([watcher1.mail])+ end+ endenddef check_meeting_mail_content(body)