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

admin provider verification task #3131

Merged
merged 5 commits into from
Sep 5, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def save!
dfe_sign_in_uid: dfe_sign_in_uid,
dfe_sign_in_organisation_id: dfe_sign_in_organisation_id,
dfe_sign_in_organisation_ukprn: dfe_sign_in_organisation_ukprn,
dfe_sign_in_organisation_name: dfe_sign_in_organisation_name,
dfe_sign_in_service_access: dfe_sign_in_service_access?,
dfe_sign_in_role_codes: dfe_sign_in_role_codes,
dfe_sign_in_first_name: dfe_sign_in_first_name,
Expand All @@ -38,6 +39,10 @@ def dfe_sign_in_organisation_id
auth.dig("extra", "raw_info", "organisation", "id")
end

def dfe_sign_in_organisation_name
auth.dig("extra", "raw_info", "organisation", "name")
end

def dfe_sign_in_service_access?
dfe_sign_in_user.service_access?
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class VerifyClaimForm < Form
teaching_responsibilities
further_education_teaching_start_year
teaching_hours_per_week
hours_teaching_eligible_subjects
half_teaching_hours
subjects_taught
],
variable_contract: %i[
Expand All @@ -19,7 +19,7 @@ class VerifyClaimForm < Form
further_education_teaching_start_year
taught_at_least_one_term
teaching_hours_per_week
hours_teaching_eligible_subjects
half_teaching_hours
subjects_taught
teaching_hours_per_week_next_term
]
Expand Down Expand Up @@ -99,14 +99,18 @@ def save
dfe_sign_in_uid: answers.dfe_sign_in_uid,
first_name: answers.dfe_sign_in_first_name,
last_name: answers.dfe_sign_in_last_name,
email: answers.dfe_sign_in_email
email: answers.dfe_sign_in_email,
dfe_sign_in_organisation_name: answers.dfe_sign_in_organisation_name,
dfe_sign_in_role_codes: answers.dfe_sign_in_role_codes
},
created_at: DateTime.now
}
)

claim.save!

ClaimVerifierJob.perform_later(claim)

true
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
module AutomatedChecks
module ClaimVerifiers
class ProviderVerification
TASK_NAME = "provider_verification".freeze

def initialize(claim:)
@claim = claim

unless claim.policy.further_education_payments?
raise ArgumentError, "Claim must be an Further Education claim"
end
end

def perform
return unless claim.eligibility.verified?
return if task_exists?

create_task!
end

private

attr_reader :claim

def task_exists?
claim.tasks.where(name: TASK_NAME).exists?
end

def create_task!
claim.tasks.create!(
name: TASK_NAME,
created_by: created_by,
manual: false,
passed: passed?
)
end

def passed?
verification.fetch("assertions").all? do |assertion|
assertion.fetch("outcome") == true
end
end

def verification
@verification ||= claim.eligibility.verification
end

def verifier
verification.fetch("verifier")
end

def created_by
DfeSignIn::User.find_or_create_by!(
dfe_sign_in_id: verifier.fetch("dfe_sign_in_uid"),
given_name: verifier.fetch("first_name"),
family_name: verifier.fetch("last_name"),
email: verifier.fetch("email"),
organisation_name: verifier.fetch("dfe_sign_in_organisation_name"),
role_codes: verifier.fetch("dfe_sign_in_role_codes")
)
end
end
end
end
4 changes: 4 additions & 0 deletions app/models/base_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ def searchable_eligibility_attributes
def international_relocation_payments?
to_s == "InternationalRelocationPayments"
end

def further_education_payments?
to_s == "FurtherEducationPayments"
end
end
3 changes: 3 additions & 0 deletions app/models/claim_checking_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def applicable_task_names
task_names.delete("subject")
task_names.delete("teaching_hours")
end
unless claim.policy.further_education_payments?
task_names.delete("provider_verification")
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class SessionAnswers < Journeys::SessionAnswers
attribute :dfe_sign_in_uid, :string
attribute :dfe_sign_in_organisation_id, :string
attribute :dfe_sign_in_organisation_ukprn, :string
attribute :dfe_sign_in_organisation_name, :string
attribute :dfe_sign_in_service_access, :boolean, default: false
attribute :dfe_sign_in_role_codes, default: []
attribute :dfe_sign_in_first_name, :string
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 @@ -11,6 +11,10 @@ module FurtherEducationPayments

URL_SPREADSHEET_ELIGIBLE_PROVIDERS = "https://assets.publishing.service.gov.uk/media/667300fe64e554df3bd0db92/List_of_eligible_FE_providers_and_payment_value_for_levelling_up_premium.xlsx".freeze

VERIFIERS = [
AutomatedChecks::ClaimVerifiers::ProviderVerification
]

# Options shown to admins when rejecting a claim
ADMIN_DECISION_REJECTED_REASONS = [
# FIXME RL: this `placeholder` is required to make the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
module Policies
module FurtherEducationPayments
class AdminProviderVerificationTaskPresenter
class Row < Struct.new(
:label,
:claimant_answer,
:provider_answer,
keyword_init: true
)
end

attr_reader :claim

def initialize(claim)
@claim = claim
end

def rows
assertions.map do |assertion|
Row.new(
label: label(assertion),
claimant_answer: claimant_answer(assertion),
provider_answer: provider_answer(assertion)
)
end
end

private

def verification
@verification ||= claim.eligibility.verification
end

def assertions
verification["assertions"] + [courses_taught_assertion]
end

# The provider verifies the courses taught question as part of verifying the
# subjects taught question, however the admin UI designs require we
# display these separately, so we construct an additional "assertion" for
# courses taught
def courses_taught_assertion
subjects_taught_outcome = verification["assertions"].detect do |a|
a["name"] == "subjects_taught"
end.fetch("outcome")

{
"name" => "courses_taught",
"outcome" => subjects_taught_outcome
}
end

def label(assertion)
I18n.t(
[
"further_education_payments",
"admin",
"task_questions",
"provider_verification",
assertion["name"],
"label"
].join(".")
)
end

def claimant_answer(assertion)
key = assertion["name"]
case key
when "subjects_taught"
subjects_taught
when "courses_taught"
courses_taught
when "further_education_teaching_start_year"
"September #{further_education_teaching_start_year.to_i} " \
"to August #{further_education_teaching_start_year.to_i + 1}"
else
I18n.t(
[
"further_education_payments",
"admin",
"task_questions",
"provider_verification",
key,
"claimant_answers",
claim.eligibility.send(key)
].join(".")
)
end
end

def provider_answer(assertion)
assertion["outcome"] ? "Yes" : "No"
end

def subjects_taught
claim.eligibility.subjects_taught.map do |subject|
I18n.t(
[
"further_education_payments",
"forms",
"subjects_taught",
"options",
subject
].join(".")
)
end
end

def courses_taught
claim.eligibility.courses_taught.map(&:description)
end

def further_education_teaching_start_year
claim.eligibility.further_education_teaching_start_year
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,29 @@ class AdminTasksPresenter
def initialize(claim)
@claim = claim
end

def provider_verification
AdminProviderVerificationTaskPresenter.new(claim).rows
end

def provider_name
[verifier.fetch("first_name"), verifier.fetch("last_name")].join(" ")
end

def provider_verification_submitted?
claim.eligibility.verification.present?
end

# FIXME RL - temp stub so the provider verification task can be completed
def qualifications
[]
end

private

def verifier
@verifier ||= claim.eligibility.verification.fetch("verifier")
end
end
end
end
1 change: 1 addition & 0 deletions app/models/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class Task < ApplicationRecord
NAMES = %w[
identity_confirmation
provider_verification
visa
arrival_date
qualifications
Expand Down
69 changes: 69 additions & 0 deletions app/views/admin/tasks/provider_verification.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<% content_for(:page_title) { page_title("Claim #{@claim.reference} provider verification check for# {@claim.policy.short_name}") } %>
<%= link_to "Back", admin_claim_tasks_path(claim_id: @claim.id), class: "govuk-back-link" %>
<%= render "shared/error_summary", instance: @task, errored_field_id_overrides: { "passed": "task_passed_true" } if @task.errors.any? %>

<div class="govuk-grid-row">

<%= render "claim_summary", claim: @claim, heading: "Provider verification" %>

<div class="govuk-grid-column-three-quarters">
<h2 class="govuk-heading-xl"><%= @current_task_name.humanize %></h2>

<% if @tasks_presenter.provider_verification_submitted? %>
<p class="govuk-body">
This task was verified by the provider
(<%= @tasks_presenter.provider_name %>).
</p>

<table class="govuk-table govuk-!-margin-bottom-9">
<caption class="govuk-table__caption govuk-visually-hidden">
<%= @current_task_name.humanize %>
</caption>
<thead>
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header">
Eligibility check
</th>
<th scope="col" class="govuk-table__header">
Claimant submitted
</th>
<th scope="col" class="govuk-table__header">
Provider response
</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<% @tasks_presenter.provider_verification.each do |row| %>
<tr class="govuk-table__row govuk-!-width-one-quarter">
<th scope="row" class="govuk-table__header">
<%= row.label %>
</th>
<td class="govuk-table__cell govuk-!-width-one-half">
<%= Array.wrap(row.claimant_answer).join("<br><br>").html_safe %>
</td>
<td class="govuk-table__cell govuk-!-width-one-quarter">
<%= row.provider_answer %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<p class="govuk-body">
This task has not yet been completed by the provider
</p>
<% end %>
</div>

<% if @tasks_presenter.provider_verification_submitted? %>
<div class="govuk-grid-column-two-thirds">
<% if @task.persisted? %>
<%= render "task_outcome", task: @task, notes: @notes %>
<% else %>
<%= render "form", task_name: "provider_verification", claim: @claim %>
<% end %>

<%= render partial: "admin/task_pagination" %>
</div>
<% end %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
value: "12345678"
) %>

<%= f.govuk_text_field(
"[extra][raw_info][organisation][name]",
label: { text: "Organisation id" },
value: "Springfield Elementary School"
) %>

<%= f.govuk_text_field(
"uid",
label: { text: "DfE sign in UID" },
Expand Down
Loading
Loading