[29485] Add author to icalendar notification

https://community.openproject.com/wp/29485

[ci skip]
pull/7041/head
Oliver Günther 6 years ago
parent c300dfe963
commit 16ede2c200
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 2
      modules/meeting/app/controllers/meeting_contents_controller.rb
  2. 8
      modules/meeting/app/services/meeting_notification_service.rb
  3. 63
      modules/meeting/spec/controllers/meeting_contents_controller_spec.rb

@ -98,7 +98,7 @@ class MeetingContentsController < ApplicationController
def icalendar
unless @content.new_record?
service = MeetingNotificationService.new(@meeting, @content_type)
result = service.call(@content, :icalendar_notification)
result = service.call(@content, :icalendar_notification, include_author: true)
if result.success?
flash[:notice] = l(:notice_successful_notification)

@ -7,16 +7,16 @@ class MeetingNotificationService
@content_type = content_type
end
def call(content, action)
recipients_with_errors = send_notifications!(content, action)
def call(content, action, include_author: false)
recipients_with_errors = send_notifications!(content, action, include_author: include_author)
ServiceResult.new(success: recipients_with_errors.empty?, errors: recipients_with_errors)
end
private
def send_notifications!(content, action)
def send_notifications!(content, action, include_author:)
author_mail = meeting.author.mail
do_not_notify_author = meeting.author.pref[:no_self_notified]
do_not_notify_author = meeting.author.pref[:no_self_notified] && !include_author
recipients_with_errors = []
meeting.participants.each do |recipient|

@ -21,13 +21,13 @@
require 'spec_helper'
describe MeetingContentsController do
let(:role) { FactoryBot.create(:role, permissions: [:view_meetings]) }
let(:project) { FactoryBot.create(:project) }
let(:author) { FactoryBot.create(:user, member_in_project: project, member_through_role: role) }
let(:watcher1) { FactoryBot.create(:user, member_in_project: project, member_through_role: role) }
let(:watcher2) { FactoryBot.create(:user, member_in_project: project, member_through_role: role) }
let(:meeting) { FactoryBot.create(:meeting, author: author, project: project) }
let(:meeting_agenda) do
shared_let(:role) { FactoryBot.create(:role, permissions: [:view_meetings]) }
shared_let(:project) { FactoryBot.create(:project) }
shared_let(:author) { FactoryBot.create(:user, member_in_project: project, member_through_role: role) }
shared_let(:watcher1) { FactoryBot.create(:user, member_in_project: project, member_through_role: role) }
shared_let(:watcher2) { FactoryBot.create(:user, member_in_project: project, member_through_role: role) }
shared_let(:meeting) { FactoryBot.create(:meeting, author: author, project: project) }
shared_let(:meeting_agenda) do
FactoryBot.create(:meeting_agenda, meeting: meeting)
end
@ -43,13 +43,15 @@ describe MeetingContentsController do
end
shared_examples_for 'delivered by mail' do
before { put 'notify', params: { meeting_id: meeting.id } }
before { put action, params: { meeting_id: meeting.id } }
it { expect(ActionMailer::Base.deliveries.count).to eql(mail_count) }
end
describe 'PUT' do
describe 'notify' do
let(:action) { 'notify' }
context 'when author no_self_notified property is true' do
before do
author.pref[:no_self_notified] = true
@ -91,5 +93,50 @@ describe MeetingContentsController do
end
end
end
describe 'icalendar' do
let(:action) { 'icalendar' }
context 'when author no_self_notified property is true' do
before do
author.pref[:no_self_notified] = true
author.save!
end
it_behaves_like 'delivered by mail' do
let(:mail_count) { 3 }
end
end
context 'when author no_self_notified property is false' do
before do
author.pref[:no_self_notified] = false
author.save!
end
it_behaves_like 'delivered by mail' do
let(:mail_count) { 3 }
end
end
context 'with an error during deliver' do
before do
author.pref[:no_self_notified] = false
author.save!
allow(MeetingMailer).to receive(:content_for_review).and_raise(Net::SMTPError)
end
it 'does not raise an error' do
expect { put 'notify', params: { meeting_id: meeting.id } }.to_not raise_error
end
it 'produces a flash message containing the mail addresses raising the error' do
put 'notify', params: { meeting_id: meeting.id }
meeting.participants.each do |participant|
expect(flash[:error]).to include(participant.name)
end
end
end
end
end
end

Loading…
Cancel
Save