Skip to content
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

Prevent accepted resubmit #187434120 #4504

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions app/forms/state_file/esign_declaration_form.rb
Expand Up @@ -17,6 +17,13 @@ def save
efile_info = StateFileEfileDeviceInfo.find_by(event_type: "submission", intake: @intake)
efile_info&.update!(attributes_for(:state_file_efile_device_info))

unless Flipper.enabled?(:allow_duplicate_submissions)
if accepted_submissions_with_same_ssn(@intake).any?
Rails.logger.warn "#{@intake.state_code}#{@intake.id} was not submitted because there is already an accepted submission for that ssn"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this sufficient notification? would it be worth elevating this to a slack message or sentry warning or similar?

return
end
end

old_efile_submission = @intake.efile_submissions&.last
if old_efile_submission.present?
# the after_transitions :resubmission creates a new efile submission and transitions it to :preparing
Expand All @@ -32,5 +39,16 @@ def save
end
end
end

def accepted_submissions_with_same_ssn(intake)
table_name = intake.class.table_name
class_name = intake.class.name
EfileSubmission
.joins("INNER JOIN #{table_name} ON efile_submissions.data_source_type='#{class_name}' AND efile_submissions.data_source_id = #{table_name}.id")
.joins(:efile_submission_transitions)
.where(efile_submission_transitions: { to_state: :accepted })
.where(table_name => { hashed_ssn: intake.hashed_ssn })
.where.not(efile_submissions: {id: intake.id})
end
end
end
1 change: 1 addition & 0 deletions config/initializers/flipper.rb
Expand Up @@ -10,6 +10,7 @@
begin
Flipper.disable :sms_notifications unless Flipper.exist?(:sms_notifications)
Flipper.enable :w2_override unless Flipper.exist?(:w2_override)
Flipper.disable :allow_duplicate_submissions unless Flipper.exist?(:allow_duplicate_submissions)
rescue
# make sure we can still run rake tasks before table has been created
nil
Expand Down
34 changes: 34 additions & 0 deletions spec/forms/state_file/esign_declaration_form_spec.rb
Expand Up @@ -122,6 +122,40 @@
expect(intake.reload.efile_submissions.last.current_state).to eq("accepted")
end
end

context "when there is already an accepted submission in a different account with the same SSN" do
let!(:efile_submission) { create :efile_submission, :accepted, :for_state, data_source: intake }
before do
other_intake = create :state_file_az_intake
submission = EfileSubmission.create(data_source: other_intake)
EfileSubmissionTransition.create(to_state: :accepted, efile_submission: submission, most_recent: true, sort_key: 1)
end
it "does not create a new efile submission" do
form = described_class.new(intake, params)
expect(form).to be_valid
expect {
form.save
}.to change(intake.efile_submissions, :count).by(0)
expect(intake.reload.efile_submissions.last.current_state).to eq("accepted")
end
end

context "when there is already a non-accepted submission in a different account with the same SSN" do
#let!(:efile_submission) { create :efile_submission, :accepted, :for_state, data_source: intake }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we nuke this comment?

before do
other_intake = create :state_file_az_intake
submission = EfileSubmission.create(data_source: other_intake)
EfileSubmissionTransition.create(to_state: :rejected, efile_submission: submission, most_recent: true, sort_key: 1)
end
it "creates a new efile submission" do
form = described_class.new(intake, params)
expect(form).to be_valid
expect {
form.save
}.to change(intake.efile_submissions, :count).by(1)
expect(intake.reload.efile_submissions.last.current_state).to eq("bundling")
end
end
end

describe "#validations" do
Expand Down