Skip to content

Commit

Permalink
Merge branch 'master' into LUPEYALPHA-877-practitioner-notify-email
Browse files Browse the repository at this point in the history
  • Loading branch information
vacabor committed Sep 24, 2024
2 parents 237cac6 + 178ffac commit bd317c5
Show file tree
Hide file tree
Showing 35 changed files with 493 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ def create
body: "Verification email sent to #{claim.school.name}"
)

ClaimMailer.further_education_payment_provider_verification_email(claim).deliver_later
Policies::FurtherEducationPayments::ProviderVerificationEmails.new(claim)
.send_further_education_payment_provider_verification_email

flash[:notice] = "Verification email sent to #{claim.school.name}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def save
# noop
# do not send provider verification email
else
ClaimMailer.further_education_payment_provider_verification_email(claim).deliver_later
Policies::FurtherEducationPayments::ProviderVerificationEmails.new(claim)
.send_further_education_payment_provider_verification_email
end

true
Expand Down
6 changes: 6 additions & 0 deletions app/helpers/claim_mailer_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ def rejected_reasons_personalisation(reasons)
rejected_reasons_with_answers(reasons)
end

def rejected_reason_claimed_last_year?
return false unless @claim.policy == Policies::InternationalRelocationPayments

@claim.latest_decision&.rejected_reasons_hash&.[](:reason_claimed_last_year) == "1"
end

private

def rejected_reasons_with_answers(reasons)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module FurtherEducationPayments
class ProviderVerificationChaseEmailJob < CronJob
# Daily 8am
self.cron_expression = "0 8 * * *"

queue_as :user_data

def perform
Rails.logger.info "ProviderVerificationChaseEmailJob sending chase emails..."

unverified_claims_with_provider_email_sent_over_3_weeks_ago.each do |claim|
claim.notes.create!(
label: "provider_verification",
body: "Verification chaser email sent to #{claim.school.name}"
)

Policies::FurtherEducationPayments::ProviderVerificationEmails.new(claim)
.send_further_education_payment_provider_verification_chase_email
end
end

private

def unverified_claims_with_provider_email_sent_over_3_weeks_ago
Policies::FurtherEducationPayments::Eligibility
.includes(:claim)
.unverified
.provider_verification_email_last_sent_over(3.weeks.ago)
.provider_verification_chase_email_not_sent
.map(&:claim)
.reject { |claim| claim.held? || claim.latest_decision&.rejected? }
end
end
end
1 change: 1 addition & 0 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ApplicationMailer < Mail::Notify::Mailer
CLAIM_REJECTED_NOTIFY_TEMPLATE_ID: "a1bb5f64-585f-4b03-b9db-0b20ad801b34".freeze,

CLAIM_PROVIDER_VERIFICATION_EMAIL_TEMPLATE_ID: "9a25fe46-2ee4-4a5c-8d47-0f04f058a87d".freeze,
CLAIM_PROVIDER_VERIFICATION_CHASE_EMAIL_TEMPLATE_ID: "9c84a684-b751-449a-bce0-ebe4aa5b187a".freeze,
CLAIM_PROVIDER_VERIFICATION_CONFIRMATION_EMAIL_TEMPLATE_ID: "70942fe1-5838-4d37-904c-9d070f2582f0".freeze
}

Expand Down
22 changes: 22 additions & 0 deletions app/mailers/claim_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def rejected(claim)
ref_number: @claim.reference,
support_email_address: @support_email_address,
current_financial_year: (claim.policy == Policies::StudentLoans) ? Policies::StudentLoans.current_financial_year : "",
last_academic_year: rejected_reason_claimed_last_year? ? (AcademicYear.current - 1).to_s : "",
**rejected_reasons_personalisation(@claim.latest_decision&.rejected_reasons_hash)
}

Expand Down Expand Up @@ -123,6 +124,27 @@ def further_education_payment_provider_verification_email(claim)
)
end

def further_education_payment_provider_verification_chase_email(claim)
policy_check!(claim, Policies::FurtherEducationPayments)

personalisation = {
recipient_name: claim.school.name,
claimant_name: claim.full_name,
claim_reference: claim.reference,
claim_submission_date: l(claim.created_at.to_date),
verification_due_date: l(Policies::FurtherEducationPayments.verification_chase_due_date_for_claim(claim)),
verification_url: Journeys::FurtherEducationPayments::Provider::SlugSequence.verify_claim_url(claim)
}

template_id = template_ids(claim)[:CLAIM_PROVIDER_VERIFICATION_CHASE_EMAIL_TEMPLATE_ID]

template_mail(
template_id,
to: claim.school.eligible_fe_provider.primary_key_contact_email_address,
personalisation: personalisation
)
end

def further_education_payment_provider_confirmation_email(claim)
policy_check!(claim, Policies::FurtherEducationPayments)

Expand Down
4 changes: 4 additions & 0 deletions app/models/policies/further_education_payments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ def verification_due_date_for_claim(claim)
(claim.created_at + 2.weeks).to_date
end

def verification_chase_due_date_for_claim(claim)
(claim.eligibility.provider_verification_chase_email_last_sent_at + 3.weeks).to_date
end

def duplicate_claim?(claim)
Claim::MatchingAttributeFinder.new(claim).matching_claims.exists?
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/policies/further_education_payments/eligibility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def description
belongs_to :possible_school, optional: true, class_name: "School"
belongs_to :school, optional: true

scope :unverified, -> { where(verification: {}) }
scope :provider_verification_email_last_sent_over, ->(older_than) { where("provider_verification_email_last_sent_at < ?", older_than) }
scope :provider_verification_chase_email_not_sent, -> { where(provider_verification_chase_email_last_sent_at: nil) }

# Claim#school expects this
alias_method :current_school, :school

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Policies
module FurtherEducationPayments
class ProviderVerificationEmails
def initialize(claim)
@claim = claim
end

# First provider email
def send_further_education_payment_provider_verification_email
@claim.eligibility.update!(provider_verification_email_last_sent_at: Time.now)
ClaimMailer.further_education_payment_provider_verification_email(@claim).deliver_later
end

# Second automated provider chase email
def send_further_education_payment_provider_verification_chase_email
@claim.eligibility.update!(provider_verification_chase_email_last_sent_at: Time.now)
ClaimMailer.further_education_payment_provider_verification_chase_email(@claim).deliver_later
end
end
end
end
3 changes: 2 additions & 1 deletion app/models/policies/international_relocation_payments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ module InternationalRelocationPayments
:no_response_from_school,
:suspected_fraud,
:information_mismatch_new_details_needed,
:ineligible_previous_residency
:ineligible_previous_residency,
:claimed_last_year
]

# Attributes to delete from claims submitted before the current academic
Expand Down
2 changes: 1 addition & 1 deletion app/views/additional_payments/landing_page.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</p>

<p class="govuk-body">
Payments are given up to 16 weeks from applying. You will receive an approval email with further information on your application.
Payments are given up to 26 weeks from applying. You will receive an approval email with further information on your application.
</p>

<%= govuk_details(summary_text: "The different additional payments") do %>
Expand Down
1 change: 1 addition & 0 deletions app/views/admin/tasks/_claim_summary.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<%= claim_summary_heading(claim) %>
</span>
<span class="govuk-body-m">
<%= link_to "View tasks", admin_claim_tasks_path(claim), class: "govuk-link" unless current_page? admin_claim_tasks_path(@claim) %>
<%= link_to "View full claim", admin_claim_path(claim), class: "govuk-link" %>
<%= link_to "Amend claim", new_admin_claim_amendment_path(claim), class: "govuk-link" if claim.amendable? %>
<%= link_to "Top up claim", new_admin_claim_topup_path(@claim), class: "govuk-link" if @claim.topupable? %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<%= claim_summary_heading(claim) %>
</span>
<span class="govuk-body-m">
<%= link_to "View tasks", admin_claim_tasks_path(claim), class: "govuk-link" %>
<%= link_to "View full claim", admin_claim_path(claim), class: "govuk-link" %>
<%= link_to "Amend claim", new_admin_claim_amendment_path(claim), class: "govuk-link" if claim.amendable? %>
<%= link_to "Top up claim", new_admin_claim_topup_path(@claim), class: "govuk-link" if @claim.topupable? %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<%= claim_summary_heading(claim) %>
</span>
<span class="govuk-body-m">
<%= link_to "View tasks", admin_claim_tasks_path(claim), class: "govuk-link" %>
<%= link_to "View full claim", admin_claim_path(claim), class: "govuk-link" %>
<%= link_to "Amend claim", new_admin_claim_amendment_path(claim), class: "govuk-link" if claim.amendable? %>
<%= link_to "Top up claim", new_admin_claim_topup_path(@claim), class: "govuk-link" if @claim.topupable? %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<% if @tasks_presenter.provider_verification.verification_email_sent? %>
<% if @tasks_presenter.provider_verification.verification_email_sent_by_admin_team? %>
<div class="govuk-inset-text">
<% @tasks_presenter.provider_verification.admin_sent_emails.each do |verification_email| %>
<% @tasks_presenter.provider_verification.admin_sent_emails.each do |verification_email|%>
<p>
The verification request was sent to the provider by
<%= user_details(verification_email.created_by) %> on <%= l(verification_email.created_at) %>
<% if verification_email.created_by %>
<%= user_details(verification_email.created_by) %>
<% else %>
an automated process
<% end %>
on <%= l(verification_email.created_at) %>
</p>
<% end %>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/submissions/_confirmation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
</p>

<p class="govuk-body">
Payments are given up to 16 weeks from applying. We will email you updates on the progress of your application.
Payments are given up to 26 weeks from applying. We will email you updates on the progress of your application.
</p>

<p class="govuk-body">
Expand All @@ -12,7 +12,7 @@

<ul class="govuk-list govuk-list--bullet">
<li>
whether your application is accepted or rejected, usually within 12 weeks
whether your application is accepted or rejected, usually within 20 weeks
</li>
<li>
when your payment has been made, with a full breakdown of how much you have received
Expand Down
2 changes: 2 additions & 0 deletions config/analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ shared:
- subject_to_disciplinary_action
- half_teaching_hours
- flagged_as_duplicate
- provider_verification_email_last_sent_at
- provider_verification_chase_email_last_sent_at
:eligible_fe_providers:
- id
- ukprn
Expand Down
9 changes: 5 additions & 4 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ en:
suspected_fraud: Suspected fraud
information_mismatch_new_details_needed: "Information mismatch - new details needed"
ineligible_previous_residency: Ineligible previous residency
claimed_last_year: "Claimed last year"
eligibility_answers:
nationality: "Nationality"
passport_number: "Passport number"
Expand Down Expand Up @@ -895,8 +896,8 @@ en:
teaching_hours_per_week:
label: "Timetabled teaching hours"
claimant_answers:
more_than_12: "More than 12 hours per week"
between_2_5_and_12: "Between 2.5 and 12 hours per week"
more_than_12: "12 hours or more per week"
between_2_5_and_12: "2.5 hours or more but less than 12 hours per week"
less_than_2_5: "Less than 2.5 hours per week"
half_teaching_hours:
label: "Age range taught"
Expand Down Expand Up @@ -988,8 +989,8 @@ en:
On average, how many hours per week are you timetabled to teach at %{school_name} during the current term?
hint: ‘Timetabled teaching hours’ refers to the time you spend teaching lessons to students of all ages.
options:
more_than_12: More than 12 hours per week
between_2_5_and_12: Between 2.5 and 12 hours per week
more_than_12: 12 hours or more per week
between_2_5_and_12: 2.5 hours or more but less than 12 hours per week
less_than_2_5: Less than 2.5 hours per week
errors:
inclusion: Select the number of hours you are timetabled to teach per week at %{school_name} during the current term
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddProviderVerificationEmailLastSentAtToFurtherEducationPaymentsEligibilities < ActiveRecord::Migration[7.0]
def change
add_column :further_education_payments_eligibilities, :provider_verification_email_last_sent_at, :datetime
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddProviderVerificationChaseEmailLastSentAtToFurtherEducationPaymentsEligibilities < ActiveRecord::Migration[7.0]
def change
add_column :further_education_payments_eligibilities, :provider_verification_chase_email_last_sent_at, :datetime
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2024_09_04_150711) do
ActiveRecord::Schema[7.0].define(version: 2024_09_23_130010) do
# These are extensions that must be enabled in order to support this database
enable_extension "citext"
enable_extension "pg_trgm"
Expand Down Expand Up @@ -261,6 +261,8 @@
t.boolean "half_teaching_hours"
t.jsonb "verification", default: {}
t.boolean "flagged_as_duplicate", default: false
t.datetime "provider_verification_email_last_sent_at"
t.datetime "provider_verification_chase_email_last_sent_at"
t.index ["possible_school_id"], name: "index_fe_payments_eligibilities_on_possible_school_id"
t.index ["school_id"], name: "index_fe_payments_eligibilities_on_school_id"
end
Expand Down
9 changes: 7 additions & 2 deletions spec/factories/claims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
eligibility_trait { nil }
eligibility_attributes { nil }
decision_creator { nil }
rejected_reasons { nil }
using_mobile_number_from_tid { false }
end

Expand Down Expand Up @@ -153,9 +154,13 @@

trait :rejected do
submitted
after(:build) do |claim|
after(:build) do |claim, evaluator|
claim.save
create(:decision, :rejected, claim: claim)
if evaluator.rejected_reasons
create(:decision, :rejected, claim: claim, rejected_reasons: evaluator.rejected_reasons)
else
create(:decision, :rejected, claim: claim)
end
end
end

Expand Down
Loading

0 comments on commit bd317c5

Please sign in to comment.