Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jw email bug fixes #42

Merged
merged 5 commits into from
Jan 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/controllers/service_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,10 @@ def remove_service

if ssr.line_items.empty?
if !ssr.submitted_at.nil?
# only notify service providers of destroyed ssr
NotifierLogic.new(@service_request, nil, current_user).send_ssr_service_provider_notifications(ssr, ssr_destroyed: true, request_amendment: false)
# notify service providers and admin of a destroyed ssr upon deletion of ssr
notifier_logic = NotifierLogic.new(@service_request, nil, current_user)
notifier_logic.send_ssr_service_provider_notifications(ssr, ssr_destroyed: true, request_amendment: false)
notifier_logic.send_admin_notifications([ssr], request_amendment: false, ssr_destroyed: true)
end
ssr.destroy
end
Expand Down
18 changes: 14 additions & 4 deletions app/mailers/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,17 @@ def notify_user(project_role, service_request, xls, approval, user_current, audi
mail(:to => email, :from => NO_REPLY_FROM, :subject => subject)
end

def notify_admin(submission_email_address, xls, user_current, ssr, audit_report=nil)
def notify_admin(submission_email_address, xls, user_current, ssr, audit_report=nil, ssr_destroyed=false)
@ssr_deleted = false
@notes = ssr.service_request.notes

@status = audit_report.present? ? 'request_amendment' : ssr.service_request.status
if ssr_destroyed
@status = 'ssr_destroyed'
elsif audit_report.present?
@status = 'request_amendment'
else
@status = ssr.service_request.status
end

@role = 'none'
@full_name = submission_email_address
Expand All @@ -77,7 +83,10 @@ def notify_admin(submission_email_address, xls, user_current, ssr, audit_report=
@portal_text = "Administrators/Service Providers, Click Here"

@audit_report = audit_report
attachments["service_request_#{@service_request.protocol.id}.xlsx"] = xls

if !ssr_destroyed
attachments["service_request_#{@service_request.protocol.id}.xlsx"] = xls
end

email = submission_email_address
subject = "#{@protocol.id} - #{t(:mailer)[:application_title]} service request"
Expand Down Expand Up @@ -109,7 +118,8 @@ def notify_service_provider(service_provider, service_request, attachments_to_ad
@portal_text = "Administrators/Service Providers, Click Here"

# only display the ssrs that are associated with service_provider
@ssrs_to_be_displayed = @service_request.ssrs_to_be_displayed_in_email(service_provider, @audit_report, ssr_destroyed, ssr_id)
ssr = SubServiceRequest.find(ssr_id)
@ssrs_to_be_displayed = [ssr] if service_provider.identity.is_service_provider?(ssr)

if !ssr_destroyed
attachments_to_add.each do |file_name, document|
Expand Down
20 changes: 0 additions & 20 deletions app/models/service_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -543,26 +543,6 @@ def cart_sub_service_requests
{ active: active, complete: complete }
end

def ssrs_associated_with_service_provider(service_provider)
ssrs_to_be_displayed = []
self.sub_service_requests.each do |ssr|
if service_provider.identity.is_service_provider?(ssr)
ssrs_to_be_displayed << ssr
end
end
ssrs_to_be_displayed
end

def ssrs_to_be_displayed_in_email(service_provider, audit_report, ssr_destroyed, ssr_id)
if ssr_destroyed
ssr = SubServiceRequest.find(ssr_id)
ssrs_to_be_displayed = [ssr] if service_provider.identity.is_service_provider?(ssr)
else
ssrs_to_be_displayed = self.ssrs_associated_with_service_provider(service_provider)
end
ssrs_to_be_displayed
end

private

def set_original_submitted_date
Expand Down
2 changes: 1 addition & 1 deletion app/views/notifier/_srid_information.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
- else
%td.skinny-black-border.center= ssr.display_id
%td.skinny-black-border.center= ssr.org_tree_display
%td.skinny-black-border.center= AVAILABLE_STATUSES[ssr.status]
%td.skinny-black-border.center= AVAILABLE_STATUSES[ssr.reload.status]
%br
%br
41 changes: 20 additions & 21 deletions lib/notifier_logic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,30 @@ def send_ssr_service_provider_notifications(sub_service_request, ssr_destroyed:
end
end

def send_admin_notifications(sub_service_requests, request_amendment: false, ssr_destroyed: false)
# Iterates through each SSR to find the correct admin email.
# Passes the correct SSR to display in the attachment and email.
sub_service_requests.each do |sub_service_request|
audit_report = request_amendment ? sub_service_request.audit_report(@current_user, sub_service_request.service_request.previous_submitted_at.utc, Time.now.utc) : nil
sub_service_request.organization.submission_emails_lookup.each do |submission_email|
service_list_false = sub_service_request.service_request.service_list(false, nil, sub_service_request)
service_list_true = sub_service_request.service_request.service_list(true, nil, sub_service_request)
line_items = sub_service_request.line_items
protocol = @service_request.protocol
controller = set_instance_variables(@current_user, @service_request, service_list_false, service_list_true, line_items, protocol)
xls = controller.render_to_string action: 'show', formats: [:xlsx]
Notifier.notify_admin(submission_email.email, xls, @current_user, sub_service_request, audit_report, ssr_destroyed).deliver
end
end
end

private
def send_notifications(sub_service_requests)
# If user has added a new service related to a new ssr and edited an existing ssr,
# we only want to send a request amendment email and not an initial submit email
send_user_notifications(request_amendment: false) unless @send_request_amendment_and_not_initial
send_admin_notifications(sub_service_requests, request_amendment: false)
send_service_provider_notifications(sub_service_requests, request_amendment: false)
send_admin_notifications(sub_service_requests, request_amendment: false)
send_service_provider_notifications(sub_service_requests, request_amendment: false)
end

def send_user_notifications(request_amendment: false)
Expand Down Expand Up @@ -152,25 +169,7 @@ def send_user_notifications(request_amendment: false)
end
end

def send_admin_notifications(sub_service_requests, request_amendment: false)
# Iterates through each SSR to find the correct admin email.
# Passes the correct SSR to display in the attachment and email.
sub_service_requests.each do |sub_service_request|

audit_report = request_amendment ? sub_service_request.audit_report(@current_user, sub_service_request.service_request.previous_submitted_at.utc, Time.now.utc) : nil
sub_service_request.organization.submission_emails_lookup.each do |submission_email|
service_list_false = sub_service_request.service_request.service_list(false, nil, sub_service_request)
service_list_true = sub_service_request.service_request.service_list(true, nil, sub_service_request)
line_items = sub_service_request.line_items
protocol = @service_request.protocol
controller = set_instance_variables(@current_user, @service_request, service_list_false, service_list_true, line_items, protocol)
xls = controller.render_to_string action: 'show', formats: [:xlsx]
Notifier.notify_admin(submission_email.email, xls, @current_user, sub_service_request, audit_report).deliver
end
end
end

def send_service_provider_notifications(sub_service_requests, request_amendment: false) #all sub-service requests on service request
def send_service_provider_notifications(sub_service_requests, request_amendment: false)
sub_service_requests.each do |sub_service_request|
send_ssr_service_provider_notifications(sub_service_request, ssr_destroyed: false, request_amendment: request_amendment)
end
Expand Down
41 changes: 0 additions & 41 deletions spec/models/service_request/ssrs_to_be_displayed_in_email_spec.rb

This file was deleted.

21 changes: 0 additions & 21 deletions spec/models/service_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,27 +289,6 @@
end
end

describe 'ssrs_associated_with_service_provider' do
context 'service_provider is associated with sub_service_requests' do

it 'should return all ssrs associated with the service_provider' do
expect(service_request.ssrs_associated_with_service_provider(service_provider)).to eq(service_request.sub_service_requests)
end
end

context 'service_provider is not associated with sub_service_requests' do

before :each do
identity = create(:identity)
@service_provider2 = create(:service_provider, identity_id: identity.id)
end

it 'should return empty array' do
expect(service_request.ssrs_associated_with_service_provider(@service_provider2)).to eq([])
end
end
end

describe '#additional_detail_services' do
it 'should select the services that have additional details' do
service_request = create(:service_request_without_validations)
Expand Down
4 changes: 2 additions & 2 deletions spec/support/emails/tables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def assert_email_user_information_when_not_selected_for_epic(mail_response)
end

def assert_email_srid_information_for_service_provider
ssrs_to_be_displayed = service_request.ssrs_associated_with_service_provider(service_provider)
ssrs_to_be_displayed = [service_request.protocol.sub_service_requests.first]
# Expect table to show only SSR's (hyper-link) that are associated with service provider
expect(mail.body).to have_xpath "//table//strong[text()='Service Request Information']"
expect(mail.body).to have_xpath "//th[text()='SRID']/following-sibling::th[text()='Organization']/following-sibling::th[text()='Status']"
Expand All @@ -89,7 +89,7 @@ def assert_email_srid_information_for_service_provider
end

def assert_email_deleted_srid_information_for_service_provider
ssrs_to_be_displayed = service_request.ssrs_associated_with_service_provider(service_provider)
ssrs_to_be_displayed = [service_request.protocol.sub_service_requests.first]
expect(mail.body).to have_xpath "//table//strong[text()='Service Request Information']"
expect(mail.body).to have_xpath "//th[text()='SRID']/following-sibling::th[text()='Organization']"
ssrs_to_be_displayed.each do |ssr_to_be_displayed|
Expand Down