Skip to content

Commit

Permalink
STEM: Email SCO on form Submission #10790 (#4538)
Browse files Browse the repository at this point in the history
* get evss info on 10203 form submission

* don't use after_save

* test

* Update va10203.rb

* AC 1,3,4

* Update school_certifying_officials_mailer.rb

* use erb templates for email body

* commit

* revert

* the email

* Update school_certifying_officials_mailer_preview.rb

* make ci

* make ci

* Update va10203.rb

* unit tests

* move config

* Update school_certifying_officials_mailer_preview.rb

* Update school_certifying_officials_mailer.rb

* unit tests

* unit tests

* unit tests

* unit tests

* unit tests

* unit tests

* unit tests

* code review changes

* Update school_certifying_officials_mailer_spec.rb

* Update va10203_spec.rb

* vets-json-schema 6.4.0

* preview

* Delete school_certifying_officials_mailer_preview.rb

* create sidekiq job

* linter, va10203_spec

* Create send_sco_email_spec.rb

* Update send_sco_email.rb

* take advantage of params to allow for dynamic testing of SCO emails logic locally

* Update school_certifying_officials_mailer_preview.rb

* Update school_certifying_officials_mailer_preview.rb
  • Loading branch information
zurbergram authored Jul 31, 2020
1 parent ca73193 commit c694346
Show file tree
Hide file tree
Showing 21 changed files with 629 additions and 16 deletions.
1 change: 1 addition & 0 deletions app/controllers/v0/education_benefits_claims_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def create
StatsD.increment("#{stats_key}.success")
Rails.logger.info "ClaimID=#{claim.id} RPO=#{claim.education_benefits_claim.region} Form=#{form_type}"
load_user
claim.after_submit(@current_user)
clear_saved_form(claim.in_progress_form_id)
render(json: claim.education_benefits_claim)
end
Expand Down
23 changes: 23 additions & 0 deletions app/mailers/school_certifying_officials_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

class SchoolCertifyingOfficialsMailer < TransactionalEmailMailer
SUBJECT = 'Applicant for VA Rogers STEM Scholarship'
GA_CAMPAIGN_NAME = 'school-certifying-officials-10203-submission-notification'
GA_DOCUMENT_PATH = '/email/form'
GA_LABEL = 'school-certifying-officials-10203-submission-notification'
TEMPLATE = 'school_certifying_officials'

STAGING_RECIPIENTS = %w[
Delli-Gatti_Michael@bah.com
roth_matthew@bah.com
shawkey_daniel@bah.com
sonntag_adam@bah.com
].freeze

def build(applicant, recipients, ga_client_id)
@applicant = applicant
opt = { cc: applicant.email }
opt[:bcc] = STAGING_RECIPIENTS.clone if FeatureFlipper.staging_email?
super(recipients, ga_client_id, opt)
end
end
18 changes: 13 additions & 5 deletions app/mailers/transactional_email_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
# frozen_string_literal: true

class TransactionalEmailMailer < ApplicationMailer
def build(email, google_analytics_client_id)
def build(email, google_analytics_client_id, opt = {})
@google_analytics_client_id = google_analytics_client_id
@google_analytics_tracking_id = Settings.google_analytics_tracking_id

template = File.read("app/mailers/views/#{self.class::TEMPLATE}.html.erb")

mail(
to: email,
subject: self.class::SUBJECT,
content_type: 'text/html',
body: ERB.new(template).result(binding)
opt.merge(
to: email,
subject: self.class::SUBJECT,
content_type: 'text/html',
body: ERB.new(template).result(binding)
)
)
end

def first_initial_last_name(name)
return '' if name.nil?

"#{name.first[0, 1]} #{name.last}"
end
end
73 changes: 73 additions & 0 deletions app/mailers/views/school_certifying_officials.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<p>Dear VA School Certifying Official,</p>

<p>A student enrolled at your school has applied for the Edith Nourse Rogers STEM Scholarship. They will also receive a copy of this letter. We aren’t able to make a formal determination on this student’s eligibility for the STEM Scholarship until we receive the following information from you.</p>

<p>
<b>Rogers STEM Scholarship Applicant</b>
<br>
Name of Student: <%= first_initial_last_name(@applicant.veteranFullName) %>
<br>
Student’s school email address: <%= @applicant.schoolEmailAddress %>
<br>
Student’s school ID number: <%= @applicant.schoolStudentId %>
</p>

<p>
<b>If the applicant is an undergraduate</b>
<br>
If the student is currently enrolled in an undergraduate program, please provide the following:
<ul>
<li>
Is the student pursuing a bachelor’s degree in an approved STEM program?:
(<a href="https://benefits.va.gov/gibill/docs/fgib/STEM_Program_List.pdf">Programs approved for the Rogers STEM Scholarship</a>)
</li>
<li>Name of STEM program student is enrolled in:</li>
<li>6-digit CIP Code for the program:</li>
<li>Credit hours completed toward STEM program (specify semester or quarter):</li>
<li>Required credit hours for STEM program (specify semester or quarter):</li>
</ul>
</p>

<p>
<b>If the applicant is a teaching certificate candidate</b>
<br>
If the student already has an undergraduate degree and is seeking a teaching certification, please provide the following:
<ul>
<li>
Has the student earned a bachelor’s degree in an approved STEM program?:
(<a href="https://benefits.va.gov/gibill/docs/fgib/STEM_Program_List.pdf">Programs approved for the Rogers STEM Scholarship</a>)
</li>
<li>Name of STEM program of degree conferred:</li>
<li>6-digit CIP Code of degree conferred:</li>
<li>Is the student currently enrolled in a program leading to a teaching certification?:</li>
</ul>
</p>

<p>
<b>A reply is requested as soon as possible, preferably within 14 days.</b>
Please submit your response to <a href="mailto:STEM.VBABUF@va.gov">STEM.VBABUF@va.gov</a>. If we don’t receive a response within that time, we won’t be able to process the student’s application for the Rogers STEM Scholarship.
</p>

<p>Please submit any questions or concerns to <a href="mailto:STEM.VBABUF@va.gov">STEM.VBABUF@va.gov</a>. Please account for the 14-day time limit when submitting these questions.</p>

<p>Thank you,</p>

<p>
Rogers STEM Scholarship Team<br>
VA Buffalo Regional Processing Office<br>
<br>
<br>
VA Form Number: 10203<br>
OMB Control Number: 2900-0878<br>
OMB Expiration Date: 6/30/2023<br>
Respondent Burden: 15 minutes<br>
cc: <%= @applicant.email %>
</p>
</body>
</html>
8 changes: 4 additions & 4 deletions app/models/form_profiles/va10203.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ def initialize_school_information(gi_bill_status)

return {} if most_recent.blank?

service = GI::Client.new
service = GIDSRedis.new
profile_response = service.get_institution_details({ id: most_recent.facility_code })

VA10203::FormInstitutionInfo.new(
name: profile_response.body[:data][:attributes][:name],
city: profile_response.body[:data][:attributes][:city],
state: profile_response.body[:data][:attributes][:state]
name: profile_response[:data][:attributes][:name],
city: profile_response[:data][:attributes][:city],
state: profile_response[:data][:attributes][:state]
)
rescue => e
Rails.logger.error "Failed to retrieve GIDS data: #{e.message}"
Expand Down
2 changes: 2 additions & 0 deletions app/models/saved_claim/education_benefits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def in_progress_form_id
form_id
end

def after_submit(user); end

private

def add_education_benefits_claim
Expand Down
8 changes: 8 additions & 0 deletions app/models/saved_claim/education_benefits/va10203.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@

class SavedClaim::EducationBenefits::VA10203 < SavedClaim::EducationBenefits
add_form_and_validation('22-10203')

def after_submit(user)
return unless Flipper.enabled?(:edu_benefits_stem_scholarship) && FeatureFlipper.send_email?

authorized = user.authorize(:evss, :access?)

EducationForm::SendSCOEmail.perform_async(user.uuid, id) if authorized
end
end
105 changes: 105 additions & 0 deletions app/workers/education_form/send_sco_email.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# frozen_string_literal: true

module EducationForm
class SendSCOEmail
include Sidekiq::Worker

def perform(user_uuid, claim_id)
@user = User.find(user_uuid)
@claim = SavedClaim::EducationBenefits::VA10203.find(claim_id)

email_sent(false)

@gi_bill_status = get_gi_bill_status
if less_than_six_months?
@facility_code = get_facility_code

if @facility_code.present?
@institution = get_institution

send_sco_email
end
end
end

def self.sco_emails(scos)
emails = []
primary = scos.find { |sco| sco[:priority] == 'Primary' && sco[:email].present? }
secondary = scos.find { |sco| sco[:priority] == 'Secondary' && sco[:email].present? }

emails.push(primary[:email]) if primary.present?
emails.push(secondary[:email]) if secondary.present?

emails
end

private

def email_sent(sco_email_sent)
application = @claim.parsed_form
application['scoEmailSent'] = sco_email_sent
@claim.form = JSON.generate(application)
@claim.save
end

def get_gi_bill_status
service = EVSS::GiBillStatus::Service.new(@user)
service.get_gi_bill_status
rescue => e
Rails.logger.error "Failed to retrieve GiBillStatus data: #{e.message}"
{}
end

def get_facility_code
most_recent = @gi_bill_status.enrollments.max_by(&:begin_date)

return {} if most_recent.blank?

most_recent.facility_code
end

def get_institution
GIDSRedis.new.get_institution_details({ id: @facility_code })[:data][:attributes]
end

def less_than_six_months?
return false if @gi_bill_status.remaining_entitlement.blank?

months = @gi_bill_status.remaining_entitlement.months
days = @gi_bill_status.remaining_entitlement.days

((months * 30) + days) <= 180
end

def school_changed?
application = @claim.parsed_form
form_school_name = application['schoolName']
form_school_city = application['schoolCity']
form_school_state = application['schoolState']

prefill_name = @institution[:name]
prefill_city = @institution[:city]
prefill_state = @institution[:state]

form_school_name != prefill_name ||
form_school_city != prefill_city ||
form_school_state != prefill_state
end

def send_sco_email
return if @institution.blank? || school_changed?

emails = recipients

if emails.any?
SchoolCertifyingOfficialsMailer.build(@claim.open_struct_form, emails, nil).deliver_now
email_sent(true)
end
end

def recipients
scos = @institution[:versioned_school_certifying_officials]
EducationForm::SendSCOEmail.sco_emails(scos)
end
end
end
2 changes: 1 addition & 1 deletion app/workers/education_form/templates/10203.erb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Program Name: <%= @applicant.degreeName %>
Provide the location where you plan to or will start training:
<%= @applicant.schoolName %>
<%= @applicant.schoolCity %>, <%= @applicant.schoolState %>
Auto Email Sent to SCO:
Auto Email Sent to SCO: <%= yesno(@applicant.scoEmailSent) %>
Applicant School Email Address: <%= @applicant.schoolEmailAddress %>
Applicant School ID: <%= @applicant.schoolStudentId %>

Expand Down
2 changes: 2 additions & 0 deletions lib/config_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module ConfigHelper
module_function

def setup_action_mailer(config)
config.action_mailer.preview_path = Rails.root.join('spec', 'mailers', 'previews')

if FeatureFlipper.send_email?
config.action_mailer.delivery_method = :govdelivery_tms
config.action_mailer.govdelivery_tms_settings = {
Expand Down
28 changes: 28 additions & 0 deletions spec/factories/gi_bill_status_response.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

FactoryBot.define do
factory :gi_bill_status_response, class: EVSS::GiBillStatus::GiBillStatusResponse do
remaining_entitlement { { months: 0, days: 12 } }
enrollments {
[{
begin_date: '2012-11-01T04:00:00.000+00:00',
end_date: '2012-12-01T05:00:00.000+00:00',
facility_code: '11902614',
facility_name: 'Purdue University',
participant_id: '11170323',
training_type: 'UNDER_GRAD',
term_id: nil,
hour_type: nil,
full_time_hours: 12,
full_time_credit_hour_under_grad: nil,
vacation_day_count: 0,
on_campus_hours: 12.0,
online_hours: 0.0,
yellow_ribbon_amount: 0.0,
status: 'Approved',
amendments: []
}]
}
initialize_with { new(status: 200, response: {}) }
end
end
54 changes: 54 additions & 0 deletions spec/factories/gids_response.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

FactoryBot.define do
factory :gids_response, class: GI::GIDSResponse do
status { 200 }
body {
{
data:
{
attributes: {
name: 'School Name',
city: 'Test',
state: 'TN',
versioned_school_certifying_officials: [
{
priority: 'Primary',
email: 'test@edu_sample.com'
},
{
priority: 'Secondary',
email: 'test@edu_sample.com'
}
]
}
}
}
}

trait :empty do
body {
{
data: {
attributes: {}
}
}
}
end

trait :no_scos do
body {
{
data: {
attributes: {
name: 'School Name',
city: 'Test',
state: 'TN',
versioned_school_certifying_officials: []
}
}
}
}
end
end
end
Loading

0 comments on commit c694346

Please sign in to comment.