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

[CAPT-2051] Better OL name #3454

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
7 changes: 5 additions & 2 deletions app/controllers/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,14 @@ def process_one_login_identity_verification_callback(core_identity_jwt)
return redirect_to "/auth/failure?strategy=onelogin&message=access_denied&origin=#{origin}"
end

first_name, last_name, date_of_birth = extract_data_from_jwt(core_identity_jwt)
first_name, last_name, full_name, date_of_birth = extract_data_from_jwt(core_identity_jwt)

journey_session.answers.assign_attributes(
identity_confirmed_with_onelogin: true,
onelogin_idv_at: Time.now,
onelogin_idv_first_name: first_name,
onelogin_idv_last_name: last_name,
onelogin_idv_full_name: full_name,
onelogin_idv_date_of_birth: date_of_birth
)
journey_session.answers.first_name ||= first_name
Expand All @@ -124,16 +125,18 @@ def extract_data_from_jwt(jwt)
if OneLoginSignIn.bypass?
first_name = ONE_LOGIN_TEST_USER[:first_name]
last_name = ONE_LOGIN_TEST_USER[:last_name]
full_name = "#{first_name} #{last_name}"
date_of_birth = ONE_LOGIN_TEST_USER[:date_of_birth]
else
validator = OneLogin::CoreIdentityValidator.new(jwt:)
validator.call
first_name = validator.first_name
last_name = validator.last_name
full_name = validator.full_name
date_of_birth = validator.date_of_birth
end

[first_name, last_name, date_of_birth]
[first_name, last_name, full_name, date_of_birth]
end

def test_user_auth_hash
Expand Down
18 changes: 8 additions & 10 deletions app/models/claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class Claim < ApplicationRecord
practitioner_email_address: true,
provider_contact_name: true,
started_at: false,
verified_at: false
verified_at: false,
onelogin_idv_full_name: true
}.freeze
DECISION_DEADLINE = 12.weeks
DECISION_DEADLINE_WARNING_POINT = 2.weeks
Expand Down Expand Up @@ -247,10 +248,6 @@ class Claim < ApplicationRecord
by_policies(Policies.all.select { |p| p.require_in_progress_update_emails? })
}

def onelogin_idv_full_name
"#{onelogin_idv_first_name} #{onelogin_idv_last_name}"
end

def hold!(reason:, user:)
if holdable? && !held?
self.class.transaction do
Expand Down Expand Up @@ -478,14 +475,14 @@ def same_claimant?(other_claim)
end
end

def one_login_idv_mismatch?
!one_login_idv_name_match? || !one_login_idv_dob_match?
end

def one_login_idv_match?
one_login_idv_name_match? && one_login_idv_dob_match?
end

def one_login_idv_mismatch?
!one_login_idv_match?
end

def awaiting_provider_verification?
return false unless has_further_education_policy?

Expand All @@ -503,7 +500,8 @@ def attributes_flagged_by_risk_indicator
private

def one_login_idv_name_match?
onelogin_idv_full_name.downcase == "#{first_name.downcase} #{surname.downcase}"
/\A#{first_name.strip.downcase} /.match?(onelogin_idv_full_name.strip.downcase) &&
/ #{surname.strip.downcase}\z/.match?(onelogin_idv_full_name.strip.downcase)
end

def one_login_idv_dob_match?
Expand Down
1 change: 1 addition & 0 deletions app/models/journeys/session_answers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class SessionAnswers

attribute :onelogin_idv_first_name, :string
attribute :onelogin_idv_last_name, :string
attribute :onelogin_idv_full_name, :string
attribute :onelogin_idv_date_of_birth, :date

attribute :onelogin_auth_at, :datetime
Expand Down
4 changes: 4 additions & 0 deletions app/models/one_login/core_identity_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def date_of_birth
Date.parse(decoded_jwt[0]["vc"]["credentialSubject"]["birthDate"][0]["value"])
end

def full_name
name_parts.map { |hash| hash["value"] }.join(" ")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we ensure that the FamilyName part(s) are always last? I suspect there's no guarantee it will be ordered this way already.

end

private

def name_parts
Expand Down
1 change: 1 addition & 0 deletions config/analytics_blocklist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
- onelogin_uid
- onelogin_idv_first_name
- onelogin_idv_last_name
- onelogin_idv_full_name
- onelogin_idv_date_of_birth
:claim_decisions:
- trn
Expand Down
15 changes: 15 additions & 0 deletions db/migrate/20241205121421_add_ol_full_name_to_claims.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class AddOlFullNameToClaims < ActiveRecord::Migration[8.0]
def up
add_column :claims, :onelogin_idv_full_name, :text

execute <<-SQL
UPDATE claims
SET onelogin_idv_full_name = CONCAT(claims.onelogin_idv_first_name, ' ', claims.onelogin_idv_last_name)
WHERE claims.onelogin_idv_full_name IS NULL
SQL
end

def down
remove_column :claims, :onelogin_idv_full_name
end
end
3 changes: 2 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[8.0].define(version: 2024_11_26_105650) do
ActiveRecord::Schema[8.0].define(version: 2024_12_05_121421) do
# These are extensions that must be enabled in order to support this database
enable_extension "citext"
enable_extension "pg_catalog.plpgsql"
Expand Down Expand Up @@ -113,6 +113,7 @@
t.date "onelogin_idv_date_of_birth"
t.datetime "started_at", precision: nil, null: false
t.datetime "verified_at"
t.text "onelogin_idv_full_name"
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"
Expand Down
1 change: 1 addition & 0 deletions spec/factories/claims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
onelogin_idv_at { (onelogin_auth_at + 1.hour) }
onelogin_idv_first_name { first_name }
onelogin_idv_last_name { surname }
onelogin_idv_full_name { [first_name, surname].join(" ") }
onelogin_idv_date_of_birth { date_of_birth }
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@

expect(claim.first_name).to eql("John")
expect(claim.surname).to eql("Doe")
expect(claim.onelogin_idv_full_name).to eql("TEST USER")
expect(claim.student_loan_plan).to eq "plan_1"

eligibility = Policies::FurtherEducationPayments::Eligibility.last
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
logged_in_with_onelogin: true,
onelogin_idv_first_name: "John",
onelogin_idv_last_name: "Doe",
onelogin_idv_full_name: "John Doe",
onelogin_idv_date_of_birth: Date.new(1970, 1, 1),
first_name: "John",
surname: "Doe",
Expand Down Expand Up @@ -47,6 +48,7 @@
expect(claim.onelogin_idv_at).to eql(answers.onelogin_idv_at)
expect(claim.onelogin_idv_first_name).to eql(answers.onelogin_idv_first_name)
expect(claim.onelogin_idv_last_name).to eql(answers.onelogin_idv_last_name)
expect(claim.onelogin_idv_full_name).to eql(answers.onelogin_idv_full_name)
expect(claim.onelogin_idv_date_of_birth).to eql(answers.onelogin_idv_date_of_birth)

expect(eligibility.award_amount).to eq(answers.award_amount)
Expand Down Expand Up @@ -141,6 +143,7 @@
logged_in_with_onelogin: true,
onelogin_idv_first_name: "John",
onelogin_idv_last_name: "Doe",
onelogin_idv_full_name: "John Doe",
onelogin_idv_date_of_birth: Date.new(1970, 1, 1),
first_name: "Jack",
surname: "Doe",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ module ClaimVerifiers
first_name: "John",
surname: "Doe",
onelogin_idv_first_name: "Tom",
onelogin_idv_last_name: "Jones"
onelogin_idv_last_name: "Jones",
onelogin_idv_full_name: "Tom Jones"
)
end

Expand Down
48 changes: 48 additions & 0 deletions spec/models/claim_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@
:onelogin_uid,
:onelogin_idv_first_name,
:onelogin_idv_last_name,
:onelogin_idv_full_name,
:onelogin_idv_date_of_birth,
:paye_reference,
:practitioner_email_address,
Expand Down Expand Up @@ -1477,4 +1478,51 @@
expect(policy).to have_received(:decision_deadline_date).with(claim)
end
end

describe "#one_login_idv_match?" do
context "space in first name" do
before do
subject.onelogin_idv_full_name = "A B C"
subject.first_name = "A B"
subject.surname = "C"

subject.onelogin_idv_date_of_birth = Date.today
subject.date_of_birth = Date.today
end

it "matches" do
expect(subject).to be_one_login_idv_match
end
end

context "close match" do
before do
subject.onelogin_idv_full_name = "A B C"
subject.first_name = "AA B"
subject.surname = "C"

subject.onelogin_idv_date_of_birth = Date.today
subject.date_of_birth = Date.today
end

it "does not match" do
expect(subject).not_to be_one_login_idv_match
end
end

context "not a match" do
before do
subject.onelogin_idv_full_name = "A B"
subject.first_name = "Z"
subject.surname = "B"

subject.onelogin_idv_date_of_birth = Date.today
subject.date_of_birth = Date.today
end

it "does not match" do
expect(subject).not_to be_one_login_idv_match
end
end
end
end
14 changes: 14 additions & 0 deletions spec/models/one_login/core_identity_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@
end
end

describe "#full_name" do
before do
stub_normal_did

travel_to(Time.at(1723548751)) do
subject.call
end
end

it "returns whole name" do
expect(subject.full_name).to eql("KENNETH DECERQUEIRA")
end
end

let(:stub_normal_did) do
return_headers = {
"Cache-Control" => "max-age=3600, private"
Expand Down
1 change: 1 addition & 0 deletions spec/requests/omniauth_callbacks_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ def set_mock_auth(trn)
call: nil,
first_name: "John",
last_name: "Doe",
full_name: "John Doe",
date_of_birth: Date.new(1970, 12, 13)
)

Expand Down
Loading