Skip to content

Commit

Permalink
JM - (SPARCRequest) Make the System-generated Email Titles more Infor…
Browse files Browse the repository at this point in the history
  • Loading branch information
jwiel86 committed Aug 17, 2017
1 parent c085dcb commit 3b30580
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 24 deletions.
38 changes: 29 additions & 9 deletions app/mailers/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ def new_identity_waiting_for_approval identity
email = ADMIN_MAIL_TO
cc = NEW_USER_CC

##REVIEW: This subject appears incorrect? Copy paste from previous method?
subject = "New Question from #{t(:mailer)[:application_title]}"

subject = t(:mailer)[:email_title][:new_account_registration]
mail(:to => email, :cc => cc, :from => @identity.email, :subject => subject)
end

Expand Down Expand Up @@ -68,7 +66,7 @@ def notify_user(project_role, service_request, ssr, approval, user_current, audi

# only send these to the correct person in the production env
email = @identity.email
subject = "#{@protocol.id} - #{t(:mailer)[:application_title]} service request"
subject = email_title(@status, @protocol, @deleted_ssrs)

mail(:to => email, :from => NO_REPLY_FROM, :subject => subject)
end
Expand Down Expand Up @@ -106,7 +104,7 @@ def notify_admin(submission_email_address, user_current, ssr, audit_report=nil,
end

email = submission_email_address
subject = "#{@protocol.id} - #{t(:mailer)[:application_title]} service request"
subject = email_title(@status, @protocol, ssr)

mail(:to => email, :from => NO_REPLY_FROM, :subject => subject)
end
Expand Down Expand Up @@ -166,7 +164,7 @@ def notify_service_provider(service_provider, service_request, user_current, ssr

# only send these to the correct person in the production env
email = service_provider.identity.email
subject = "#{@protocol.id} - #{t(:mailer)[:application_title]} service request"
subject = email_title(@status, @protocol, ssr)

mail(:to => email, :from => NO_REPLY_FROM, :subject => subject)
end
Expand Down Expand Up @@ -260,18 +258,21 @@ def notify_for_epic_rights_changes protocol, project_role, previous_rights
def epic_queue_error protocol, error=nil
@protocol = protocol
@error = error
mail(:to => QUEUE_EPIC_LOAD_ERROR_TO, :from => NO_REPLY_FROM, :subject => "#{@protocol.id} - Error batch loading protocol to Epic")
subject = "#{t(:mailer)[:epic_queue_error]} #{@protocol.id}"
mail(to: QUEUE_EPIC_LOAD_ERROR_TO, from: NO_REPLY_FROM, subject: subject)
end

def epic_queue_report
attachments["epic_queue_report.csv"] = File.read(Rails.root.join("tmp", "epic_queue_report.csv"))
mail(:to => EPIC_QUEUE_REPORT_TO, :from => NO_REPLY_FROM, :subject => "Epic Queue Report")
subject = "#{t(:mailer)[:email_title][:epic_queue_report]}"
mail(to: EPIC_QUEUE_REPORT_TO, from: NO_REPLY_FROM, subject: subject)
end

def epic_queue_complete sent, failed
@sent = sent
@failed = failed
mail(:to => EPIC_QUEUE_REPORT_TO, :from => NO_REPLY_FROM, :subject => "Epic Queue Complete")
subject = "#{t(:mailer)[:application_title]} #{t(:mailer)[:email_title][:epic_queue_summary]}"
mail(to: EPIC_QUEUE_REPORT_TO, from: NO_REPLY_FROM, subject: subject)
end

def set_instance_variables(current_user, service_request, service_list_false, service_list_true, line_items, protocol)
Expand All @@ -298,6 +299,25 @@ def status(ssr_destroyed, request_amendment, individual_ssr, ssr, service_reques
status
end

def email_title(status, protocol, ssr)
email_status = case status
when 'get_a_cost_estimate'
"Get Cost Estimate"
when 'request_amendment'
"Amendment Submitted "
when 'ssr_destroyed'
"Request Deletion"
when 'submitted'
"Submission"
end

if status == 'ssr_destroyed'
t('mailer.email_title.general', email_status: email_status, type: "Request", id: ssr.display_id)
else
t('mailer.email_title.general', email_status: email_status, type: "Protocol", id: protocol.id)
end
end

def service_requester_id(service_request, deleted_ssr)
service_request.sub_service_requests.first.present? ? service_request.sub_service_requests.first.service_requester_id : AuditRecovery.where(auditable_id: deleted_ssr.id, auditable_type: 'SubServiceRequest', action: 'destroy').first.audited_changes['service_requester_id']
end
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/survey_notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def service_survey(surveys, identity, ssr)
@surveys = surveys
@ssr = ssr
email = @identity.email
subject = t('surveyor.responses.emails.service_survey.subject', site_name: t(:proper)[:header])
subject = t('surveyor.responses.emails.service_survey.subject', site_name: t(:proper)[:header], ssr_id: @ssr.display_id)

mail(to: email, from: NO_REPLY_FROM, subject: subject)
end
Expand Down
7 changes: 4 additions & 3 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@ def authorized_user_changed(user, protocol, modified_role, action)
@send_to = user
@protocol = protocol
@protocol_link = DASHBOARD_LINK + "/protocols/#{@protocol.id}"
send_message("#{@protocol.id} - #{t(:mailer)[:application_title]} Authorized Users")

send_message(t('mailer.email_title.general', email_status: "Authorized Users Update", type: "Protocol", id: @protocol.id))
end

def notification_received(user, ssr)
@send_to = user

if ssr.present?
is_service_provider = @send_to.is_service_provider?(ssr)
send_message("New #{t(:mailer)[:application_title]} Notification", is_service_provider, ssr.id.to_s)
send_message("#{t(:mailer)[:email_title][:new]} #{t('mailer.email_title.general', email_status: 'Notification', type: 'Protocol', id: ssr.protocol.id)}", is_service_provider, ssr.id.to_s)
else
send_message("New #{t(:mailer)[:application_title]} Notification")
send_message("#{t(:mailer)[:email_title][:new]} #{t('mailer.email_title.general', email_status: 'Notification', type: 'Protocol', id: ssr.protocol.id)}")
end
end

Expand Down
13 changes: 10 additions & 3 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1395,8 +1395,15 @@ en:

# Mailer
mailer:
add_intro: "An Authorized User has been added in"
email_title:
epic_queue_error: "Epic Interface Error "
epic_queue_summary: "Epic Queue Summary"
epic_queue_report: "Epic Queue Report"
new: "New"
new_account_registration: "New SPARCRequest Account Registration"
general: "SPARCRequest %{email_status} (%{type} %{id})"
application_title: "SPARCRequest"
add_intro: "An Authorized User has been added in"
contact_information: "Contact Information"
delete_intro: "An Authorized User has been deleted in"
epic_access: "Epic Access"
Expand Down Expand Up @@ -1487,8 +1494,8 @@ en:
notes_present: "*Note(s) are included with this submission."
notice:
approve: "Approve Account"
body1: "Request for new SPARC Request account submitted and awaiting approval"
body2: "A new SPARC Request account is waiting for approval."
body1: "Request for new SPARCRequest account submitted and awaiting approval"
body2: "A new SPARCRequest account is waiting for approval."
company: "Company"
disapprove: "Disapprove Account"
email: "Email"
Expand Down
2 changes: 1 addition & 1 deletion config/locales/proper.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ en:
##########
footer:
listserv: "Listserv"
listserv_subject: "SPARC Request Listserv"
listserv_subject: "SPARCRequest Listserv"
sparc_blog: "Blog"
sparc_blog_url: "https://sparcrequestblog.com/"
sctr: "SCTR"
Expand Down
4 changes: 2 additions & 2 deletions config/locales/surveyor.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ en:
to_dashboard: "Return to Dashboard"
emails:
system_satisfaction:
subject: "System satisfaction survey completed in %{site_name}"
subject: "System Satisfaction Survey Completed in %{site_name}"
text1: "has completed a system satisfaction survey."
text2: "Results can be found "
service_survey:
subject: "%{site_name} Survey Notification"
subject: "%{site_name} Survey Notification (Request %{ssr_id})"
greeting: "Dear %{name},"
text1: "Thank you for requesting services from"
text2: "The service(s) you requested have now been completed."
Expand Down
4 changes: 4 additions & 0 deletions spec/mailers/notifier/deleted_all_services_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
@mail = Notifier.notify_service_provider(@service_provider, @service_request, identity, @sub_service_request, @report, true, false, false)
end

it 'should display correct subject' do
expect(@mail).to have_subject("SPARCRequest Request Deletion (Request #{@sub_service_request.display_id})")
end

# 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
2 changes: 1 addition & 1 deletion spec/mailers/notifier/get_a_cost_estimate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
end

it 'should display correct subject' do
expect(@mail).to have_subject("#{@protocol.id} - SPARCRequest service request")
expect(@mail).to have_subject("SPARCRequest Get Cost Estimate (Protocol #{@protocol.id})")
end

# Expected service provider message is defined under get_a_cost_estimate_service_provider_admin_message
Expand Down
4 changes: 4 additions & 0 deletions spec/mailers/notifier/request_amendment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
@mail = Notifier.notify_service_provider(@service_provider, @service_request, identity, @sub_service_request, @report, false, true)
end

it 'should display correct subject' do
expect(@mail).to have_subject("SPARCRequest Amendment Submitted (Protocol #{@protocol.id})")
end

# Expected service provider message is defined under request_amendment_intro
it 'should display service provider intro message, conclusion, link, and should not display acknowledgments' do
request_amendment_intro(@mail)
Expand Down
2 changes: 1 addition & 1 deletion spec/mailers/notifier/submitted_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
end

it 'should display correct subject' do
expect(@mail).to have_subject("#{@protocol.id} - SPARCRequest service request")
expect(@mail).to have_subject("SPARCRequest Submission (Protocol #{@protocol.id})")
end
# Expected service provider message is defined under submitted_service_provider_and_admin_message
it 'should display service provider intro message, conclusion, link, and should not display acknowledgments' do
Expand Down
6 changes: 3 additions & 3 deletions spec/mailers/survey_notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#ensure that the subject is correct
it 'should render the subject' do
expect(mail).to have_subject("System satisfaction survey completed in SPARCRequest")
expect(mail).to have_subject("System Satisfaction Survey Completed in SPARCRequest")
end

#ensure that the receiver is correct
Expand Down Expand Up @@ -63,7 +63,7 @@

#ensure that the subject is correct
it 'should render the subject' do
expect(mail).to have_subject("SPARCRequest Survey Notification")
expect(mail).to have_subject("SPARCRequest Survey Notification (Request #{ssr.display_id})")
end

#ensure that the receiver is correct
Expand Down Expand Up @@ -93,7 +93,7 @@

#ensure that the subject is correct
it 'should render the subject' do
expect(mail).to have_subject("SPARCRequest Survey Notification")
expect(mail).to have_subject("SPARCRequest Survey Notification (Request #{ssr.display_id})")
end

#ensure that the receiver is correct
Expand Down
4 changes: 4 additions & 0 deletions spec/mailers/user_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
@protocol_role = create(:project_role, protocol: @protocol, identity: modified_identity, project_rights: 'approve', role: 'consultant')
@mail = UserMailer.authorized_user_changed(identity, @protocol, @protocol_role, 'add')
end

it 'should display correct subject' do
expect(@mail).to have_subject("SPARCRequest Authorized Users Update (Protocol #{@protocol.id})")
end

it "should display the 'added' message" do
# An Authorized User has been added in SparcDashboard ***(link to protocol)***
Expand Down

0 comments on commit 3b30580

Please sign in to comment.