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
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.erbindex 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.rbindex 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 < ApplicationControllerdef notifyunless @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 < ApplicationControllerdef icalendarunless @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.rbindex 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 < ApplicationControllerendend+ 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+privatedef load_query@@ -264,8 +278,8 @@ class MeetingsController < ApplicationControllerdef 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.projectrescue ActiveRecord::RecordNotFoundrender_404diff --git a/modules/meeting/app/mailers/meeting_mailer.rb b/modules/meeting/app/mailers/meeting_mailer.rbindex 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 = meetingopen_project_headers 'Project' => @meeting.project.identifier,'Meeting-Id' => @meeting.idUser.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:)+ endendend- def icalendar_notification(content, content_type, user)- @meeting = content.meeting+ def icalendar_notification(meeting, content_type, user)+ @meeting = meeting@content_type = content_typeset_headers @meetingdiff --git a/modules/meeting/app/models/meeting.rb b/modules/meeting/app/models/meeting.rbindex 0290ee8cdb9..2c1c555bd09 100644--- a/modules/meeting/app/models/meeting.rb+++ b/modules/meeting/app/models/meeting.rb@@ -36,7 +36,12 @@ class Meeting < ApplicationRecordhas_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 < ApplicationRecordadd_watcher(p.user)endend++ def send_participant_added_mail(participant)+ MeetingMailer.invited(self, participant.user, User.current).deliver_later+ endenddiff --git a/modules/meeting/app/services/meeting_notification_service.rb b/modules/meeting/app/services/meeting_notification_service.rbindex 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 MeetingNotificationServiceattr_reader :meeting, :content_type- def initialize(meeting, content_type)+ def initialize(meeting)@meeting = meeting- @content_type = content_typeend- 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)endprivate- def send_notifications!(content, action, include_author:)+ def send_notifications!(action, include_author:)author_mail = meeting.author.mailrecipients_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_laterrescue StandardError => eRails.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.erbsimilarity index 89%rename from modules/meeting/app/views/meeting_mailer/content_for_review.html.erbrename to modules/meeting/app/views/meeting_mailer/invited.html.erbindex 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.erbsimilarity index 91%rename from modules/meeting/app/views/meeting_mailer/content_for_review.text.erbrename to modules/meeting/app/views/meeting_mailer/invited.text.erbindex 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.ymlindex 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.rbindex 6875ffe50d7..e28a792f98e 100644--- a/modules/meeting/config/routes.rb+++ b/modules/meeting/config/routes.rb@@ -53,6 +53,7 @@ OpenProject::Application.routes.draw doput :update_detailsput :update_participantsput :change_state+ post :notifyendresources :agenda_items, controller: 'meeting_agenda_items' docollection dodiff --git a/modules/meeting/lib/open_project/meeting/engine.rb b/modules/meeting/lib/open_project/meeting/engine.rbindex 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::Meetingpermissible_on: :project,require: :memberpermission :send_meeting_agendas_notification,- { meeting_agendas: [:notify] },+ {+ meetings: [:notify],+ meeting_agendas: [:notify]+ },permissible_on: :project,require: :memberpermission :send_meeting_agendas_icalendar,