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

Hub and efile submission page cleanups #4382

Merged
merged 8 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion app/controllers/hub/efile_submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def failed

authorize! :update, @efile_submission
@efile_submission.transition_to!(:failed, { initiated_by_id: current_user.id })
flash[:notice] = "Transition to failed (for testing purpose only)"
flash[:notice] = "Transitioned to failed (for testing purpose only)"
redirect_after_action
end

Expand All @@ -52,6 +52,15 @@ def cancel
redirect_after_action
end

def reject
return if Rails.env.production?

authorize! :update, @efile_submission
@efile_submission.transition_to!(:rejected, error_code: EfileError.where(service_type: :state_file).last.code)
flash[:notice] = "Transitioned to rejected (for testing purpose only)"
redirect_after_action
end

def investigate
authorize! :update, @efile_submission
@efile_submission.transition_to!(:investigating, { initiated_by_id: current_user.id })
Expand Down
7 changes: 6 additions & 1 deletion app/state_machines/efile_submission_state_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class EfileSubmissionStateMachine
transition from: :queued, to: [:transmitted, :failed]
transition from: :transmitted, to: [:accepted, :rejected, :failed, :ready_for_ack, :transmitted, :notified_of_rejection]
transition from: :ready_for_ack, to: [:accepted, :rejected, :failed, :ready_for_ack, :notified_of_rejection]
transition from: :failed, to: [:resubmitted, :cancelled, :investigating, :waiting, :fraud_hold]
transition from: :failed, to: [:resubmitted, :cancelled, :investigating, :waiting, :fraud_hold, :rejected]
transition from: :rejected, to: [:resubmitted, :cancelled, :investigating, :waiting, :fraud_hold, :notified_of_rejection]
transition from: :notified_of_rejection, to: [:resubmitted, :cancelled, :investigating, :waiting, :fraud_hold]
transition from: :investigating, to: [:resubmitted, :cancelled, :waiting, :fraud_hold]
Expand All @@ -46,6 +46,11 @@ class EfileSubmissionStateMachine
submission.is_for_state_filing? || submission.fraud_score.present?
end

guard_transition(from: :failed, to: :rejected) do |_submission|
# we need this for testing since submissions will fail on bundle in heroku and staging
!Rails.env.production?
end

after_transition(to: :preparing) do |submission|
submission.create_qualifying_dependents
if submission.is_for_federal_filing?
Expand Down
37 changes: 29 additions & 8 deletions app/views/hub/state_file/efile_errors/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,53 @@
<hr/>
<h2>Options</h2>
<%= form_with model: @efile_error, method: :put, local: true, url: hub_state_file_efile_error_path, builder: VitaMinFormBuilder do |f| %>
<%= f.hub_checkbox :expose, "Exposed to client? (exposes reject code and description on return-status page)" %>
<%= f.hub_checkbox :auto_cancel, "Auto-cancel?" %>
<%= f.hub_checkbox :auto_wait, "Auto-wait? (shows terminal reject state on return-status page)" %>
<div>
<%= f.label "Correction Path" %><br />
<span class="tooltip" data-position="right" title="will expose the error code & message and/or custom description & resolution on the /return-status page">
<%= f.hub_checkbox :expose, "Exposed to client?" %>
</span>
</div>

<div>
<span class="tooltip" data-position="right" title="will show 'what can I do next' text on /return-status page">
<%= f.hub_checkbox :auto_cancel, "Auto-cancel?" %>
</span>
</div>

<div>
<span class="tooltip" data-position="right" title="will allow the client to resubmit their return">
<%= f.hub_checkbox :auto_wait, "Auto-wait?" %>
</span>
</div>

<div>
<%= f.label "Correction Path", class: "h4" %>
<p class="help-text">directs clients to path when resubmitting</p>
<%= f.select :correction_path, @correction_path_options_for_select, selected: @efile_error.correction_path %>
</div>

<div class="spacing-above-25">
<%= f.label :description_en, "Description [English] (overwrites default reject description on return-status page)", class: "h4" %>
<%= f.label :description_en, "English Description", class: "h4" %>
<p class="help-text">overwrites default reject description on <em>en/questions/return-status</em> page if exposed</p>
<%= f.rich_text_area :description_en %>
</div>

<div class="spacing-above-25">
<%= f.label :description_es, "Description [Spanish]", class: "h4" %>
<%= f.label :description_es, "Spanish Description", class: "h4" %>
<p class="help-text">overwrites default reject description on <em>es/questions/return-status</em> page if exposed</p>
<%= f.rich_text_area :description_es %>
</div>


<div class="spacing-above-25">
<%= f.label :resolution_en, "Resolution [English] (overwrites default 'what's next' message on return-status page)", class: "h4" %>
<%= f.label :resolution_en, "English Resolution", class: "h4" %>
<p class="help-text">overwrites default 'what's next' message on <em>en/questions/return-status</em> page if exposed and auto-wait true</p>
<%= f.rich_text_area :resolution_en %>
</div>


<div class="spacing-above-25">
<%= f.label :resolution_es, "Resolution [Spanish]", class: "h4" %>
<%= f.label :resolution_es, "Spanish Resolution", class: "h4" %>
<p class="help-text">overwrites default 'what's next' message on <em>en/questions/return-status</em> page if exposed and auto-wait true</p>
<%= f.rich_text_area :resolution_es %>
</div>

Expand Down
46 changes: 8 additions & 38 deletions app/views/hub/state_file/efile_submissions/_log.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% transmitted_transitions = transitions.select { |t| t.to_state == "transmitted" } %>
<% if transitions.present? %>
<% transitions.each do |transition| %>
<% transitions&.each do |transition| %>
<% transmitted_transitions = transitions.select { |t| t.to_state == "transmitted" } %>
<% unless transmitted_transitions.include?(transition) && transition != transmitted_transitions.first %>
<li role="listitem">
<div class="timestamp"><%= timestamp transition.created_at %></div>
Expand All @@ -12,49 +12,19 @@

<% transition.efile_errors.each do |error| %>
<div>
<strong><%= "#{error.code}" if error.code.present? %></strong>
<span class="tooltip max-250 error-<%= error.id %>" data-position="left" title="<%= error.message %>">
<%= link_to hub_state_file_efile_error_path(id: error.id) do %>
<div class="label label--red"><%= error.code %></div>
<% end %>
</span>
<%= error.message %>
</div>
<% end %>

<% if transition.to_state == "transmitted" %>
<table>
<tr>
<th>date</th>
<th>submission status</th>
</tr>
<% transmitted_transitions.each do |t| %>
<% if t.metadata["raw_response"].present? %>
<% xml = Nokogiri::XML(t.metadata["raw_response"]) %>
<tr>
<td>
<%= xml.css("SubmsnStatusAcknowledgementDt").text.strip %>
</td>
<td>
<%= xml.css("SubmissionStatusTxt").text.strip %>
</td>
</tr>
<% elsif t.metadata["receipt"] %>
<% xml = Nokogiri::XML(t.metadata["receipt"]) %>
<tr>
<td>
<%= DateTime.parse(xml.css("SubmissionReceivedTs").text.strip).strftime("%Y-%m-%d %H:%M") %>
</td>
<td>Submission received</td>
</tr>
<% end %>
<% end %>
</table>
<%= render 'log_transmitted', transmitted_transitions: transmitted_transitions %>
<% end %>

<% if ["failed", "rejected"].include?(transition.to_state) && transition.metadata["raw_response"].present? && !transition.metadata["raw_response"].kind_of?(Array) %>
<% xml = Nokogiri::XML(transition.metadata["raw_response"]) %>
<% error_msg = xml.css("ErrorMessageTxt").text.strip %>
<% if error_msg.present? %>
<p><strong>Error message:</strong> <%= error_msg %></p>
<% end %>
<% end %>

<% if transition.metadata.present? %>
<div class="accordion spacing-above-10">
<a href="#" class="accordion__button" aria-expanded="true" aria-controls="a2">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<div class="grid">
<div class="grid__item width-one-half">
<table class="fixed-width-table data-table">
<tr>
<th>Date</th>
<th>Sub-status</th>
</tr>
<% transmitted_transitions.each do |t| %>
<% if t.metadata["raw_response"].present? %>
<% xml = Nokogiri::XML(t.metadata["raw_response"]) %>
<tr>
<td>
<%= xml.css("SubmsnStatusAcknowledgementDt").text.strip %>
</td>
<td>
<%= xml.css("SubmissionStatusTxt").text.strip %>
</td>
</tr>
<% elsif t.metadata["receipt"] %>
<% xml = Nokogiri::XML(t.metadata["receipt"]) %>
<tr>
<td>
<%= DateTime.parse(xml.css("SubmissionReceivedTs").text.strip).strftime("%Y-%m-%d %H:%M") %>
</td>
<td>Submission received</td>
</tr>
<% end %>
<% end %>
</table>
</div>
</div>
6 changes: 4 additions & 2 deletions app/views/hub/state_file/efile_submissions/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@
<%= link_to submission.current_state.humanize(capitalize: false), hub_state_file_efile_submission_path(id: submission.id), class: "underline" %>
</td>
<td class="index-table__cell">
<% submission.last_transition&.efile_errors&.each do |error| %>
<span class="tooltip max-250 error-<%= error.id %>" data-position="left" title="<%= error.message %>">
<% errors = submission.last_transition&.efile_errors %>
<% errors = submission&.efile_submission_transitions&.where(to_state: 'rejected')&.last&.efile_errors if ['waiting', 'notified_of_rejection'].include?(submission.current_state) %>
<% errors&.each do |error| %>
Copy link
Contributor

@rickreyhsig rickreyhsig Mar 22, 2024

Choose a reason for hiding this comment

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

For for readability sakes:

<% if ['waiting', 'notified_of_rejection'].include?(submission.current_state)
    errors = submission&.efile_submission_transitions&.where(to_state: 'rejected')&.last&.efile_errors  
end
%>

<span class="tooltip max-250 error-<%= error.id %>" data-position="right" title="<%= error.message %>">
<%= link_to hub_state_file_efile_error_path(id: error.id) do %>
<div class="label label--red"><%= error.code %></div>
<% end %>
Expand Down
10 changes: 10 additions & 0 deletions app/views/hub/state_file/efile_submissions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@
class: "button button--danger button--small") %>
</div>
<% end %>

<% if @efile_submission.can_transition_to?(:rejected) && !Rails.env.production? %>
<div style="margin-left: 10px">
<%= link_to("Rejected",
reject_hub_efile_submission_path(id: @efile_submission.id),
method: :patch,
data: { confirm: "Are you sure you want to mark this tax return submission as 'Rejected'?" },
class: "button button--danger button--small") %>
</div>
<% end %>
</div>
<div class="log-wrapper">
<h4 class="spacing-below-10">Status Logs</h4>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ def scoped_navigation_routes(context, navigation)
resources :efile_submissions, path: "efile", only: [:index, :show] do
patch '/resubmit', to: 'efile_submissions#resubmit', on: :member, as: :resubmit
patch '/failed', to: 'efile_submissions#failed', on: :member, as: :failed
patch '/reject', to: 'efile_submissions#reject', on: :member, as: :reject
patch '/cancel', to: 'efile_submissions#cancel', on: :member, as: :cancel
patch '/investigate', to: 'efile_submissions#investigate', on: :member, as: :investigate
patch '/notify_of_rejection', to: 'efile_submissions#notify_of_rejection', on: :member, as: :notify_of_rejection
Expand Down
25 changes: 25 additions & 0 deletions spec/state_machines/efile_submission_state_machine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,31 @@
expect(AfterTransitionTasksForRejectedReturnJob).to have_been_enqueued.with(submission, submission.last_transition)
end

context "transition from failed" do
let(:submission) { create(:efile_submission, :failed) }

context "in prod" do
before do
allow(Rails.env).to receive(:production?).and_return(true)
end

it "raises an error" do
expect { submission.transition_to!(:rejected) }.to raise_error(Statesman::GuardFailedError)
end
end

context "in heroku" do
before do
allow(Rails.env).to receive(:heroku?).and_return(true)
end

it "succeeds in transitioning to rejected" do
submission.transition_to!(:rejected)
expect(submission.current_state).to eq "rejected"
end
end
end

context "schedule job for still processing notice" do
context "for state filing" do
it "enqueues StateFile::SendStillProcessingNoticeJob with run time at 24 hours from now" do
Expand Down
Loading