Skip to content

Commit

Permalink
Use UpdateService to make use of send_notifcations
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverguenther committed Jul 30, 2024
1 parent 6ec3ab6 commit f5573e5
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 22 deletions.
10 changes: 6 additions & 4 deletions modules/meeting/app/controllers/meetings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,15 @@ def cancel_edit
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
Expand Down
2 changes: 1 addition & 1 deletion modules/meeting/app/models/meeting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def add_new_participants_as_watcher
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def set_default_attributes(_params)
end

def set_participants(participants_attributes)
model.participants.clear
model.participants.clear if model.new_record?
model.participants_attributes = participants_attributes
end
end
Expand Down
23 changes: 10 additions & 13 deletions modules/meeting/app/views/meetings/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 1 addition & 1 deletion modules/meeting/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
54 changes: 52 additions & 2 deletions modules/meeting/spec/requests/meetings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@
: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

Expand All @@ -49,6 +50,55 @@
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
{
Expand Down

0 comments on commit f5573e5

Please sign in to comment.