-
Notifications
You must be signed in to change notification settings - Fork 166
LG-7832: Validate State ID and Address are transliterable to a valid USPS submission #7938
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
Merged
NavaTim
merged 42 commits into
main
from
tbradley/lg-7832-transliterate-usps-api-frontend
Mar 10, 2023
Merged
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
306b9ad
LG-7832: Transliterate name, address, and city for USPS API (w/ FF)
NavaTim bbb6bd8
LG-7832: Preserve State ID and Address form data on invalid submissions
NavaTim 7e43196
Merge branch 'tbradley/lg-7832-transliterate-usps-api-fix-forms' into…
NavaTim d2f5e4c
LG-7832: Validate State ID and Address are transliterable to a valid …
NavaTim 7dd52e4
LG-7832: Fix address test
NavaTim e3c5080
Merge branch 'tbradley/lg-7832-transliterate-usps-api-fix-forms' into…
NavaTim 0f5103b
LG-7832: Remove bad auto-merged configs
NavaTim 73e3fa6
Merge branch 'tbradley/lg-7832-transliterate-usps-api-integration' in…
NavaTim 3b1bb95
LG-7832: Move TransliterationResult to location expected by Rails aut…
NavaTim 3d683fb
LG-7832: Fix state ID step test
NavaTim acf503a
Merge branch 'tbradley/lg-7832-transliterate-usps-api-fix-forms' into…
NavaTim ce32726
Update Makefile
NavaTim 06ea563
Merge branch 'tbradley/lg-7832-transliterate-usps-api-integration' in…
NavaTim 923e77b
Update app/services/usps_in_person_proofing/transliterator.rb
NavaTim 36c5cab
Update app/services/usps_in_person_proofing/transliterator.rb
NavaTim 05b579c
LG-7832: Make test updates based on PR feedback
NavaTim 2b42b45
Merge branch 'tbradley/lg-7832-transliterate-usps-api-integration' of…
NavaTim e15cb28
LG-7832: Lint fix
NavaTim 63df395
Update spec/services/usps_in_person_proofing/enrollment_helper_spec.rb
NavaTim cad7a75
Update app/services/usps_in_person_proofing/enrollment_helper.rb
NavaTim 8bbf6bd
LG-7832: Remove incorrect usage of .class
NavaTim 8bda24e
LG-7832: Feature should only be enabled by default in dev environments
NavaTim 0a85a50
Update app/services/idv/steps/in_person/address_step.rb
NavaTim d76ccba
Update app/services/idv/steps/in_person/state_id_step.rb
NavaTim fc48a3e
Merge branch 'main' of https://github.com/18F/identity-idp into tbrad…
NavaTim 969c2f4
Merge branch 'main' of https://github.com/18F/identity-idp into tbrad…
NavaTim 0fc657c
Merge branch 'main' of https://github.com/18F/identity-idp into tbrad…
NavaTim 22ba566
Merge branch 'tbradley/lg-7832-transliterate-usps-api-fix-forms' of h…
NavaTim 959b264
Merge branch 'tbradley/lg-7832-transliterate-usps-api-integration' in…
NavaTim 94c54b7
Merge branch 'tbradley/lg-7832-transliterate-usps-api-fix-forms' into…
NavaTim d2b2390
Merge branch 'main' of https://github.com/18F/identity-idp into tbrad…
NavaTim eb4fee3
Merge branch 'main' of https://github.com/18F/identity-idp into tbrad…
NavaTim f8daae1
LG-7832: Use case no longer requires support for HashWithIndifferentA…
NavaTim 2d9d5d6
LG-7832: Clean up translation usage
NavaTim 966e7ac
LG-7832: Update test
NavaTim 66cbf42
LG-7832: Update test
NavaTim 79e09fc
LG-7832: Simplify unsupported character extraction from transliterate…
NavaTim b772dc5
LG-7832: Clarify transliteration result documentation
NavaTim 7b49ac3
LG-7832: Refactor helper logic into validator classes
NavaTim 5b20738
Switch to ->() lambda syntax to remove extra parens
zachmargolis 0841878
Change one more proc syntax to "stabby lambda"
zachmargolis 9a8522e
un-stub the TransliterableValidator spec as much as possible
zachmargolis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
app/services/usps_in_person_proofing/transliterable_validator.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| module UspsInPersonProofing | ||
| # Validator that can be attached to a form or other model | ||
| # to verify that specific supported fields are transliterable | ||
| # and conform to additional character requirements | ||
| # | ||
| # == Example | ||
| # | ||
| # validates_with UspsInPersonProofing::TransliterableValidator, | ||
| # fields: [:first_name, :last_name], | ||
| # reject_chars: /[^A-Za-z\-' ]/, | ||
| # message: ->(invalid_chars) | ||
| # "Rejected chars: #{invalid_chars.join(', ')}" | ||
| # end | ||
| # | ||
| class TransliterableValidator < ActiveModel::Validator | ||
| # Initialize the validator with the given fields configured | ||
| # for transliteration validation | ||
| # | ||
| # @param [Hash] options | ||
| # @option options [Array<Symbol>] fields Fields for which to validate transliterability | ||
| # @option options [Regexp] reject_chars Regex of chars to reject post-transliteration | ||
| # @option options [String,#call] message Error message or message generator | ||
| def initialize(options) | ||
| super | ||
| @fields = options[:fields] | ||
| @reject_chars = options[:reject_chars] | ||
| @message = options[:message] | ||
| end | ||
|
|
||
| # Check if the configured values on the record are transliterable | ||
| # | ||
| # @param [ActiveModel::Validations] record | ||
| def validate(record) | ||
| return unless IdentityConfig.store.usps_ipp_transliteration_enabled | ||
|
|
||
| @fields.each do |field| | ||
| next unless record.respond_to?(field) | ||
|
|
||
| value = record.send(field) | ||
| next unless value.respond_to?(:to_s) | ||
|
|
||
| invalid_chars = get_invalid_chars(value) | ||
| next unless invalid_chars.present? | ||
|
|
||
| record.errors.add( | ||
| field, | ||
| :nontransliterable_field, | ||
| message: get_error_message(invalid_chars), | ||
| ) | ||
| end | ||
| end | ||
|
|
||
| def transliterator | ||
| @transliterator ||= Transliterator.new | ||
| end | ||
|
|
||
| private | ||
|
|
||
| # Use unsupported character list to generate error message | ||
| def get_error_message(unsupported_chars) | ||
| return unless unsupported_chars.present? | ||
| if @message.respond_to?(:call) | ||
| @message.call(unsupported_chars) | ||
| else | ||
| @message | ||
| end | ||
| end | ||
|
|
||
| def get_invalid_chars(value) | ||
| # Get transliterated value | ||
| result = transliterator.transliterate(value) | ||
| transliterated = result.transliterated | ||
|
|
||
| # Remove question marks corresponding with unsupported chars | ||
| # for transliteration | ||
| unless transliterated.count(Transliterator::REPLACEMENT) > result.unsupported_chars.length | ||
| transliterated = transliterated.gsub(Transliterator::REPLACEMENT, '') | ||
| end | ||
|
|
||
| # Scan for unsupported chars for the field | ||
| if @reject_chars.is_a?(Regexp) | ||
| additional_chars = transliterated.scan(@reject_chars) | ||
| else | ||
| additional_chars = [] | ||
| end | ||
|
|
||
| # Create sorted list of unique unsupported characters | ||
| (result.unsupported_chars + additional_chars).sort.uniq | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like the copy is a little misleading, clearly the system can read the characters if we can render them back... but I'm guessing this copy already went through UX, and this is not the hill I die on