-
Notifications
You must be signed in to change notification settings - Fork 166
LG-752 Verify by mail / undeliverable as addressed processing #2684
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
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6a2baf2
LG-752 Verify by mail undeliverable as addressed processing
stevegsa ae4ecd9
Rename migration
stevegsa 1a55aa9
Lint
stevegsa 56b57f9
Update schema
stevegsa 620ad0a
Normalize yaml
stevegsa 112c53e
Update mailer
stevegsa 8666d64
Fixed specs
stevegsa daea7db
Add route
stevegsa 2316197
Remove unused code
stevegsa f9e1df1
Added more coverage
stevegsa 88d6080
Merge branch 'master' into stevegsa-undeliverable-as-addressed
stevegsa 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| class UndeliverableAddressController < ApplicationController | ||
| skip_before_action :verify_authenticity_token | ||
|
|
||
| def create | ||
| authorize do | ||
| UndeliverableAddressNotifier.new.call | ||
|
|
||
| render plain: 'ok' | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def authorize | ||
| # Check for empty to make sure that the token is configured | ||
| if authorization_token && authorization_token == Figaro.env.usps_download_token | ||
| yield | ||
| else | ||
| head :unauthorized | ||
| end | ||
| end | ||
|
|
||
| def authorization_token | ||
| request.headers['X-API-AUTH-TOKEN'] | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| class UndeliverableAddressNotifier | ||
| TEMP_FILE_BASENAME = 'usps_bounced'.freeze | ||
|
|
||
| def call | ||
| temp_file = download_file | ||
| notifications_sent = process_file(temp_file) | ||
| cleanup(temp_file) | ||
| notifications_sent | ||
| end | ||
|
|
||
| private | ||
|
|
||
| attr_accessor :ucc | ||
|
|
||
| def download_file | ||
| file = Tempfile.new(TEMP_FILE_BASENAME) | ||
| Net::SFTP.start(*sftp_config) do |sftp| | ||
| sftp.download!(Figaro.env.usps_download_sftp_directory, file.path) | ||
| end | ||
| file | ||
| end | ||
|
|
||
| def cleanup(file) | ||
| file.close | ||
| file.unlink | ||
| end | ||
|
|
||
| def process_file(file) | ||
| notifications_sent = 0 | ||
| File.readlines(file.path).each do |line| | ||
| code = line.chomp | ||
| sent = process_code(code) | ||
| notifications_sent += 1 if sent | ||
| end | ||
| notifications_sent | ||
| end | ||
|
|
||
| def process_code(otp) | ||
| ucc = usps_confirmation_code(otp) | ||
| ucc&.safe_update_bounced_at_and_send_notification | ||
| end | ||
|
|
||
| def sftp_config | ||
| [ | ||
| env.usps_download_sftp_host, | ||
| env.usps_download_sftp_username, | ||
| password: env.usps_download_sftp_password, | ||
| timeout: env.usps_download_sftp_timeout.to_i, | ||
| ] | ||
| end | ||
|
|
||
| def env | ||
| Figaro.env | ||
| end | ||
|
|
||
| def usps_confirmation_code(otp) | ||
| @ucc ||= UspsConfirmationCode.find_by(otp_fingerprint: Pii::Fingerprinter.fingerprint(otp)) | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| p.lead == t('.intro', app: link_to(APP_NAME, Figaro.env.mailer_domain_name, class: 'gray')) | ||
|
|
||
| p.lead == t('.call_to_action') | ||
|
|
||
| table.spacer | ||
| tbody | ||
| tr | ||
| td.s10 height="10px" | ||
| | | ||
| table.hr | ||
| tr | ||
| th | ||
| | | ||
|
|
||
| p == t('.help', | ||
| app: link_to(APP_NAME, Figaro.env.mailer_domain_name, class: 'gray'), | ||
| help_link: link_to(t('user_mailer.help_link_text'), MarketingSite.help_url), | ||
| contact_link: link_to(t('user_mailer.contact_link_text'), MarketingSite.contact_url)) |
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
8 changes: 8 additions & 0 deletions
8
db/migrate/20181122100307_add_bounced_at_to_usps_confirmation_code.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,8 @@ | ||
| class AddBouncedAtToUspsConfirmationCode < ActiveRecord::Migration[5.1] | ||
| disable_ddl_transaction! | ||
|
|
||
| def change | ||
| add_column :usps_confirmation_codes, :bounced_at, :timestamp | ||
| add_index :usps_confirmation_codes, :otp_fingerprint, algorithm: :concurrently | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| require 'rails_helper' | ||
|
|
||
| describe UndeliverableAddressController do | ||
| describe '#create' do | ||
| context 'with no token' do | ||
| it 'returns unauthorized' do | ||
| post :create | ||
|
|
||
| expect(response.status).to eq 401 | ||
| end | ||
| end | ||
|
|
||
| context 'with an invalid token' do | ||
| before do | ||
| headers('foobar') | ||
| end | ||
|
|
||
| it 'returns unauthorized' do | ||
| post :create | ||
|
|
||
| expect(response.status).to eq 401 | ||
| end | ||
| end | ||
|
|
||
| context 'with a valid token' do | ||
| before do | ||
| headers(Figaro.env.usps_download_token) | ||
| end | ||
|
|
||
| it 'returns a good status' do | ||
| notifier = instance_double(UndeliverableAddressNotifier) | ||
| expect(notifier).to receive(:call) | ||
| expect(UndeliverableAddressNotifier).to receive(:new).and_return(notifier) | ||
|
|
||
| post :create | ||
|
|
||
| expect(response).to have_http_status(:ok) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def headers(token) | ||
| request.headers['X-API-AUTH-TOKEN'] = token | ||
| 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
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.
We tell people to sign in and follow instructions, but the instructions they see will them to enter the code we couldn't send them, right? Should we build in something, either here or in another PR, that shows users something if their letter bounced?
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.
The GUI and this email verbiage is up in the air right now. I guess depending on where we go with the GUI will drive what we say here. Docauth currently does not have a way to change the address so we would need to add a new flow for that.
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.
Okay, cool. Those are all things we can handle outside this PR once we know what needs to happen.