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 delete services email fix #711

Merged
merged 7 commits into from
Oct 24, 2016
Merged
Show file tree
Hide file tree
Changes from 6 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
17 changes: 9 additions & 8 deletions app/controllers/service_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -433,14 +433,14 @@ def remove_service

# clean up sub_service_requests
@service_request.reload

@service_request.previous_submitted_at = @service_request.submitted_at
@protocol = @service_request.protocol

if ssr.line_items.empty?
ssr.destroy
if !ssr.submitted_at.nil?
send_ssr_service_provider_notifications(@service_request, ssr, true)
end
ssr.destroy
end

@service_request.reload
Expand Down Expand Up @@ -544,12 +544,13 @@ def send_admin_notifications(service_request, sub_service_requests)
end
end

def send_ssr_service_provider_notifications(service_request, sub_service_request, all_ssrs_deleted=false) #single sub-service request
def send_ssr_service_provider_notifications(service_request, sub_service_request, ssr_destroyed=false) #single sub-service request

previously_submitted_at = service_request.previous_submitted_at.nil? ? Time.now.utc : service_request.previous_submitted_at.utc
audit_report = sub_service_request.audit_report(current_user, previously_submitted_at, Time.now.utc)

sub_service_request.organization.service_providers.where("(`service_providers`.`hold_emails` != 1 OR `service_providers`.`hold_emails` IS NULL)").each do |service_provider|
send_individual_service_provider_notification(service_request, sub_service_request, service_provider, audit_report, all_ssrs_deleted) end
send_individual_service_provider_notification(service_request, sub_service_request, service_provider, audit_report, ssr_destroyed) end
end

def ssr_has_changed?(service_request, sub_service_request) #specific ssr has changed?
Expand All @@ -569,7 +570,7 @@ def service_request_has_changed_ssr?(service_request) #any ssr on sr has changed
return false
end

def send_individual_service_provider_notification(service_request, sub_service_request, service_provider, audit_report=nil, all_ssrs_deleted=false)
def send_individual_service_provider_notification(service_request, sub_service_request, service_provider, audit_report=nil, ssr_destroyed=false)
attachments = {}
@service_list_true = @service_request.service_list(true, service_provider)
@service_list_false = @service_request.service_list(false, service_provider)
Expand All @@ -592,12 +593,12 @@ def send_individual_service_provider_notification(service_request, sub_service_r
request_for_grant_billing_form = RequestGrantBillingPdf.generate_pdf service_request
attachments["request_for_grant_billing_#{service_request.id}.pdf"] = request_for_grant_billing_form
end

if audit_report.nil?
previously_submitted_at = service_request.previous_submitted_at.nil? ? Time.now.utc : service_request.previous_submitted_at.utc
audit_report = sub_service_request.audit_report(current_user, previously_submitted_at, Time.now.utc)
end
Notifier.notify_service_provider(service_provider, service_request, attachments, current_user, audit_report, all_ssrs_deleted).deliver_now
ssr_id = sub_service_request.id
Notifier.notify_service_provider(service_provider, service_request, attachments, current_user, ssr_id, audit_report, ssr_destroyed).deliver_now
end

def send_epic_notification_for_user_approval(protocol)
Expand Down
10 changes: 5 additions & 5 deletions app/mailers/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ def notify_admin(service_request, submission_email_address, xls, user_current, s
mail(:to => email, :from => NO_REPLY_FROM, :subject => subject)
end

def notify_service_provider(service_provider, service_request, attachments_to_add, user_current, audit_report=nil, all_ssrs_deleted=false)
def notify_service_provider(service_provider, service_request, attachments_to_add, user_current, ssr_id, audit_report=nil, ssr_destroyed=false)
@notes = service_request.notes

if all_ssrs_deleted
@status = 'all_ssrs_deleted'
if ssr_destroyed
@status = 'ssr_destroyed'
else
@status = service_request.status
end
Expand All @@ -111,9 +111,9 @@ 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_associated_with_service_provider(service_provider)
@ssrs_to_be_displayed = @service_request.ssrs_to_be_displayed_in_email(service_provider, @audit_report, ssr_destroyed, ssr_id)

if !all_ssrs_deleted
if !ssr_destroyed
attachments_to_add.each do |file_name, document|
next if document.nil?
attachments["#{file_name}"] = document
Expand Down
10 changes: 10 additions & 0 deletions app/models/service_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,16 @@ def ssrs_associated_with_service_provider (service_provider)
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
return ssrs_to_be_displayed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to explicitly 'return' here on line 618, I think you could just say the variable name.

end

private

def set_original_submitted_date
Expand Down
8 changes: 4 additions & 4 deletions app/views/notifier/_notification_email.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
%body
/***** EMAIL INTRO *****
- case @status
- when 'all_ssrs_deleted'
- when 'ssr_destroyed'
= render "deleted_all_services_from_cart"
- when 'get_a_cost_estimate'
= render "welcome"
Expand All @@ -47,20 +47,20 @@
= render "user_information"

- if @ssrs_to_be_displayed
- if @status == 'all_ssrs_deleted'
- if @status == 'ssr_destroyed'
= render "deleted_srid_information"
- else
= render "srid_information"

- if @status != 'all_ssrs_deleted' && @audit_report.present? && @audit_report[:line_items].present?
- if @status != 'ssr_destroyed' && @audit_report.present? && @audit_report[:line_items].present?
= render "audit_action"
/***** END EMAIL TABLES *****

/***** OTHER EMAIL TIDBITS *****
- if @status == "submitted" && @role == 'none' && !@notes.empty?
%p= t(:notifier)[:notes_present]

- if @status != 'all_ssrs_deleted'
- if @status != 'ssr_destroyed'
%p= t(:notifier)[:body6]

%p= t(:issue_contact)
Expand Down
50 changes: 17 additions & 33 deletions spec/mailers/notifier/deleted_all_services_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,54 +25,38 @@
let_there_be_lane
let_there_be_j
fake_login_for_each_test
build_service_request_with_project
build_service_request_with_study

let(:service3) { create(:service,
organization_id: program.id,
name: 'ABCD',
one_time_fee: true) }
let(:pricing_setup) { create(:pricing_setup,
organization_id: program.id,
display_date: Time.now - 1.day,
federal: 50,
corporate: 50,
other: 50,
member: 50,
college_rate_type: 'federal',
federal_rate_type: 'federal',
industry_rate_type: 'federal',
investigator_rate_type: 'federal',
internal_rate_type: 'federal',
foundation_rate_type: 'federal') }
let(:pricing_map) { create(:pricing_map,
unit_minimum: 1,
unit_factor: 1,
service: service3,
quantity_type: 'Each',
quantity_minimum: 5,
otf_unit_type: 'Week',
display_date: Time.now - 1.day,
full_rate: 2000,
units_per_qty_max: 20) }
let(:identity) { Identity.first }
let(:organization) { Organization.first }
let(:non_service_provider_org) { create(:organization, name: 'BLAH', process_ssrs: 0, is_available: 1) }
let(:service_provider) { create(:service_provider,
identity: identity,
organization: organization,
service: service3) }
let!(:non_service_provider_ssr) { create(:sub_service_request, ssr_id: "0004", status: "submitted", service_request_id: service_request.id, organization_id: non_service_provider_org.id, org_tree_display: "SCTR1/BLAH")}

let(:previously_submitted_at) { service_request.submitted_at.nil? ? Time.now.utc : service_request.submitted_at.utc }
let(:audit) { sub_service_request.audit_report(identity,
previously_submitted_at,
Time.now.utc) }

before { add_visits }

# SUBMITTED
before do
service_request.update_attribute(:status, "submitted")
before :each do
service_request.update_attribute(:submitted_at, Time.now.yesterday)
service_request.sub_service_requests.each do |ssr|
ssr.update_attribute(:submitted_at, Time.now.yesterday)
ssr.update_attribute(:status, 'submitted')
li_id = ssr.line_items.first.id
ssr.line_items.first.destroy!
ssr.save!
service_request.reload
@audit = AuditRecovery.where("auditable_id = '#{li_id}' AND auditable_type = 'LineItem' AND action = 'destroy'")
end

@audit.first.update_attribute(:created_at, Time.now - 5.hours)
@audit.first.update_attribute(:user_id, identity.id)
@report = service_request.sub_service_requests.first.audit_report(identity, Time.now.yesterday - 4.hours, Time.now.tomorrow)
end

context 'service_provider' do
Expand All @@ -81,7 +65,7 @@
service_request,
xls,
identity,
audit, true) }
@report, true, service_request.sub_service_requests.first) }
# Expected service provider message is defined under deleted_all_services_intro_for_service_providers
it 'should display service provider intro message, conclusion, link, and should not display acknowledgments' do
deleted_all_services_intro_for_service_providers(mail)
Expand Down
1 change: 1 addition & 0 deletions spec/mailers/notifier/get_a_cost_estimate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
service_request,
xls,
identity,
service_request.sub_service_requests.first,
audit) }
# Expected service provider message is defined under get_a_cost_estimate_service_provider_admin_message
it 'should display service_provider intro message, link, conclusion, and should not display acknowledgments' do
Expand Down
2 changes: 2 additions & 0 deletions spec/mailers/notifier/submitted_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
service_request,
xls,
identity,
service_request.protocol.sub_service_requests.first,
audit) }

# Expected service provider message is defined under submitted_service_provider_and_admin_message
Expand Down Expand Up @@ -208,6 +209,7 @@
service_request,
xls,
identity,
service_request.protocol.sub_service_requests.first,
audit) }
# Expected service provider message is defined under submitted_service_provider_and_admin_message
it 'should display admin intro message, conclusion, link, and should not display acknowledgments' do
Expand Down
41 changes: 41 additions & 0 deletions spec/models/service_request/ssrs_to_be_displayed_in_email_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright © 2011-2016 MUSC Foundation for Research Development~
# All rights reserved.~

# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:~

# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.~

# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following~
# disclaimer in the documentation and/or other materials provided with the distribution.~

# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products~
# derived from this software without specific prior written permission.~

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,~
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT~
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL~
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS~
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR~
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.~
require 'rails_helper'

RSpec.describe ServiceRequest, type: :model do
let_there_be_lane
let_there_be_j
build_service_request_with_study

describe "#ssrs_to_be_displayed_in_email" do

context "ssr_deleted == true" do
it "should return the ssr with deleted line_item" do
expect(service_request.ssrs_to_be_displayed_in_email(service_provider, @report, true, service_request.sub_service_requests.first.id)).to eq([service_request.sub_service_requests.first])
end
end

context "ssr_deleted == false" do
it "should return all ssrs belonging to service_provider" do
expect(service_request.ssrs_to_be_displayed_in_email(service_provider, @report, false, service_request.sub_service_requests)).to eq(service_request.sub_service_requests)
end
end
end
end
2 changes: 1 addition & 1 deletion spec/support/emails/messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def deleted_all_services_intro_for_service_providers(mail_response)
# Expected message:
# 'All services have been deleted in SPARCRequest for the Study
# below to which you have been granted access.'
expect(mail_response).to have_xpath("//p[normalize-space(text()) = 'All services have been deleted in SPARCRequest for the Project below to which you have been granted access.']")
expect(mail_response).to have_xpath("//p[normalize-space(text()) = 'All services have been deleted in SPARCRequest for the #{service_request.protocol.type} below to which you have been granted access.']")
expect(mail_response).not_to have_xpath("//p[normalize-space(text()) = 'A list of requested services is attached.']")
expect(mail_response).to have_xpath("//p[normalize-space(text()) = 'Please contact the SUCCESS Center at (843) 792-8300 or success@musc.edu for assistance with this process or with any questions you may have.']")
end
Expand Down
6 changes: 3 additions & 3 deletions spec/support/emails/tables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ module EmailHelpers

def assert_email_project_information(mail_response)
#assert correct protocol information is included in notification email
expect(mail_response).to have_xpath "//table//strong[text()='Project Information']"
expect(mail_response).to have_xpath "//th[text()='Project ID']/following-sibling::td[text()='#{service_request.protocol.id}']"
expect(mail_response).to have_xpath "//table//strong[text()='#{service_request.protocol.type} Information']"
expect(mail_response).to have_xpath "//th[text()='#{service_request.protocol.type} ID']/following-sibling::td[text()='#{service_request.protocol.id}']"
expect(mail_response).to have_xpath "//th[text()='Short Title']/following-sibling::td[text()='#{service_request.protocol.short_title}']"
expect(mail_response).to have_xpath "//th[text()='Project Title']/following-sibling::td[text()='#{service_request.protocol.title}']"
expect(mail_response).to have_xpath "//th[text()='#{service_request.protocol.type} Title']/following-sibling::td[text()='#{service_request.protocol.title}']"
expect(mail_response).to have_xpath "//th[text()='Sponsor Name']/following-sibling::td[text()='#{service_request.protocol.sponsor_name}']"
expect(mail_response).to have_xpath "//th[text()='Funding Source']/following-sibling::td[text()='#{service_request.protocol.funding_source.capitalize}']"
end
Expand Down