Skip to content

Commit

Permalink
Merge pull request #6323 from ministryofjustice/ap-4783-surname-at-birth
Browse files Browse the repository at this point in the history
Ap 4783 surname at birth
  • Loading branch information
colinbruce authored Feb 9, 2024
2 parents bc765d0 + 715fca1 commit ef7e3d9
Show file tree
Hide file tree
Showing 42 changed files with 3,587 additions and 52 deletions.
2 changes: 1 addition & 1 deletion app/controllers/providers/applicant_details_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def applicant

def form_params
merged_params = merge_with_model(applicant) do
params.require(:applicant).permit(:first_name, :last_name, :date_of_birth)
params.require(:applicant).permit(:first_name, :last_name, :date_of_birth, :changed_last_name, :last_name_at_birth)
end
convert_date_params(merged_params)
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/providers/applicants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def edit_applicant_key_point

def form_params
merged_params = merge_with_model(applicant) do
params.require(:applicant).permit(:first_name, :last_name, :date_of_birth)
params.require(:applicant).permit(:first_name, :last_name, :date_of_birth, :changed_last_name, :last_name_at_birth)
end
convert_date_params(merged_params)
end
Expand Down
16 changes: 14 additions & 2 deletions app/forms/applicants/basic_details_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ class BasicDetailsForm < BaseForm
last_name
date_of_birth_1i
date_of_birth_2i
date_of_birth_3i].freeze
date_of_birth_3i
changed_last_name
last_name_at_birth].freeze

form_for Applicant

attr_accessor(*ATTRIBUTES)
attr_writer :date_of_birth

before_validation do
squish_whitespaces(:first_name, :last_name)
squish_whitespaces(:first_name, :last_name, :last_name_at_birth)
end

# Note order of validation here determines order they appear on page
Expand All @@ -23,6 +25,8 @@ class BasicDetailsForm < BaseForm
validates :first_name, presence: true, unless: proc { draft? && last_name.present? }
validates :last_name, presence: true, unless: proc { draft? && first_name.present? }
validates :date_of_birth, presence: true, unless: :draft_and_not_partially_complete_date_of_birth?
validates :changed_last_name, inclusion: %w[true false], unless: :draft?
validates :last_name_at_birth, presence: true, unless: proc { draft? || changed_last_name.to_s != "true" }

validates(
:date_of_birth,
Expand All @@ -32,5 +36,13 @@ class BasicDetailsForm < BaseForm
},
allow_nil: true,
)

def save
if changed_last_name.to_s == "false"
attributes[:last_name_at_birth] = nil
end
super
end
alias_method :save!, :save
end
end
5 changes: 5 additions & 0 deletions app/models/applicant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def full_name
"#{first_name} #{last_name}".strip
end

def surname_at_birth
# used by CCMS generators
last_name_at_birth.presence || last_name
end

def true_layer_token
encrypted_true_layer_token&.fetch("token", nil)
end
Expand Down
3 changes: 2 additions & 1 deletion app/services/ccms/requestors/applicant_add_requestor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(applicant, provider_username)
end

def call
soap_client.call(:create_client, xml: request_xml)
Faraday::SoapCall.new(wsdl_location, :ccms).call(request_xml)
end

private
Expand Down Expand Up @@ -42,6 +42,7 @@ def client(xml)
def name(xml)
xml.__send__(:"common:Surname", applicant.last_name)
xml.__send__(:"common:FirstName", applicant.first_name)
xml.__send__(:"common:SurnameAtBirth", applicant.surname_at_birth.presence)
end

# this is all mandatory: we don't hold any of this data except date of birth
Expand Down
4 changes: 2 additions & 2 deletions app/services/ccms/requestors/applicant_search_requestor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(applicant, provider_username)
end

def call
soap_client.call(:get_client_details, xml: request_xml)
Faraday::SoapCall.new(wsdl_location, :ccms).call(request_xml)
end

private
Expand All @@ -35,7 +35,7 @@ def record_count(xml)
def search_criteria(xml)
xml.__send__(:"clientbim:ClientInfo") do
xml.__send__(:"clientbio:FirstName", @applicant.first_name)
xml.__send__(:"clientbio:Surname", @applicant.last_name)
xml.__send__(:"clientbio:Surname", @applicant.surname_at_birth)
xml.__send__(:"clientbio:DateOfBirth", @applicant.date_of_birth.to_fs(:ccms_date))
xml.__send__(:"clientbio:NINumber", @applicant.national_insurance_number)
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/ccms/requestors/case_add_requestor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def initialize(submission, options)

def call
save_request(@options[:case_type]) unless Rails.env.production?
soap_client.call(:create_case_application, xml: request_xml) unless @options[:no_call]
Faraday::SoapCall.new(wsdl_location, :ccms).call(request_xml)
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<%= render(
"shared/check_answers/client_details",
attributes: %i[first_name last_name date_of_birth national_insurance_number employment_status address],
attributes: %i[first_name last_name last_name_at_birth changed_last_name date_of_birth national_insurance_number employment_status address],
applicant: @applicant,
address: @address,
read_only: @read_only,
Expand Down
2 changes: 1 addition & 1 deletion app/views/providers/means_reports/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<%= render(
"shared/check_answers/client_details",
attributes: %i[first_name last_name date_of_birth age means_test national_insurance_number],
attributes: %i[first_name last_name last_name_at_birth changed_last_name date_of_birth age means_test national_insurance_number],
applicant: @legal_aid_application.applicant,
read_only: true,
) %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/providers/merits_reports/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<%= render(
"shared/check_answers/client_details",
attributes: %i[first_name last_name date_of_birth age means_test national_insurance_number],
attributes: %i[first_name last_name last_name_at_birth changed_last_name date_of_birth age means_test national_insurance_number],
applicant: @legal_aid_application.applicant,
read_only: true,
) %>
Expand Down
24 changes: 24 additions & 0 deletions app/views/shared/check_answers/_client_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@
<% end %>
<% end %>

<% if :changed_last_name.in?(attributes) %>
<%= summary_list.with_row(html_attributes: { id: "app-check-your-answers__changed_last_name" }) do |row| %>
<%= row.with_key(text: t(".changed_last_name"), classes: "govuk-!-width-one-half") %>
<%= row.with_value(text: yes_no(applicant.changed_last_name)) %>
<%= row.with_action(
text: t("generic.change"),
href: providers_legal_aid_application_applicant_details_path(@legal_aid_application, anchor: :changed_last_name),
visually_hidden_text: t(".changed_last_name"),
) %>
<% end %>
<% end %>

<% if :last_name_at_birth.in?(attributes) && !applicant.last_name_at_birth.nil? %>
<%= summary_list.with_row(html_attributes: { id: "app-check-your-answers__last_name_at_birth" }) do |row| %>
<%= row.with_key(text: t(".last_name_at_birth"), classes: "govuk-!-width-one-half") %>
<%= row.with_value(text: applicant.last_name_at_birth.presence || applicant.last_name) %>
<%= row.with_action(
text: t("generic.change"),
href: providers_legal_aid_application_applicant_details_path(@legal_aid_application, anchor: :last_name_at_birth),
visually_hidden_text: t(".last_name_at_birth"),
) %>
<% end %>
<% end %>

<% if :date_of_birth.in?(attributes) %>
<%= summary_list.with_row(html_attributes: { id: "app-check-your-answers__date_of_birth" }) do |row| %>
<%= row.with_key(text: t(".dob"), classes: "govuk-!-width-one-half") %>
Expand Down
9 changes: 8 additions & 1 deletion app/views/shared/forms/_applicant_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@
<%= form.govuk_text_field :first_name, label: { text: "First name" }, width: "three-quarters" %>
<%= form.govuk_text_field :last_name, label: { text: "Last name" }, width: "three-quarters" %>
<% end %>

<%= form.govuk_radio_buttons_fieldset :changed_last_name,
legend: { text: t(".changed_last_name") },
hint: { text: t(".changed_last_name_hint") } do %>
<%= form.govuk_radio_button :changed_last_name, true, link_errors: true, label: { text: t("generic.yes") } do %>
<%= form.govuk_text_field :last_name_at_birth, label: { text: t(".last_name_at_birth") }, hint: { text: t(".last_name_at_birth_hint") }, width: "three-quarters" %>
<% end %>
<%= form.govuk_radio_button :changed_last_name, false, label: { text: t("generic.no") } %>
<% end %>
<div class="govuk-!-padding-bottom-4"></div>
<%= form.govuk_date_field :date_of_birth, legend: { text: t("shared.forms.date_input_fields.date_of_birth_label") },
hint: { text: t("shared.forms.date_input_fields.date_of_birth_hint") } %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<h2 class="govuk-heading-l"><%= t(".client_details_heading") %></h2>
<%= render(
"shared/check_answers/client_details",
attributes: %i[first_name last_name date_of_birth national_insurance_number email address],
attributes: %i[first_name last_name last_name_at_birth changed_last_name date_of_birth national_insurance_number email address],
applicant: @legal_aid_application.applicant,
address: @legal_aid_application.applicant.address,
read_only: true,
Expand Down
4 changes: 2 additions & 2 deletions config/ccms/attribute_block_configs/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ global_means:
response_type: currency
user_defined: false
SURNAME_AT_BIRTH:
value: '#applicant_last_name'
value: '#applicant_surname_at_birth'
br100_meaning: 'Client: Surname at birth'
response_type: text
user_defined: true
Expand Down Expand Up @@ -2819,7 +2819,7 @@ global_merits:
response_type: boolean
user_defined: false
SURNAME_AT_BIRTH:
value: '#applicant_last_name'
value: '#applicant_surname_at_birth'
br100_meaning: 'Client: Surname at birth'
response_type: text
user_defined: true
Expand Down
4 changes: 4 additions & 0 deletions config/locales/en/activemodel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ en:
inclusion: Select yes if the client has a National Insurance number
last_name:
blank: Enter last name
last_name_at_birth:
blank: Enter your client's last name at birth
changed_last_name:
inclusion: Select yes if your client has ever changed their last name
national_insurance_number:
blank: Enter a National Insurance number
not_valid: Enter a valid National Insurance number
Expand Down
6 changes: 6 additions & 0 deletions config/locales/en/shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ en:
email: Email address
first_name: First name
last_name: Last name
changed_last_name: Has your client ever changed their last name?
last_name_at_birth: What was your client's last name at birth?
nino: National Insurance number
has_partner: Does your client have a partner?
has_partner_aria_label: Change whether your client has a partner
Expand Down Expand Up @@ -567,6 +569,10 @@ en:
page_title: Enter your client's details
name: Name
email_label: Email address
changed_last_name: Has your client ever changed their last name?
changed_last_name_hint: For example, through marriage or deed poll
last_name_at_birth: What was your client's last name at birth?
last_name_at_birth_hint: This lets us check for any records we have for your client under a previous name
date_input_fields:
date_of_birth_hint: For example, 31 3 1980.
date_of_birth_label: Date of birth
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddLastNameAtBirthToApplicants < ActiveRecord::Migration[7.1]
def change
add_column :applicants, :last_name_at_birth, :string
add_column :applicants, :changed_last_name, :boolean
end
end
8 changes: 5 additions & 3 deletions 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.1].define(version: 2024_01_24_161717) do
ActiveRecord::Schema[7.1].define(version: 2024_02_06_145546) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
Expand Down Expand Up @@ -110,9 +110,9 @@
t.integer "failed_attempts", default: 0, null: false
t.string "unlock_token"
t.datetime "locked_at", precision: nil
t.boolean "employed"
t.datetime "remember_created_at", precision: nil
t.string "remember_token"
t.boolean "employed"
t.boolean "self_employed", default: false
t.boolean "armed_forces", default: false
t.boolean "has_national_insurance_number"
Expand All @@ -125,6 +125,8 @@
t.decimal "student_finance_amount"
t.boolean "extra_employment_information"
t.string "extra_employment_information_details"
t.string "last_name_at_birth"
t.boolean "changed_last_name"
t.index ["confirmation_token"], name: "index_applicants_on_confirmation_token", unique: true
t.index ["email"], name: "index_applicants_on_email"
t.index ["unlock_token"], name: "index_applicants_on_unlock_token", unique: true
Expand Down Expand Up @@ -593,9 +595,9 @@
t.boolean "no_cash_income"
t.boolean "no_cash_outgoings"
t.date "purgeable_on"
t.string "required_document_categories", default: [], null: false, array: true
t.boolean "extra_employment_information"
t.string "extra_employment_information_details"
t.string "required_document_categories", default: [], null: false, array: true
t.string "full_employment_details"
t.datetime "client_declaration_confirmed_at", precision: nil
t.boolean "substantive_cost_override"
Expand Down
8 changes: 8 additions & 0 deletions features/providers/applicant_details.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Feature: Applicant details
Scenario: Completes the application using address lookup with multiple proceedings
Given I start the journey as far as the applicant page
Then I enter name 'Test', 'User'
Then I choose 'Yes'
Then I enter last name at birth 'Smith'
Then I enter the date of birth '03-04-1999'
Then I click 'Save and continue'
Then I am on the postcode entry page
Expand Down Expand Up @@ -132,6 +134,7 @@ Feature: Applicant details
Scenario: Completes the application using address lookup
Given I start the journey as far as the applicant page
Then I enter name 'Test', 'User'
Then I choose 'No'
Then I enter the date of birth '03-04-1999'
Then I click 'Save and continue'
Then I am on the postcode entry page
Expand Down Expand Up @@ -191,6 +194,7 @@ Feature: Applicant details
Scenario: Completes the application using manual address
Given I start the journey as far as the applicant page
Then I enter name 'Test', 'User'
Then I choose 'No'
Then I enter the date of birth '03-04-1999'
Then I click 'Save and continue'
Then I am on the postcode entry page
Expand Down Expand Up @@ -268,6 +272,7 @@ Feature: Applicant details
Given I start the journey as far as the applicant page
And a "bank holiday" exists in the database
Then I enter name 'Test', 'Walker'
Then I choose 'No'
Then I enter the date of birth '10-1-1980'
Then I click 'Save and continue'
Then I am on the postcode entry page
Expand Down Expand Up @@ -320,6 +325,7 @@ Feature: Applicant details
Scenario: I can see that the applicant does not receive benefits
Given I start the journey as far as the applicant page
Then I enter name 'Test', 'Paul'
Then I choose 'No'
Then I enter the date of birth '10-12-1961'
Then I click 'Save and continue'
Then I am on the postcode entry page
Expand Down Expand Up @@ -366,6 +372,7 @@ Feature: Applicant details
Then I click the first link 'Client name'
Then I should be on a page showing "Enter your client's details"
Then I enter name 'Kyle', 'Walker'
Then I choose 'No'
Then I enter the date of birth '10-1-1980'
When I click 'Save and continue'
Then I should be on a page with title "Does your client have a National Insurance number?"
Expand All @@ -380,6 +387,7 @@ Feature: Applicant details
Scenario: Allows return to, and proceed from, Delegated Function date view
Given I start the journey as far as the applicant page
Then I enter name 'Test', 'User'
Then I choose 'No'
Then I enter the date of birth '03-04-1999'
Then I click 'Save and continue'
Then I am on the postcode entry page
Expand Down
1 change: 1 addition & 0 deletions features/providers/applicant_under_16_blocked.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Feature: Applicant under 16 blocked
Given I start the journey as far as the applicant page

When I enter name 'Test', 'Paul'
Then I choose 'No'
And I enter a date of birth that will make me 16 today
And I click 'Save and continue'
Then I am on the postcode entry page
Expand Down
Loading

0 comments on commit ef7e3d9

Please sign in to comment.