Use UpdateService to make use of send_notifcations

This commit is contained in:
Oliver Günther
2024-07-29 13:57:46 +02:00
parent 6ec3ab692a
commit f5573e5d69
6 changed files with 71 additions and 22 deletions
@@ -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
+1 -1
View File
@@ -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
@@ -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
@@ -192,18 +192,15 @@ See COPYRIGHT and LICENSE files for more details.
<%= render partial: 'meetings/participants_section' %>
<% if @meeting.new_record? || copy_from.present? %>
<div class="form--field">
<%= styled_label_tag 'send_notfications', t(:"meeting.email.send_emails") %>
<div class="form--field-container">
<%= styled_check_box_tag 'send_notifications',
1,
true %>
</div>
<div class="form--field-instructions">
<%= t(:"meeting.email.send_invitation_emails") %>
</div>
<div class="form--field">
<%= styled_label_tag 'send_notfications', t(:"meeting.email.send_emails") %>
<div class="form--field-container">
<%= styled_check_box_tag 'send_notifications',
1,
true %>
</div>
<% end %>
<div class="form--field-instructions">
<%= t(:"meeting.email.send_invitation_emails") %>
</div>
</div>
</section>
+1 -1
View File
@@ -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}"
+52 -2
View File
@@ -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
{