From c9d2a6d97f73065c059fc50f1ca6c79b90f3c782 Mon Sep 17 00:00:00 2001 From: Richard Lynch Date: Mon, 28 Oct 2024 10:18:23 +0000 Subject: [PATCH] Set verified at on the claim We need to be able to access the timestamp a claim was verified in big query. The provider verification is flagged in the analytics block list so isn't sent over to big query (it's a json structure and some of it's fields are pii). To ensure big query has access to the verification timestamp we have added a new column on the claim `Claim#verified_at` which will be sent over to big query. A follow up PR will back fill this column on already verified claims. --- .../provider/verify_claim_form.rb | 38 +++++++++++-------- app/models/claim.rb | 3 +- config/analytics.yml | 1 + ...040_add_verified_at_timestamp_to_claims.rb | 5 +++ db/schema.rb | 3 +- .../provider/verify_claim_form_spec.rb | 2 + 6 files changed, 34 insertions(+), 18 deletions(-) create mode 100644 db/migrate/20241028095040_add_verified_at_timestamp_to_claims.rb diff --git a/app/forms/journeys/further_education_payments/provider/verify_claim_form.rb b/app/forms/journeys/further_education_payments/provider/verify_claim_form.rb index a896f10c17..01c57407ac 100644 --- a/app/forms/journeys/further_education_payments/provider/verify_claim_form.rb +++ b/app/forms/journeys/further_education_payments/provider/verify_claim_form.rb @@ -107,22 +107,28 @@ def assertions_attributes=(params) def save return false unless valid? - claim.eligibility.update!( - verification: { - assertions: assertions.map(&:attributes), - verifier: { - 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, - 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! + ApplicationRecord.transaction do + verified_at = DateTime.now + + claim.eligibility.update!( + verification: { + assertions: assertions.map(&:attributes), + verifier: { + 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, + dfe_sign_in_organisation_name: answers.dfe_sign_in_organisation_name, + dfe_sign_in_role_codes: answers.dfe_sign_in_role_codes + }, + created_at: verified_at + } + ) + + claim.verified_at = verified_at + + claim.save! + end ClaimMailer .further_education_payment_provider_confirmation_email(claim) diff --git a/app/models/claim.rb b/app/models/claim.rb index 298219227a..f4e01b6c45 100644 --- a/app/models/claim.rb +++ b/app/models/claim.rb @@ -92,7 +92,8 @@ class Claim < ApplicationRecord paye_reference: true, practitioner_email_address: true, provider_contact_name: true, - started_at: false + started_at: false, + verified_at: false }.freeze DECISION_DEADLINE = 12.weeks DECISION_DEADLINE_WARNING_POINT = 2.weeks diff --git a/config/analytics.yml b/config/analytics.yml index ca63ca8517..d179ee6a55 100644 --- a/config/analytics.yml +++ b/config/analytics.yml @@ -79,6 +79,7 @@ shared: - onelogin_auth_at - onelogin_idv_at - started_at + - verified_at :decisions: - id - result diff --git a/db/migrate/20241028095040_add_verified_at_timestamp_to_claims.rb b/db/migrate/20241028095040_add_verified_at_timestamp_to_claims.rb new file mode 100644 index 0000000000..33146b4753 --- /dev/null +++ b/db/migrate/20241028095040_add_verified_at_timestamp_to_claims.rb @@ -0,0 +1,5 @@ +class AddVerifiedAtTimestampToClaims < ActiveRecord::Migration[7.0] + def change + add_column :claims, :verified_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index fd7e4e3b8c..c04e0342a3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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_10_17_113701) do +ActiveRecord::Schema[7.0].define(version: 2024_10_28_095040) do # These are extensions that must be enabled in order to support this database enable_extension "citext" enable_extension "pg_trgm" @@ -112,6 +112,7 @@ t.text "onelogin_idv_last_name" t.date "onelogin_idv_date_of_birth" t.datetime "started_at", precision: nil, null: false + t.datetime "verified_at" t.index ["academic_year"], name: "index_claims_on_academic_year" t.index ["created_at"], name: "index_claims_on_created_at" t.index ["eligibility_type", "eligibility_id"], name: "index_claims_on_eligibility_type_and_eligibility_id" diff --git a/spec/forms/journeys/further_education_payments/provider/verify_claim_form_spec.rb b/spec/forms/journeys/further_education_payments/provider/verify_claim_form_spec.rb index 202f51f7fb..3946cabd53 100644 --- a/spec/forms/journeys/further_education_payments/provider/verify_claim_form_spec.rb +++ b/spec/forms/journeys/further_education_payments/provider/verify_claim_form_spec.rb @@ -344,6 +344,8 @@ "created_at" => "2024-01-01T12:00:00.000+00:00" } ) + + expect(claim.verified_at).to eq(DateTime.new(2024, 1, 1, 12, 0, 0)) end it "creates a provider verification task" do