Skip to content

Commit

Permalink
Merge pull request #15500 from opf/feature/notify-on-meeting-creation
Browse files Browse the repository at this point in the history
 [#54469] Allow sending notifications for invited users
  • Loading branch information
mrmir authored May 22, 2024
2 parents bb757ed + bacdbaa commit 1e80d6d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
2 changes: 2 additions & 0 deletions modules/meeting/app/controllers/meetings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def cancel_edit

def update
@meeting.participants_attributes = @converted_params.delete(:participants_attributes)
@converted_params.delete(:send_notifications)
@meeting.attributes = @converted_params
if @meeting.save
flash[:notice] = I18n.t(:notice_successful_update)
Expand Down Expand Up @@ -315,6 +316,7 @@ def convert_params
# Force defaults on participants
@converted_params[:participants_attributes] ||= {}
@converted_params[:participants_attributes].each { |p| p.reverse_merge! attended: false, invited: false }
@converted_params[:send_notifications] = params[:send_notifications] == "1"
end

def meeting_params
Expand Down
14 changes: 14 additions & 0 deletions modules/meeting/app/services/meetings/create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,19 @@ def instance(params)
Meeting.new
end
end

def after_perform(call)
if call.success? && Journal::NotificationConfiguration.active?
meeting = call.result

meeting.participants.where(invited: true).each do |participant|
MeetingMailer
.invited(meeting, participant.user, User.current)
.deliver_later
end
end

call
end
end
end
15 changes: 15 additions & 0 deletions modules/meeting/app/views/meetings/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,19 @@ See COPYRIGHT and LICENSE files for more details.
</div>

<%= 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>
<% end %>

</section>
2 changes: 2 additions & 0 deletions modules/meeting/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ en:
agenda: "Copy agenda"
agenda_text: "Copy the agenda of the old meeting"
email:
send_emails: "Send emails"
send_invitation_emails: "Send out invitation emails upon creation"
open_meeting_link: "Open meeting"
invited:
summary: "%{actor} has sent you an invitation for the meeting %{title}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@
let(:meeting) { StructuredMeeting.order(id: :asc).last }
let(:show_page) { Pages::StructuredMeeting::Show.new(meeting) }

before do
before do |test|
login_as current_user
new_page.visit!
expect(page).to have_current_path(new_page.path)
expect(page).to have_current_path(new_page.path) # rubocop:disable RSpec/ExpectInHook
new_page.set_title "Some title"
new_page.set_type "Dynamic"

Expand All @@ -77,12 +77,21 @@
new_page.set_duration "1.5"
new_page.invite(other_user)

if test.metadata[:unchecked]
expect(page).to have_checked_field "send_notifications" # rubocop:disable RSpec/ExpectInHook
uncheck "send_notifications"
end

new_page.click_create
end

it "can create a structured meeting and add agenda items" do
show_page.expect_toast(message: "Successful creation")

# Can send invitation mails by default
perform_enqueued_jobs
expect(ActionMailer::Base.deliveries.size).to eq 2

# Can add and edit a single item
show_page.add_agenda_item do
fill_in "Title", with: "My agenda item"
Expand Down Expand Up @@ -312,6 +321,11 @@
end
end

it "does not send emails on creation when 'Send emails' is unchecked", :unchecked do
perform_enqueued_jobs
expect(ActionMailer::Base.deliveries.size).to eq 0
end

context "with sections" do
let!(:meeting) { create(:structured_meeting, project:, author: current_user) }
let(:show_page) { Pages::StructuredMeeting::Show.new(meeting) }
Expand Down

0 comments on commit 1e80d6d

Please sign in to comment.