diff --git a/modules/meeting/app/controllers/meetings_controller.rb b/modules/meeting/app/controllers/meetings_controller.rb index 61cd650816b..847fdd190ae 100644 --- a/modules/meeting/app/controllers/meetings_controller.rb +++ b/modules/meeting/app/controllers/meetings_controller.rb @@ -151,13 +151,15 @@ class MeetingsController < ApplicationController end def update - @meeting.participants_attributes = @converted_params.delete(:participants_attributes) - @converted_params.delete(:send_notifications) - @meeting.attributes = @converted_params - if @meeting.save + call = ::Meetings::UpdateService + .new(user: current_user, model: @meeting) + .call(@converted_params) + + if call.success? flash[:notice] = I18n.t(:notice_successful_update) redirect_to action: "show", id: @meeting else + @meeting = call.result render action: "edit" end end diff --git a/modules/meeting/app/models/meeting.rb b/modules/meeting/app/models/meeting.rb index 9116281ae33..66a3a683fc2 100644 --- a/modules/meeting/app/models/meeting.rb +++ b/modules/meeting/app/models/meeting.rb @@ -317,7 +317,7 @@ class Meeting < ApplicationRecord end def send_participant_added_mail(participant) - if persisted? + if persisted? && Journal::NotificationConfiguration.active? MeetingMailer.invited(self, participant.user, User.current).deliver_later end end diff --git a/modules/meeting/app/services/meetings/set_attributes_service.rb b/modules/meeting/app/services/meetings/set_attributes_service.rb index 7d107b9c36c..4473a6776b4 100644 --- a/modules/meeting/app/services/meetings/set_attributes_service.rb +++ b/modules/meeting/app/services/meetings/set_attributes_service.rb @@ -43,7 +43,7 @@ module Meetings end def set_participants(participants_attributes) - model.participants.clear + model.participants.clear if model.new_record? model.participants_attributes = participants_attributes end end diff --git a/modules/meeting/app/views/meetings/_form.html.erb b/modules/meeting/app/views/meetings/_form.html.erb index 45230408792..ed8dab007fb 100644 --- a/modules/meeting/app/views/meetings/_form.html.erb +++ b/modules/meeting/app/views/meetings/_form.html.erb @@ -192,18 +192,15 @@ See COPYRIGHT and LICENSE files for more details. <%= render partial: 'meetings/participants_section' %> - <% if @meeting.new_record? || copy_from.present? %> -
- <%= styled_label_tag 'send_notfications', t(:"meeting.email.send_emails") %> -
- <%= styled_check_box_tag 'send_notifications', - 1, - true %> -
-
- <%= t(:"meeting.email.send_invitation_emails") %> -
+
+ <%= styled_label_tag 'send_notfications', t(:"meeting.email.send_emails") %> +
+ <%= styled_check_box_tag 'send_notifications', + 1, + true %>
- <% end %> - +
+ <%= t(:"meeting.email.send_invitation_emails") %> +
+
diff --git a/modules/meeting/config/locales/en.yml b/modules/meeting/config/locales/en.yml index 5a8a0ed125b..8ea3f9d6249 100644 --- a/modules/meeting/config/locales/en.yml +++ b/modules/meeting/config/locales/en.yml @@ -139,7 +139,7 @@ en: agenda_text: "Copy the agenda of the old meeting" email: send_emails: "Send emails" - send_invitation_emails: "Send out invitation emails upon creation" + send_invitation_emails: "Send out invitation emails for all participants." open_meeting_link: "Open meeting" invited: summary: "%{actor} has sent you an invitation for the meeting %{title}" diff --git a/modules/meeting/spec/requests/meetings_spec.rb b/modules/meeting/spec/requests/meetings_spec.rb index 5fce07427a0..07faa0e87b7 100644 --- a/modules/meeting/spec/requests/meetings_spec.rb +++ b/modules/meeting/spec/requests/meetings_spec.rb @@ -32,10 +32,11 @@ RSpec.describe "Meeting requests", :skip_csrf, type: :rails_request do shared_let(:project) { create(:project, enabled_module_names: %i[meetings]) } - shared_let(:user) { create(:user, member_with_permissions: { project => %i[view_meetings create_meetings] }) } - shared_let(:meeting) { create(:structured_meeting, project:) } + shared_let(:user) { create(:user, member_with_permissions: { project => %i[view_meetings create_meetings edit_meetings] }) } + shared_let(:meeting) { create(:structured_meeting, project:, author: user) } before do + meeting.participants.delete_all login_as user end @@ -49,6 +50,55 @@ RSpec.describe "Meeting requests", end end + describe "update with a new particpant" do + let(:other_user) { create(:user, member_with_permissions: { project => %i[view_meetings] }) } + let(:params) do + { + send_notifications:, + title: "Updated meeting", + meeting: { + participants_attributes: [ + { user_id: user.id, invited: true }, + { user_id: other_user.id, invited: true } + ] + } + + } + end + + subject do + meeting.reload + end + + context "with send_notifications" do + let(:send_notifications) { "1" } + + it "sends an invitation mail to the invited users" do + patch(meeting_path(meeting), params:) + + expect(subject.participants.count).to eq(2) + + perform_enqueued_jobs + + expect(ActionMailer::Base.deliveries.size).to eq(2) + end + end + + context "with send_notifications false" do + let(:send_notifications) { "0" } + + it "sends an invitation mail to the invited users" do + patch(meeting_path(meeting), params:) + + expect(subject.participants.count).to eq(2) + + perform_enqueued_jobs + + expect(ActionMailer::Base.deliveries.size).to eq(0) + end + end + end + describe "copy" do let(:base_params) do {