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

Fix recurring meetings not receiving rescheduled mails

Oliver Günther63e5e5252428
diff --git a/modules/meeting/app/mailers/meeting_series_mailer.rb b/modules/meeting/app/mailers/meeting_series_mailer.rb
index 0eafbab385b..77b3418faaf 100644
--- a/modules/meeting/app/mailers/meeting_series_mailer.rb
+++ b/modules/meeting/app/mailers/meeting_series_mailer.rb
@@ -42,6 +42,20 @@ class MeetingSeriesMailer < UserMailer
end
end
+ def rescheduled(series, user, actor, changes:)
+ @actor = actor
+ @series = series
+ @user = user
+ @changes = changes
+
+ set_headers(series)
+
+ with_attached_ics(series, user) do
+ subject = I18n.t("meeting.email.series_rescheduled.title", title: series.title, project_name: series.project.name)
+ mail(to: user, subject:)
+ end
+ end
+
private
def with_attached_ics(series, user)
diff --git a/modules/meeting/app/services/recurring_meetings/update_service.rb b/modules/meeting/app/services/recurring_meetings/update_service.rb
index 9c00ff4253c..054e0702ca8 100644
--- a/modules/meeting/app/services/recurring_meetings/update_service.rb
+++ b/modules/meeting/app/services/recurring_meetings/update_service.rb
@@ -32,11 +32,22 @@ module RecurringMeetings
protected
+ def validate_params(*)
+ @old_schedule = model.full_schedule_in_words
+ super
+ end
+
def after_perform(call)
return call unless call.success?
- cleanup_cancelled_schedules(call.result)
- reschedule_init_job(call.result)
+ recurring_meeting = call.result
+ cleanup_cancelled_schedules(recurring_meeting)
+
+ if should_reschedule?(recurring_meeting)
+ reschedule_init_job(recurring_meeting)
+ send_rescheduled_mail(recurring_meeting)
+ end
+
update_template(call)
end
@@ -61,9 +72,22 @@ module RecurringMeetings
end
end
- def reschedule_init_job(recurring_meeting)
- return unless should_reschedule?(recurring_meeting)
+ def send_rescheduled_mail(recurring_meeting)
+ recurring_meeting
+ .template
+ .participants
+ .invited
+ .find_each do |participant|
+ MeetingSeriesMailer.rescheduled(
+ recurring_meeting,
+ participant.user,
+ User.current,
+ changes: { old_schedule: @old_schedule }
+ ).deliver_later
+ end
+ end
+ def reschedule_init_job(recurring_meeting)
concurrency_key = InitNextOccurrenceJob.unique_key(recurring_meeting)
# Delete all scheduled jobs for this meeting
diff --git a/modules/meeting/app/views/meeting_series_mailer/rescheduled.html.erb b/modules/meeting/app/views/meeting_series_mailer/rescheduled.html.erb
new file mode 100644
index 00000000000..85ef00eb537
--- /dev/null
+++ b/modules/meeting/app/views/meeting_series_mailer/rescheduled.html.erb
@@ -0,0 +1,94 @@
+<%#-- copyright
+OpenProject is an open source project management software.
+Copyright (C) the OpenProject GmbH
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License version 3.
+
+OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+Copyright (C) 2006-2013 Jean-Philippe Lang
+Copyright (C) 2010-2013 the ChiliProject Team
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+See COPYRIGHT and LICENSE files for more details.
+
+++#%>
+
+<%= render layout: "mailer/spacer_table" do %>
+ <%= render partial: "mailer/mailer_header",
+ locals: {
+ user: @user,
+ summary: I18n.t("meeting.email.series_rescheduled.summary", title: @series.title, actor: @actor),
+ bottom_spacing: false
+ } %>
+
+ <%= render layout: "mailer/border_table" do %>
+ <tr>
+ <%= placeholder_cell("24px", vertical: true) %>
+ <td>
+ <table>
+ <tr>
+ <td style="<%= placeholder_text_styles(width: "30%") %>">
+ <%= t("meeting.email.series_rescheduled.old_schedule") %>
+ </td>
+ <td style="<%= placeholder_text_styles %>">
+ <s>
+ <%= @changes[:old_schedule] %> (<%= formatted_time_zone_offset %>)
+ </s>
+ </td>
+ </tr>
+ <tr>
+ <td style="<%= placeholder_text_styles(width: "30%") %>">
+ <%= t("meeting.email.series_rescheduled.new_schedule") %>
+ </td>
+ <td style="<%= placeholder_text_styles("font-weight": "bold") %>">
+ <%= @series.full_schedule_in_words %> (<%= formatted_time_zone_offset %>)
+ </td>
+ </tr>
+ <tr>
+ <td style="<%= placeholder_text_styles(width: "30%") %>">
+ <%= Meeting.human_attribute_name(:project) %>
+ </td>
+ <td style="<%= placeholder_text_styles %>">
+ <%= link_to @series.project.name, project_url(@series.project) %>
+ </td>
+ </tr>
+ <tr>
+ <td style="<%= placeholder_text_styles(width: "30%") %>">
+ <%= Meeting.human_attribute_name(:author) %>
+ </td>
+ <td style="<%= placeholder_text_styles %>">
+ <%= @series.author %>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <% end %>
+
+ <table>
+ <tr>
+ <%= placeholder_cell("20px", vertical: false) %>
+ </tr>
+ </table>
+
+ <%= action_button do %>
+ <%= link_to I18n.t(:"meeting.email.open_meeting_link"),
+ recurring_meeting_url(@series),
+ target: "_blank",
+ style: "color: #333333; text-decoration: none; font-size: 14px;white-space: nowrap;", rel: "noopener" %>
+ <% end %>
+<% end %>
diff --git a/modules/meeting/app/views/meeting_series_mailer/rescheduled.text.erb b/modules/meeting/app/views/meeting_series_mailer/rescheduled.text.erb
new file mode 100644
index 00000000000..594b498e796
--- /dev/null
+++ b/modules/meeting/app/views/meeting_series_mailer/rescheduled.text.erb
@@ -0,0 +1,41 @@
+<%#-- copyright
+OpenProject is an open source project management software.
+Copyright (C) the OpenProject GmbH
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License version 3.
+
+OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+Copyright (C) 2006-2013 Jean-Philippe Lang
+Copyright (C) 2010-2013 the ChiliProject Team
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+See COPYRIGHT and LICENSE files for more details.
+
+++#%>
+
+<%= @series.project.name %>: <%= @series.title %> (<%= recurring_meeting_url(@series) %>)
+<%= @series.author %>
+
+<%= t('meeting.email.series_rescheduled.summary',
+ actor: @actor,
+ title: @series.title) %>
+
+<%= t('meeting.email.series_rescheduled.old_schedule') %>:
+<%= @changes[:old_schedule] %> (<%= formatted_time_zone_offset %>)
+
+<%= t('meeting.email.series_rescheduled.new_schedule') %>:
+<%= @series.full_schedule_in_words %> (<%= formatted_time_zone_offset %>)
diff --git a/modules/meeting/app/views/meeting_series_mailer/template_completed.text.erb b/modules/meeting/app/views/meeting_series_mailer/template_completed.text.erb
index c86fa4bece0..a48349949f2 100644
--- a/modules/meeting/app/views/meeting_series_mailer/template_completed.text.erb
+++ b/modules/meeting/app/views/meeting_series_mailer/template_completed.text.erb
@@ -32,6 +32,6 @@ See COPYRIGHT and LICENSE files for more details.
<%= @series.project.name %>: <%= @series.title %> (<%= meeting_url(@series) %>)
<%= @series.author %>
-<%=t :label_meeting_date_time %>: <%= format_time_as_date @template.start_time %> <%= format_time @template.start_time, include_date: false %>-<%= format_time @template.end_time, include_date: false %> (<%= formatted_time_zone_offset %>)
+<%=t :label_recurring_meeting_schedule %>: <%= @series.full_schedule_in_words %> (<%= formatted_time_zone_offset %>)
<%= Meeting.human_attribute_name(:location) %>: <%= @template.location %>
<%= Meeting.human_attribute_name(:participants_invited) %>: <%= @template.participants.invited.sort.join("; ") %>
diff --git a/modules/meeting/config/locales/en.yml b/modules/meeting/config/locales/en.yml
index e08617f39f9..ed6592ead40 100644
--- a/modules/meeting/config/locales/en.yml
+++ b/modules/meeting/config/locales/en.yml
@@ -198,10 +198,15 @@ en:
open_meeting_link: "Open meeting"
open_my_meetings_link: "Go to My meetings"
series:
- title: "[%{project_name}] Meeting series %{title}"
- summary: "%{actor} has set up a new meeting series %{title}"
+ title: "[%{project_name}] Meeting series '%{title}'"
+ summary: "%{actor} has set up a new meeting series '%{title}'"
+ series_rescheduled:
+ title: "[%{project_name}] Meeting series '%{title}' rescheduled"
+ summary: "%{actor} has changed the schedule for meeting series '%{title}'"
+ old_schedule: "Old schedule"
+ new_schedule: "New schedule"
invited:
- summary: "%{actor} has sent you an invitation for the meeting %{title}"
+ summary: "%{actor} has sent you an invitation for the meeting '%{title}'"
cancelled:
header: "Cancelled: Meeting '%{title}'"
header_occurrence: "Cancelled: Meeting occurrence '%{title}'"
@@ -211,9 +216,9 @@ en:
summary: "'%{title}' has been cancelled by %{actor}."
date_time: "Scheduled date/time"
rescheduled:
- header: "Meeting %{title} has been rescheduled"
- summary: "Meeting %{title} has been rescheduled by %{actor}"
- body: "The meeting %{title} has been rescheduled by %{actor}."
+ header: "Meeting '%{title}' has been rescheduled"
+ summary: "Meeting '%{title}' has been rescheduled by %{actor}"
+ body: "The meeting '%{title}' has been rescheduled by %{actor}."
old_date_time: "Old date/time"
new_date_time: "New date/time"
label_mail_all_participants: "Send email to all participants"
diff --git a/modules/meeting/spec/features/recurring_meetings/recurring_meeting_create_spec.rb b/modules/meeting/spec/features/recurring_meetings/recurring_meeting_create_spec.rb
index 4c83041dfd2..f307cdf1b06 100644
--- a/modules/meeting/spec/features/recurring_meetings/recurring_meeting_create_spec.rb
+++ b/modules/meeting/spec/features/recurring_meetings/recurring_meeting_create_spec.rb
@@ -134,7 +134,7 @@ RSpec.describe "Recurring meetings creation",
perform_enqueued_jobs
expect(ActionMailer::Base.deliveries.size).to eq 2
title = ActionMailer::Base.deliveries.map(&:subject).uniq.first
- expect(title).to eq "[#{project.name}] Meeting series Some title"
+ expect(title).to eq "[#{project.name}] Meeting series 'Some title'"
end
end
diff --git a/modules/meeting/spec/mailers/meeting_series_mailer_spec.rb b/modules/meeting/spec/mailers/meeting_series_mailer_spec.rb
new file mode 100644
index 00000000000..2116ac5c633
--- /dev/null
+++ b/modules/meeting/spec/mailers/meeting_series_mailer_spec.rb
@@ -0,0 +1,158 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+require_relative "../spec_helper"
+
+RSpec.describe MeetingSeriesMailer do
+ shared_let(:role) { create(:project_role, permissions: [:view_meetings]) }
+ shared_let(:project) { create(:project, name: "My project") }
+ shared_let(:author) do
+ create(:user,
+ member_with_roles: { project => role },
+ preferences: { time_zone: "Europe/Berlin" })
+ end
+ shared_let(:recipient) { create(:user, member_with_roles: { project => role }) }
+
+ let(:series) do
+ create(:recurring_meeting,
+ title: "Recurring Standup",
+ project: project,
+ author: author)
+ end
+ let(:i18n) do
+ Class.new do
+ include Redmine::I18n
+ public :format_date, :format_time
+ end
+ end
+
+ let(:tokyo_offset) { "UTC#{ActiveSupport::TimeZone['Asia/Tokyo'].now.formatted_offset}" }
+ let(:berlin_offset) { "UTC#{ActiveSupport::TimeZone['Europe/Berlin'].now.formatted_offset}" }
+
+ before do
+ User.current = author
+ end
+
+ describe "template_completed" do
+ let(:mail) { described_class.template_completed(series, recipient, author) }
+
+ it "renders the headers" do
+ expect(mail.subject).to include(series.project.name)
+ expect(mail.subject).to include(series.title)
+ expect(mail.to).to contain_exactly(recipient.mail)
+ expect(mail.from).to eq([Setting.mail_from])
+ end
+
+ it "renders the text body" do
+ User.execute_as(recipient) do
+ check_series_mail_content(mail.text_part.body)
+ end
+ end
+
+ it "renders the html body" do
+ User.execute_as(recipient) do
+ check_series_mail_content(mail.html_part.body)
+ end
+ end
+
+ it "attaches an iCalendar file" do
+ expect(mail.attachments["meeting.ics"]).to be_present
+ end
+ end
+
+ describe "rescheduled" do
+ let(:changes) { { old_schedule: "some old schedule" } }
+ let(:mail) { described_class.rescheduled(series, recipient, author, changes:) }
+
+ it "renders the headers" do
+ expect(mail.subject).to include(series.project.name)
+ expect(mail.subject).to include(series.title)
+ expect(mail.to).to contain_exactly(recipient.mail)
+ expect(mail.from).to eq([Setting.mail_from])
+ end
+
+ it "renders the text body" do
+ User.execute_as(recipient) do
+ check_series_mail_content(mail.text_part.body)
+ expect(mail.text_part.body).to include("has changed the schedule")
+ expect(mail.text_part.body).to include("some old schedule")
+ expect(mail.text_part.body).to include(series.full_schedule_in_words)
+ end
+ end
+
+ it "renders the html body" do
+ User.execute_as(recipient) do
+ check_series_mail_content(mail.html_part.body)
+ expect(mail.html_part.body).to include("has changed the schedule")
+ expect(mail.html_part.body).to include("some old schedule")
+ expect(mail.html_part.body).to include(series.full_schedule_in_words)
+ end
+ end
+
+ it "attaches an iCalendar file" do
+ expect(mail.attachments["meeting.ics"]).to be_present
+ end
+ end
+
+ describe "icalendar attachment" do
+ let(:mail) { described_class.template_completed(series, recipient, author) }
+ let(:ical) { mail.parts.detect { |x| !x.multipart? } }
+ let(:parsed) { Icalendar::Event.parse(ical.body.raw_source) }
+ let(:entry) { parsed.first }
+
+ it "renders the calendar entry" do
+ expect(parsed).to be_a Array
+ expect(parsed.length).to eq 1
+
+ expect(entry.summary).to eq "[My project] Recurring Standup"
+ expect(entry.description).to eq "[My project] Meeting series: Recurring Standup"
+ expect(entry.location).to eq(series.template&.location.presence)
+ end
+ end
+
+ context "with a recipient with another time zone" do
+ let!(:preference) { recipient.pref.update(time_zone: "Asia/Tokyo") }
+ let(:mail) { described_class.template_completed(series, recipient, author) }
+
+ it "renders the mail with the correct locale" do
+ expect(mail.text_part.body).to include(tokyo_offset)
+ expect(mail.html_part.body).to include(tokyo_offset)
+
+ expect(mail.to).to contain_exactly(recipient.mail)
+ end
+ end
+
+ def check_series_mail_content(body)
+ expect(body).to include(series.project.name)
+ expect(body).to include(series.title)
+ expect(body).to include(series.full_schedule_in_words)
+ expect(body).to include(i18n.formatted_time_zone_offset)
+ end
+end
diff --git a/modules/meeting/spec/services/recurring_meetings/update_service_integration_spec.rb b/modules/meeting/spec/services/recurring_meetings/update_service_integration_spec.rb
index 333bceca20b..0c5bafff4a9 100644
--- a/modules/meeting/spec/services/recurring_meetings/update_service_integration_spec.rb
+++ b/modules/meeting/spec/services/recurring_meetings/update_service_integration_spec.rb
@@ -121,4 +121,41 @@ RSpec.describe RecurringMeetings::UpdateService, "integration", type: :model do
end
end
end
+
+ describe "rescheduling mails" do
+ context "when updating the title" do
+ let(:params) do
+ { title: "New title" }
+ end
+
+ it "does not create them" do
+ expect(service_result).to be_success
+ perform_enqueued_jobs
+ expect(ActionMailer::Base.deliveries).to be_empty
+ end
+ end
+
+ context "when updating the frequency and start_time" do
+ let(:params) do
+ { start_time: Time.zone.today + 2.days + 11.hours }
+ end
+
+ let(:recipient) do
+ create(:user, member_with_permissions: { project => %i(view_meetings) })
+ end
+
+ before do
+ series.template.participants.delete_all
+ series.template.participants << MeetingParticipant.new(user: recipient, invited: true)
+ end
+
+ it "sends out rescheduled mails" do
+ expect(service_result).to be_success
+ perform_enqueued_jobs
+ expect(ActionMailer::Base.deliveries.count).to eq(1)
+ expect(ActionMailer::Base.deliveries.first.subject)
+ .to eq "[#{project.name}] Meeting series '#{series.title}' rescheduled"
+ end
+ end
+ end
end
diff --git a/spec/mailers/previews/meeting_series_mailer_preview.rb b/spec/mailers/previews/meeting_series_mailer_preview.rb
index 569af0b2123..0db3e3e2148 100644
--- a/spec/mailers/previews/meeting_series_mailer_preview.rb
+++ b/spec/mailers/previews/meeting_series_mailer_preview.rb
@@ -37,4 +37,19 @@ class MeetingSeriesMailerPreview < ActionMailer::Preview
MeetingSeriesMailer.template_completed(meeting, user, actor)
end
+
+ def rescheduled
+ language = params["locale"] || I18n.default_locale
+ actor = FactoryBot.build_stubbed(:user, lastname: "Actor")
+ user = FactoryBot.build_stubbed(:user, language:)
+ meeting = RecurringMeeting.last
+ old_schedule = meeting.full_schedule_in_words
+
+ meeting.start_time = 5.days.from_now
+ meeting.frequency = 2
+ meeting.end_after = "iterations"
+ meeting.iterations = 2
+
+ MeetingSeriesMailer.rescheduled(meeting, user, actor, changes: { old_schedule: })
+ end
end