Skip to content

Commit

Permalink
store full name from OL
Browse files Browse the repository at this point in the history
  • Loading branch information
asmega committed Dec 5, 2024
1 parent a393ab4 commit fe26058
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 9 deletions.
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
7 changes: 2 additions & 5 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
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
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
1 change: 1 addition & 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
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

0 comments on commit fe26058

Please sign in to comment.