Skip to content

Commit

Permalink
initial setup for SSN work
Browse files Browse the repository at this point in the history
# Conflicts:
#	app/controllers/state_file/archived_intakes/email_address_controller.rb
  • Loading branch information
anisharamnani committed Jan 8, 2025
1 parent 88f1ef1 commit 771f228
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ def update
event_type: 0,
state_file_archived_intake: archived_intake
)


session[:archived_intake_email_address] = @form.email_address # TODO: change to params
redirect_to state_file_archived_intakes_edit_verification_code_path(email_address: @form.email_address)
else
render :edit
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 1. use front end validations for SSN
# 2. give them 1 attempt at an inccorect SSN
# 3. update the access logs to have the correct event
# 4. tests, translations
module StateFile
module ArchivedIntakes
class IdentificationNumberController < ApplicationController
def edit
@form = IdentificationNumberForm.new
render :edit
end

def update
@form = IdentificationNumberForm.new(identification_number_form_params)
hashed_ssn = SsnHashingService.hash(identification_number_form_params[:ssn])
archived_intake = StateFileArchivedIntake.find_by(email_address: session[:archived_intake_email_address])

if hashed_ssn == archived_intake.hashed_ssn
StateFileArchivedIntakeAccessLog.create!(
ip_address: ip_for_irs,
details: { hashed_ssn: @form.email_address },
event_type: 0,
state_file_archived_intake: archived_intake
)
else
StateFileArchivedIntakeAccessLog.create!(
ip_address: ip_for_irs,
details: { hashed_ssn: @form.email_address },
event_type: 0,
)
end
end

def identification_number_form_params
params.require(:state_file_archived_intakes_identification_number_form).permit(:ssn)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def update
@form = VerificationCodeForm.new(verification_code_form_params)

if @form.save
redirect_to root_path
redirect_to state_file_archived_intakes_edit_identification_number_path
else
render :edit
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module StateFile
module ArchivedIntakes
class IdentificationNumberForm < Form
validates :ssn, social_security_number: true, presence: true

def initialize(attributes = {})
super
assign_attributes(attributes)
end

def save
run_callbacks :save do
valid?
end
end
end
end
end
12 changes: 7 additions & 5 deletions app/models/state_file_archived_intake_access_log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@
class StateFileArchivedIntakeAccessLog < ApplicationRecord
belongs_to :state_file_archived_intake, foreign_key: :state_file_archived_intakes_id, optional: true
enum event_type: {
issued_email_challenge: 0,
correct_email_code: 1,
incorrect_email_code: 2,
issued_ssn_challenge: 3,
correct_email_address: 0, # redundant
incorrect_email_address: 0, # redundant
incorrect_email_address: 0,
correct_verification_code: 1,
incorrect_verification_code: 2,
issued_ssn_challenge: 3, # redundant
correct_ssn_challenge: 4,
incorrect_ssn_challenge: 5,
client_lockout_begin: 6,
client_lockout_end: 7,
issued_mailing_address_challenge: 8,
issued_mailing_address_challenge: 8, # redundant
correct_mailing_address: 9,
incorrect_mailing_address: 10,
issued_pdf_download_link: 11,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<% title ="title" %>
<h1 class="h2" id="main-question"><%= title %></h1>
<p><%= "help_text" %></p>

<%= form_with model: @form, url: state_file_archived_intakes_identification_number_path, local: true, method: :patch, builder: VitaMinFormBuilder do |f| %>
<div class="white-group">
<%= f.cfa_input_field(:ssn, "ssn_label", classes: ["form-width--long"]) %>
</div>
<%= f.submit t("general.continue"), class: "button button--primary button--wide spacing-below-15" %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<% content_for :page_title, t(".title") do %>
<% end %>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,8 @@ def scoped_navigation_routes(context, navigation)
patch 'email_address', to: 'email_address#update'
get 'verification_code/edit', to: 'verification_code#edit', as: 'edit_verification_code'
patch 'verification_code', to: 'verification_code#update'
get 'identification_number/edit', to: 'identification_number#edit', as: 'edit_identification_number'
patch 'identification_number', to: 'identification_number#update'
end
namespace :questions do
get "show_xml", to: "confirmation#show_xml"
Expand Down
28 changes: 27 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1683,6 +1683,30 @@
t.index ["record_type", "record_id"], name: "index_state_file_analytics_on_record"
end

create_table "state_file_archived_intake_access_logs", force: :cascade do |t|
t.datetime "created_at", null: false
t.jsonb "details", default: "{}"
t.integer "event_type"
t.string "ip_address"
t.bigint "state_file_archived_intakes_id"
t.datetime "updated_at", null: false
t.index ["state_file_archived_intakes_id"], name: "idx_on_state_file_archived_intakes_id_e878049c06"
end

create_table "state_file_archived_intakes", force: :cascade do |t|
t.datetime "created_at", null: false
t.string "email_address"
t.string "hashed_ssn"
t.string "mailing_apartment"
t.string "mailing_city"
t.string "mailing_state"
t.string "mailing_street"
t.string "mailing_zip"
t.string "state_code"
t.integer "tax_year"
t.datetime "updated_at", null: false
end

create_table "state_file_az1099_r_followups", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
Expand Down Expand Up @@ -1757,7 +1781,6 @@
t.bigint "spouse_state_id_id"
t.string "spouse_suffix"
t.integer "spouse_was_incarcerated", default: 0, null: false
t.integer "ssn_no_employment", default: 0, null: false
t.integer "tribal_member", default: 0, null: false
t.decimal "tribal_wages_amount", precision: 12, scale: 2
t.text "unfinished_intake_ids", default: [], array: true
Expand Down Expand Up @@ -2775,6 +2798,8 @@
add_foreign_key "incoming_text_messages", "clients"
add_foreign_key "intake_archives", "intakes", column: "id"
add_foreign_key "intakes", "clients"
add_foreign_key "intakes", "drivers_licenses", column: "primary_drivers_license_id"
add_foreign_key "intakes", "drivers_licenses", column: "spouse_drivers_license_id"
add_foreign_key "intakes", "intakes", column: "matching_previous_year_intake_id"
add_foreign_key "intakes", "vita_partners"
add_foreign_key "notes", "clients"
Expand All @@ -2789,6 +2814,7 @@
add_foreign_key "site_coordinator_roles_vita_partners", "site_coordinator_roles"
add_foreign_key "site_coordinator_roles_vita_partners", "vita_partners"
add_foreign_key "source_parameters", "vita_partners"
add_foreign_key "state_file_archived_intake_access_logs", "state_file_archived_intakes", column: "state_file_archived_intakes_id"
add_foreign_key "state_routing_fractions", "state_routing_targets"
add_foreign_key "state_routing_fractions", "vita_partners"
add_foreign_key "system_notes", "clients"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require "rails_helper"

RSpec.describe StateFile::ArchivedIntakes::IdentificationNumberController, type: :controller do
describe "GET #edit" do
it "renders the edit template with a new IdentificationNumberForm" do
get :edit

expect(assigns(:form)).to be_a(StateFile::ArchivedIntakes::IdentificationNumberForm)
expect(response).to render_template(:edit)
end
end

describe "POST #update" do
let(:email_address) { "[email protected]" }
let(:ip_address) { "127.0.0.1" }

before do
allow(controller).to receive(:ip_for_irs).and_return(ip_address)
end

context "when the form is valid" do

it "creates an access log and redirects to the verification code page" do
post :update, params: {
state_file_archived_intakes_email_address_form: { email_address: valid_email_address }
}
expect(assigns(:form)).to be_valid

access_log = StateFileArchivedIntakeAccessLog.last
expect(access_log.ip_address).to eq(ip_address)
expect(access_log.details["email_address"]).to eq(valid_email_address)
expect(access_log.event_type).to eq("issued_email_challenge")

expect(response).to redirect_to(
state_file_archived_intakes_edit_verification_code_path(email_address: valid_email_address)
)
end
end

context "when the form is invalid" do
it "renders the edit template" do
post :update, params: {
state_file_archived_intakes_email_address_form: { email_address: invalid_email_address }
}

expect(assigns(:form)).not_to be_valid

expect(StateFileArchivedIntakeAccessLog.count).to eq(0)

expect(response).to render_template(:edit)
end
end
end
end

0 comments on commit 771f228

Please sign in to comment.