Skip to content

Commit

Permalink
Api 34592 poa v2 claimant signatures (#15827)
Browse files Browse the repository at this point in the history
* Schema updates and add generated swagger

* Add logic to use veteran or claimant for sig, update tests

* Add tests for non-veteran claimants

* Rubocop fixes

* Remove unused attribute from tests

* POA v2: Clean up required attributes

* Validate claimantId included when request includes claimant data

* Add test, fix logic based on tests

* Add test for org request

* Rubocop to the rescue

* Update test data to reflect schema updates

* Compiles swagger docs with update changes to required/not required values

* Fixing Gemfile.lock after merge conflict

* Adds space at the end of Gemfile.lock file

* Update modules/claims_api/app/controllers/concerns/claims_api/v2/power_of_attorney_validation.rb

Co-authored-by: jvcAdHoc <[email protected]>

* Cleans up a conditional and spelling error

* Adds language to explain conditionally required fields in schemas/docs

* Move logic to validation class, add to errors if found

* Validate claimantId, handle MPI errors, handle missing claimantId in form builder

* Update error message and add cassette

* Refactor logic to single call to MPI

* Fix poa individual request tests

* Disable module length check on poa validation

* Refactor to use form_data to store claimant first & last

* Fix tests, misc cleanup

* Refactor user profile access

* Rename variables to differ from method name

* Add defined? check for to handle nil from mpi

---------

Co-authored-by: Derrick Ellerbie <[email protected]>
Co-authored-by: rockwellwindsor-va <[email protected]>
Co-authored-by: Rockwell Windsor Rice <[email protected]>
Co-authored-by: jvcAdHoc <[email protected]>
  • Loading branch information
5 people authored Mar 25, 2024
1 parent 3dd4722 commit 02ff64f
Show file tree
Hide file tree
Showing 9 changed files with 483 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ def request_representative
def shared_form_validation(form_number)
target_veteran
# Custom validations for POA submission, we must check this first
@claims_api_forms_validation_errors = validate_form_2122_and_2122a_submission_values
@claims_api_forms_validation_errors = validate_form_2122_and_2122a_submission_values(user_profile)
# JSON validations for POA submission, will combine with previously captured errors and raise
validate_json_schema(form_number.upcase)
add_claimant_data_to_form if user_profile
# if we get here there were only validations file errors
if @claims_api_forms_validation_errors
raise ::ClaimsApi::Common::Exceptions::Lighthouse::JsonDisabilityCompensationValidationError,
Expand Down Expand Up @@ -167,6 +168,30 @@ def nullable_icn

nil
end

def user_profile
return @user_profile if defined? @user_profile

@user_profile ||= fetch_claimant
end

def fetch_claimant
claimant_icn = form_attributes.dig('claimant', 'claimantId')
if claimant_icn.present?
mpi_profile = mpi_service.find_profile_by_identifier(identifier: claimant_icn,
identifier_type: MPI::Constants::ICN)
end
rescue ArgumentError
mpi_profile
end

def add_claimant_data_to_form
if user_profile&.status == :ok
first_name = user_profile.profile.given_names.first
last_name = user_profile.profile.family_name
form_attributes['claimant'].merge!(firstName: first_name, lastName: last_name)
end
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
# frozen_string_literal: false

# rubocop:disable Metrics/ModuleLength

module ClaimsApi
module V2
module PowerOfAttorneyValidation
def validate_form_2122_and_2122a_submission_values
validate_claimant
def validate_form_2122_and_2122a_submission_values(user_profile)
validate_claimant(user_profile)
# collect errors and pass back to the controller
raise_error_collection if @errors
end

private

def validate_claimant
def validate_claimant(user_profile)
return if form_attributes['claimant'].blank?

validate_claimant_id_included(user_profile)
validate_address
validate_relationship
end
Expand Down Expand Up @@ -92,6 +95,26 @@ def validate_relationship
end
end

def validate_claimant_id_included(user_profile)
claimant_icn = form_attributes.dig('claimant', 'claimantId')
if (user_profile.blank? || user_profile&.status == :not_found) && claimant_icn
collect_error_messages(
source: 'claimant/claimantId',
detail: "The 'claimantId' must be valid"
)
else
address = form_attributes.dig('claimant', 'address')
phone = form_attributes.dig('claimant', 'phone')
relationship = form_attributes.dig('claimant', 'relationship')
return if claimant_icn.present? && (address.present? || phone.present? || relationship.present?)

collect_error_messages(
source: '/claimant/claimantId/',
detail: "If claimant is present 'claimantId' must be filled in"
)
end
end

def errors_array
@errors ||= []
end
Expand All @@ -109,3 +132,4 @@ def raise_error_collection
end
end
end
# rubocop:enable Metrics/ModuleLength
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,19 @@ def data(power_of_attorney, form_number)
end

def organization_signatures(power_of_attorney)
first_name = power_of_attorney.form_data['serviceOrganization']['firstName']
last_name = power_of_attorney.form_data['serviceOrganization']['lastName']
rep_first_name = power_of_attorney.form_data['serviceOrganization']['firstName']
rep_last_name = power_of_attorney.form_data['serviceOrganization']['lastName']
first_name, last_name = veteran_or_claimant_signature(power_of_attorney)
{
'page2' => [
{
'signature' => "#{power_of_attorney.auth_headers['va_eauth_firstName']} " \
"#{power_of_attorney.auth_headers['va_eauth_lastName']} - signed via api.va.gov",
'signature' => "#{first_name} " \
"#{last_name} - signed via api.va.gov",
'x' => 35,
'y' => 240
},
{
'signature' => "#{first_name} #{last_name} - signed via api.va.gov",
'signature' => "#{rep_first_name} #{rep_last_name} - signed via api.va.gov",
'x' => 35,
'y' => 200
}
Expand Down Expand Up @@ -109,21 +110,34 @@ def individual_page1_signatures(power_of_attorney, first_name, last_name)
]
end

def individual_page2_signatures(power_of_attorney, first_name, last_name)
def individual_page2_signatures(power_of_attorney, rep_first_name, rep_last_name)
first_name, last_name = veteran_or_claimant_signature(power_of_attorney)
[
{
'signature' => "#{power_of_attorney.auth_headers['va_eauth_firstName']} " \
"#{power_of_attorney.auth_headers['va_eauth_lastName']} - signed via api.va.gov",
'signature' => "#{first_name} " \
"#{last_name} - signed via api.va.gov",
'x' => 35,
'y' => 306
},
{
'signature' => "#{first_name} #{last_name} - signed via api.va.gov",
'signature' => "#{rep_first_name} #{rep_last_name} - signed via api.va.gov",
'x' => 35,
'y' => 200
}
]
end

def veteran_or_claimant_signature(power_of_attorney)
claimant = power_of_attorney.form_data['claimant'].present?
if claimant
first_name = power_of_attorney.form_data['claimant']['firstName']
last_name = power_of_attorney.form_data['claimant']['lastName']
else
first_name = power_of_attorney.auth_headers['va_eauth_firstName']
last_name = power_of_attorney.auth_headers['va_eauth_lastName']
end
[first_name, last_name]
end
end
end
end
70 changes: 12 additions & 58 deletions modules/claims_api/app/swagger/claims_api/v2/dev/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -9022,23 +9022,10 @@
"type": "object",
"additionalProperties": false,
"properties": {
"firstName": {
"description": "First name of Claimant.",
"type": "string",
"example": "John",
"maxLength": 12
},
"middleInitial": {
"description": "Middle initial of Claimant.",
"claimantId": {
"type": "string",
"example": "M",
"maxLength": 1
},
"lastName": {
"description": "Last name of Claimant.",
"type": "string",
"example": "Dow",
"maxLength": 18
"example": "123456789",
"description": "Id of the claimant."
},
"address": {
"type": "object",
Expand Down Expand Up @@ -9716,20 +9703,10 @@
"type": "object",
"additionalProperties": false,
"properties": {
"firstName": {
"description": "First name of Claimant.",
"type": "string",
"example": "John"
},
"middleInitial": {
"description": "Middle initial of Claimant.",
"type": "string",
"example": "M"
},
"lastName": {
"description": "Last name of Claimant.",
"claimantId": {
"type": "string",
"example": "Dow"
"example": "123456789",
"description": "Id of the claimant."
},
"address": {
"type": "object",
Expand Down Expand Up @@ -10359,23 +10336,10 @@
"type": "object",
"additionalProperties": false,
"properties": {
"firstName": {
"description": "First name of Claimant.",
"type": "string",
"example": "John",
"maxLength": 12
},
"middleInitial": {
"description": "Middle initial of Claimant.",
"claimantId": {
"type": "string",
"example": "M",
"maxLength": 1
},
"lastName": {
"description": "Last name of Claimant.",
"type": "string",
"example": "Dow",
"maxLength": 18
"example": "123456789",
"description": "Id of the claimant."
},
"address": {
"type": "object",
Expand Down Expand Up @@ -11044,20 +11008,10 @@
"type": "object",
"additionalProperties": false,
"properties": {
"firstName": {
"description": "First name of Claimant.",
"type": "string",
"example": "John"
},
"middleInitial": {
"description": "Middle initial of Claimant.",
"type": "string",
"example": "M"
},
"lastName": {
"description": "Last name of Claimant.",
"claimantId": {
"type": "string",
"example": "Dow"
"example": "123456789",
"description": "Id of the claimant."
},
"address": {
"type": "object",
Expand Down
16 changes: 3 additions & 13 deletions modules/claims_api/config/schemas/v2/2122.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,10 @@
"type": "object",
"additionalProperties": false,
"properties": {
"firstName": {
"description": "First name of Claimant.",
"type": "string",
"example": "John"
},
"middleInitial": {
"description": "Middle initial of Claimant.",
"type": "string",
"example": "M"
},
"lastName": {
"description": "Last name of Claimant.",
"claimantId": {
"type": "string",
"example": "Dow"
"example": "123456789",
"description": "Id of the claimant."
},
"address": {
"type": "object",
Expand Down
19 changes: 3 additions & 16 deletions modules/claims_api/config/schemas/v2/2122a.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,10 @@
"type": "object",
"additionalProperties": false,
"properties": {
"firstName": {
"description": "First name of Claimant.",
"type": "string",
"example": "John",
"maxLength": 12
},
"middleInitial": {
"description": "Middle initial of Claimant.",
"type": "string",
"example": "M",
"maxLength": 1
},
"lastName": {
"description": "Last name of Claimant.",
"claimantId": {
"type": "string",
"example": "Dow",
"maxLength": 18
"example": "123456789",
"description": "Id of the claimant."
},
"address": {
"type": "object",
Expand Down
Loading

0 comments on commit 02ff64f

Please sign in to comment.