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

Implement email notifications for meetings

Oliver Günther753b5c69f5fc
diff --git a/modules/meeting/app/components/meetings/header_component.html.erb b/modules/meeting/app/components/meetings/header_component.html.erb
index 32083ed3012..a85d5b23f7d 100644
--- a/modules/meeting/app/components/meetings/header_component.html.erb
+++ b/modules/meeting/app/components/meetings/header_component.html.erb
@@ -26,6 +26,14 @@
item.with_leading_visual_icon(icon: :download)
end
+ if User.current.allowed_to?(:send_meeting_agendas_notification, @meeting.project)
+ menu.with_item(label: t('meeting.label_mail_all_participants'),
+ href: notify_meeting_path(@meeting),
+ form_arguments: { method: :post, data: { turbo: 'false' } }) do |item|
+ item.with_leading_visual_icon(icon: :mail)
+ end
+ end
+
menu.with_item(label: t("label_meeting_delete"),
scheme: :danger,
href: meeting_path(@meeting),
diff --git a/modules/meeting/app/controllers/meeting_contents_controller.rb b/modules/meeting/app/controllers/meeting_contents_controller.rb
index 799d58c1911..9da573568a2 100644
--- a/modules/meeting/app/controllers/meeting_contents_controller.rb
+++ b/modules/meeting/app/controllers/meeting_contents_controller.rb
@@ -92,8 +92,8 @@ class MeetingContentsController < ApplicationController
def notify
unless @content.new_record?
- service = MeetingNotificationService.new(@meeting, @content_type)
- result = service.call(@content, :content_for_review)
+ service = MeetingNotificationService.new(@meeting)
+ result = service.call(:invited)
if result.success?
flash[:notice] = I18n.t(:notice_successful_notification)
@@ -107,8 +107,8 @@ class MeetingContentsController < ApplicationController
def icalendar
unless @content.new_record?
- service = MeetingNotificationService.new(@meeting, @content_type)
- result = service.call(@content, :icalendar_notification, include_author: true)
+ service = MeetingNotificationService.new(@meeting)
+ result = service.call(:icalendar_notification, include_author: true)
if result.success?
flash[:notice] = I18n.t(:notice_successful_notification)
diff --git a/modules/meeting/app/controllers/meetings_controller.rb b/modules/meeting/app/controllers/meetings_controller.rb
index 8b978318fbc..907ecc4a4fb 100644
--- a/modules/meeting/app/controllers/meetings_controller.rb
+++ b/modules/meeting/app/controllers/meetings_controller.rb
@@ -210,6 +210,20 @@ class MeetingsController < ApplicationController
end
end
+ def notify
+ service = MeetingNotificationService.new(@meeting)
+ result = service.call(:invited)
+
+ if result.success?
+ flash[:notice] = I18n.t(:notice_successful_notification)
+ else
+ flash[:error] = I18n.t(:error_notification_with_errors,
+ recipients: result.errors.map(&:name).join('; '))
+ end
+
+ redirect_to action: :show, id: @meeting
+ end
+
private
def load_query
@@ -264,8 +278,8 @@ class MeetingsController < ApplicationController
def find_meeting
@meeting = Meeting
- .includes([:project, :author, { participants: :user }, :agenda, :minutes])
- .find(params[:id])
+ .includes([:project, :author, { participants: :user }, :agenda, :minutes])
+ .find(params[:id])
@project = @meeting.project
rescue ActiveRecord::RecordNotFound
render_404
diff --git a/modules/meeting/app/mailers/meeting_mailer.rb b/modules/meeting/app/mailers/meeting_mailer.rb
index fedc207be80..209441dafac 100644
--- a/modules/meeting/app/mailers/meeting_mailer.rb
+++ b/modules/meeting/app/mailers/meeting_mailer.rb
@@ -29,22 +29,32 @@
class MeetingMailer < UserMailer
- def content_for_review(content, content_type, user)
- @author = User.current
- @meeting = content.meeting
- @content_type = content_type
+ def invited(meeting, user, author)
+ @author = author
+ @meeting = meeting
open_project_headers 'Project' => @meeting.project.identifier,
'Meeting-Id' => @meeting.id
User.execute_as(user) do
- subject = "[#{@meeting.project.name}] #{I18n.t(:"label_#{content_type}")}: #{@meeting.title}"
- mail to: user.mail, subject:
+ timezone = Time.zone || Time.zone_default
+
+ @formatted_timezone = format_timezone_offset timezone, @meeting.start_time
+
+ ::Meetings::ICalService
+ .new(user:, meeting: @meeting)
+ .call
+ .on_success do |call|
+ attachments['meeting.ics'] = call.result
+
+ subject = "[#{@meeting.project.name}] #{@meeting.title}"
+ mail(to: user.mail, subject:)
+ end
end
end
- def icalendar_notification(content, content_type, user)
- @meeting = content.meeting
+ def icalendar_notification(meeting, content_type, user)
+ @meeting = meeting
@content_type = content_type
set_headers @meeting
diff --git a/modules/meeting/app/models/meeting.rb b/modules/meeting/app/models/meeting.rb
index 0290ee8cdb9..2c1c555bd09 100644
--- a/modules/meeting/app/models/meeting.rb
+++ b/modules/meeting/app/models/meeting.rb
@@ -36,7 +36,12 @@ class Meeting < ApplicationRecord
has_one :agenda, dependent: :destroy, class_name: 'MeetingAgenda'
has_one :minutes, dependent: :destroy, class_name: 'MeetingMinutes'
has_many :contents, -> { readonly }, class_name: 'MeetingContent'
- has_many :participants, dependent: :destroy, class_name: 'MeetingParticipant'
+
+ has_many :participants,
+ dependent: :destroy,
+ class_name: 'MeetingParticipant',
+ after_add: :send_participant_added_mail
+
has_many :agenda_items, dependent: :destroy, class_name: 'MeetingAgendaItem'
default_scope do
@@ -310,4 +315,8 @@ class Meeting < ApplicationRecord
add_watcher(p.user)
end
end
+
+ def send_participant_added_mail(participant)
+ MeetingMailer.invited(self, participant.user, User.current).deliver_later
+ end
end
diff --git a/modules/meeting/app/services/meeting_notification_service.rb b/modules/meeting/app/services/meeting_notification_service.rb
index 44c77c9b6ce..be7b2ff82fc 100644
--- a/modules/meeting/app/services/meeting_notification_service.rb
+++ b/modules/meeting/app/services/meeting_notification_service.rb
@@ -1,26 +1,25 @@
class MeetingNotificationService
attr_reader :meeting, :content_type
- def initialize(meeting, content_type)
+ def initialize(meeting)
@meeting = meeting
- @content_type = content_type
end
- def call(content, action, include_author: false)
- recipients_with_errors = send_notifications!(content, action, include_author:)
+ def call(action, include_author: false)
+ recipients_with_errors = send_notifications!(action, include_author:)
ServiceResult.new(success: recipients_with_errors.empty?, errors: recipients_with_errors)
end
private
- def send_notifications!(content, action, include_author:)
+ def send_notifications!(action, include_author:)
author_mail = meeting.author.mail
recipients_with_errors = []
- meeting.participants.includes(:user).each do |recipient|
+ meeting.participants.includes(:user).find_each do |recipient|
next if recipient.mail == author_mail && !include_author
- MeetingMailer.send(action, content, content_type, recipient.user).deliver_now
+ MeetingMailer.send(action, meeting, recipient.user, User.current).deliver_later
rescue StandardError => e
Rails.logger.error do
"Failed to deliver #{action} notification to #{recipient.mail}: #{e.message}"
diff --git a/modules/meeting/app/views/meeting_mailer/content_for_review.html.erb b/modules/meeting/app/views/meeting_mailer/invited.html.erb
similarity index 89%
rename from modules/meeting/app/views/meeting_mailer/content_for_review.html.erb
rename to modules/meeting/app/views/meeting_mailer/invited.html.erb
index ab643bd2060..77a09aee8b5 100644
--- a/modules/meeting/app/views/meeting_mailer/content_for_review.html.erb
+++ b/modules/meeting/app/views/meeting_mailer/invited.html.erb
@@ -38,9 +38,7 @@ See COPYRIGHT and LICENSE files for more details.
</ul>
<p>
- <%=raw t(:"text_review_#{@content_type}",
+ <%= raw t(:text_review_meeting,
:author => h(@author),
- :link => link_to(t(:"text_#{@content_type}_for_meeting",
- :meeting => @meeting.title),
- meeting_url(@meeting))) %>
+ :link => link_to(@meeting.title, meeting_url(@meeting))) %>
</p>
diff --git a/modules/meeting/app/views/meeting_mailer/content_for_review.text.erb b/modules/meeting/app/views/meeting_mailer/invited.text.erb
similarity index 91%
rename from modules/meeting/app/views/meeting_mailer/content_for_review.text.erb
rename to modules/meeting/app/views/meeting_mailer/invited.text.erb
index 9a92fb74c27..23435c17cf5 100644
--- a/modules/meeting/app/views/meeting_mailer/content_for_review.text.erb
+++ b/modules/meeting/app/views/meeting_mailer/invited.text.erb
@@ -35,7 +35,6 @@ See COPYRIGHT and LICENSE files for more details.
<%= Meeting.human_attribute_name(:participants_invited) %>: <%= @meeting.participants.invited.sort.join("; ") %>
<%= Meeting.human_attribute_name(:participants_attended) %>: <%= @meeting.participants.attended.sort.join("; ") %>
-<%=t(:"text_review_#{@content_type}",
+<%= t(:text_review_meeting,
:author => @author,
- :link => t(:"text_#{@content_type}_for_meeting",
- :meeting => @meeting.title) + " (#{meeting_url(@meeting)})") %>
+ :link => @meeting.title + " (#{meeting_url(@meeting)})") %>
diff --git a/modules/meeting/config/locales/en.yml b/modules/meeting/config/locales/en.yml
index 45fc6856cf3..4aeffbdd485 100644
--- a/modules/meeting/config/locales/en.yml
+++ b/modules/meeting/config/locales/en.yml
@@ -110,6 +110,7 @@ en:
meeting:
+ label_mail_all_participants: "Send email to all participants"
types:
classic: 'Classic'
classic_text: 'Organize your meeting in a formattable text agenda and protocol.'
@@ -143,8 +144,7 @@ en:
text_meeting_closing_are_you_sure: "Are you sure you want to close the meeting agenda?"
text_meeting_agenda_open_are_you_sure: "This will overwrite all changes in the minutes! Do you want to continue?"
text_meeting_minutes_for_meeting: 'minutes for the meeting "%{meeting}"'
- text_review_meeting_agenda: "%{author} has put the %{link} up for review."
- text_review_meeting_minutes: "%{author} has put the %{link} up for review."
+ text_review_meeting: "%{author} has sent you an invitation to the meeting %{link}."
text_notificiation_invited: "This mail contains an ics entry for the meeting below:"
text_meeting_empty_heading: "Your meeting is empty"
diff --git a/modules/meeting/config/routes.rb b/modules/meeting/config/routes.rb
index 6875ffe50d7..e28a792f98e 100644
--- a/modules/meeting/config/routes.rb
+++ b/modules/meeting/config/routes.rb
@@ -53,6 +53,7 @@ OpenProject::Application.routes.draw do
put :update_details
put :update_participants
put :change_state
+ post :notify
end
resources :agenda_items, controller: 'meeting_agenda_items' do
collection do
diff --git a/modules/meeting/lib/open_project/meeting/engine.rb b/modules/meeting/lib/open_project/meeting/engine.rb
index 511bb8fd71a..e039cce8c7e 100644
--- a/modules/meeting/lib/open_project/meeting/engine.rb
+++ b/modules/meeting/lib/open_project/meeting/engine.rb
@@ -85,7 +85,10 @@ module OpenProject::Meeting
permissible_on: :project,
require: :member
permission :send_meeting_agendas_notification,
- { meeting_agendas: [:notify] },
+ {
+ meetings: [:notify],
+ meeting_agendas: [:notify]
+ },
permissible_on: :project,
require: :member
permission :send_meeting_agendas_icalendar,