Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
15 changes: 15 additions & 0 deletions app/app/controllers/activities/activities_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
class Activities::ActivitiesController < Activities::BaseController
def index
# This is in support of the functionality where we delete any records that were not completed
# on creation. If you exit out of an activity flow in the middle before you save from the
# Review page, we should delete all the records that were not completed. This results in no
# visible changes when the user returns to the Activity Hub.
if session[:creating_activity]
activity_class = session[:creating_activity]["class_name"].safe_constantize
activity_class&.find_by(id: session[:creating_activity]["id"])&.destroy
session.delete(:creating_activity)
end

if session[:creating_payroll_account]
@flow.payroll_accounts.find_by(aggregator_account_id: session[:creating_payroll_account])&.destroy
session.delete(:creating_payroll_account)
end

unless @flow.identity
@flow.identity = IdentityService.new(request, @flow.cbv_applicant).get_identity
@flow.save
Expand Down
16 changes: 16 additions & 0 deletions app/app/controllers/activities/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ def progress_calculator
@_progress_calculator ||= ActivityFlowProgressCalculator.new(@flow)
end

def track_creating_activity(activity)
session[:creating_activity] = { "class_name" => activity.class.name, "id" => activity.id }
end

def clear_creating_activity
session.delete(:creating_activity)
end

def track_creating_payroll_account(aggregator_account_id)
session[:creating_payroll_account] = aggregator_account_id
end

def clear_creating_payroll_account
session.delete(:creating_payroll_account)
end

def flow_param
:activity
end
Expand Down
3 changes: 3 additions & 0 deletions app/app/controllers/activities/education_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def review

def save_review
@education_activity.update(review_params)
clear_creating_activity
redirect_to @education_activity.fully_self_attested? ? activities_flow_root_path : after_activity_path
end

Expand Down Expand Up @@ -172,6 +173,7 @@ def create_fully_self_attested_activity
@education_activity = @flow.education_activities.new(fully_self_attested_education_params)
@education_activity.data_source = :fully_self_attested
if @education_activity.save
track_creating_activity(@education_activity)
redirect_to edit_activities_flow_education_month_path(education_id: @education_activity, id: 0)
else
render :new, status: :unprocessable_content
Expand All @@ -180,6 +182,7 @@ def create_fully_self_attested_activity

def create_validated_activity
@education_activity = @flow.education_activities.create
track_creating_activity(@education_activity)
NscSynchronizationJob.perform_later(@education_activity.id)
redirect_to activities_flow_education_path(id: @education_activity.id)
end
Expand Down
2 changes: 2 additions & 0 deletions app/app/controllers/activities/employment_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def new
def create
@employment_activity = @flow.employment_activities.new(employment_activity_params)
if @employment_activity.save
track_creating_activity(@employment_activity)
redirect_to edit_activities_flow_income_employment_month_path(employment_id: @employment_activity, id: 0)
else
render :new, status: :unprocessable_content
Expand Down Expand Up @@ -49,6 +50,7 @@ def review

def save_review
@employment_activity.update(review_params)
clear_creating_activity
redirect_to after_activity_path
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def update
end

@payroll_account.update(payroll_account_params)
clear_creating_payroll_account

redirect_to next_path
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Activities::Income::SynchronizationsController < Activities::BaseController
before_action :set_payroll_account, only: %i[show update]
before_action :track_payroll_account_creation, only: %i[show]
before_action :redirect_if_session_was_reset, only: %i[update]
before_action :redirect_if_sync_finished, only: %i[show]

Expand All @@ -23,6 +24,10 @@ def update

private

def track_payroll_account_creation
track_creating_payroll_account(params[:user][:account_id])
end

def session_timeout_enabled?
false
end
Expand Down
2 changes: 2 additions & 0 deletions app/app/controllers/activities/job_training_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def new
def create
@job_training_activity = @flow.job_training_activities.new(job_training_activity_params)
if @job_training_activity.save
track_creating_activity(@job_training_activity)
redirect_to edit_activities_flow_job_training_month_path(job_training_id: @job_training_activity, id: 0)
else
render :new, status: :unprocessable_content
Expand Down Expand Up @@ -45,6 +46,7 @@ def review

def save_review
@job_training_activity.update(review_params)
clear_creating_activity
redirect_to after_activity_path
end

Expand Down
2 changes: 2 additions & 0 deletions app/app/controllers/activities/volunteering_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def new
def create
@volunteering_activity = @flow.volunteering_activities.new(volunteering_activity_params)
if @volunteering_activity.save
track_creating_activity(@volunteering_activity)
redirect_to edit_activities_flow_community_service_month_path(community_service_id: @volunteering_activity, id: 0)
else
render :new, status: :unprocessable_content
Expand Down Expand Up @@ -45,6 +46,7 @@ def review

def save_review
@volunteering_activity.update(review_params)
clear_creating_activity
redirect_to after_activity_path
end

Expand Down
3 changes: 2 additions & 1 deletion app/app/models/payroll_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def self.sti_class_for(type_name)

belongs_to :flow, polymorphic: true
validates :flow, presence: true
has_many :webhook_events
has_many :webhook_events, dependent: :destroy
has_many :activity_flow_monthly_summaries, dependent: :destroy

enum :data_source, { self_attested: "self_attested", validated: "validated" }, default: :validated

Expand Down
22 changes: 16 additions & 6 deletions app/app/models/payroll_account/argyle.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class PayrollAccount::Argyle < PayrollAccount
before_destroy :safely_delete_aggregator_account

scope :awaiting_fully_synced_webhook, -> do
joins(<<~SQL).where(webhook_events: { id: nil })
LEFT OUTER JOIN webhook_events
Expand Down Expand Up @@ -59,14 +61,22 @@ def sync_started_at
account_connected_at || created_at
end

def redact!
def safely_delete_aggregator_account
delete_aggregator_account
rescue => ex
Rails.logger.error "Unable to delete Argyle account #{aggregator_account_id}: #{ex.message}"
end

def delete_aggregator_account
argyle_environment = Rails.application.config.client_agencies[flow.cbv_applicant.client_agency_id].argyle_environment
argyle = Aggregators::Sdk::ArgyleService.new(argyle_environment)
begin
argyle.delete_account_api(account: aggregator_account_id)
rescue Faraday::ResourceNotFound
# Account already deleted on Argyle's side — safe to proceed with local redaction
end
argyle.delete_account_api(account: aggregator_account_id)
rescue Faraday::ResourceNotFound
# Account already deleted on Argyle's side
end

def redact!
delete_aggregator_account
update_column(:additional_information, Redactable::REDACTION_REPLACEMENTS[:string])
touch(:redacted_at)
rescue => ex
Expand Down
45 changes: 45 additions & 0 deletions app/spec/controllers/activities/activities_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,51 @@
end
end

describe "delete-on-close cleanup" do
let(:current_flow) { create(:activity_flow, volunteering_activities_count: 0, job_training_activities_count: 0, education_activities_count: 0) }

before do
session[:flow_id] = current_flow.id
session[:flow_type] = :activity
end

it "destroys the tracked incomplete activity on hub visit" do
activity = create(:volunteering_activity, activity_flow: current_flow)
session[:creating_activity] = { "class_name" => "VolunteeringActivity", "id" => activity.id }

expect { get :index }.to change(VolunteeringActivity, :count).by(-1)
expect(session[:creating_activity]).to be_nil
end

it "does nothing when no creating_activity is in session" do
create(:volunteering_activity, activity_flow: current_flow)

expect { get :index }.not_to change(VolunteeringActivity, :count)
end

it "handles an already-deleted activity gracefully" do
session[:creating_activity] = { "class_name" => "VolunteeringActivity", "id" => -1 }

expect { get :index }.not_to raise_error
expect(session[:creating_activity]).to be_nil
end

it "destroys a tracked incomplete payroll account on hub visit" do
payroll_account = create(:payroll_account, :pinwheel_fully_synced, flow: current_flow)
session[:creating_payroll_account] = payroll_account.aggregator_account_id

expect { get :index }.to change(current_flow.payroll_accounts, :count).by(-1)
expect(session[:creating_payroll_account]).to be_nil
end

it "handles an already-deleted payroll account gracefully" do
session[:creating_payroll_account] = "nonexistent-account-id"

expect { get :index }.not_to raise_error
expect(session[:creating_payroll_account]).to be_nil
end
end

context "when no activities are added" do
let(:current_flow) do
create(:activity_flow, volunteering_activities_count: 0, job_training_activities_count: 0, education_activities_count: 0)
Expand Down
22 changes: 22 additions & 0 deletions app/spec/controllers/activities/education_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
expect(response).to redirect_to(activities_flow_education_path(id: EducationActivity.last.id))
end

it "tracks the validated activity in the session" do
post :create

activity = EducationActivity.last
expect(session[:creating_activity]).to eq("class_name" => "EducationActivity", "id" => activity.id)
end

it "creates a self-attested EducationActivity and redirects to month 0" do
expect {
post :create, params: { education_activity: { school_name: "Test University", city: "Springfield", state: "IL", zip_code: "62701", street_address: "123 Main St" } }
Expand All @@ -52,6 +59,13 @@
expect(response).to redirect_to(edit_activities_flow_education_month_path(education_id: activity.id, id: 0))
end

it "tracks the self-attested activity in the session" do
post :create, params: { education_activity: { school_name: "Test University", city: "Springfield", state: "IL", zip_code: "62701", street_address: "123 Main St" } }

activity = EducationActivity.last
expect(session[:creating_activity]).to eq("class_name" => "EducationActivity", "id" => activity.id)
end

it "re-renders the form when self-attested params are invalid" do
post :create, params: { education_activity: { school_name: "" } }

Expand Down Expand Up @@ -382,6 +396,14 @@
expect(response).to redirect_to(activities_flow_root_path)
end

it "clears the creating_activity session" do
session[:creating_activity] = { "class_name" => "EducationActivity", "id" => education_activity.id }

patch :save_review, params: { id: education_activity.id, education_activity: { additional_comments: "" } }

expect(session[:creating_activity]).to be_nil
end

context "when validated mixed enrollment has half-time-or-above in each reporting month" do
let(:activity_flow) do
create(
Expand Down
15 changes: 15 additions & 0 deletions app/spec/controllers/activities/employment_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@
activity = activity_flow.employment_activities.last
expect(activity.data_source).to eq("self_attested")
end

it "tracks the new activity in the session" do
post :create, params: employment_params

activity = activity_flow.employment_activities.last
expect(session[:creating_activity]).to eq("class_name" => "EmploymentActivity", "id" => activity.id)
end
end

describe "PATCH #update" do
Expand Down Expand Up @@ -214,5 +221,13 @@
expect(employment_activity.reload.additional_comments).to eq("Some notes")
expect(response).to redirect_to(activities_flow_root_path)
end

it "clears the creating_activity session" do
session[:creating_activity] = { "class_name" => "EmploymentActivity", "id" => employment_activity.id }

patch :save_review, params: { id: employment_activity.id, employment_activity: { additional_comments: "" } }

expect(session[:creating_activity]).to be_nil
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@
.to(comment)
end

it "clears the creating_payroll_account session" do
session[:creating_payroll_account] = account_id

patch :update, params: {
user: { account_id: account_id },
payroll_account: { additional_information: comment }
}

expect(session[:creating_payroll_account]).to be_nil
end

it "tracks saved payment details with activity_flow_id" do
allow(EventTrackingJob).to receive(:perform_later).with("CbvPageView", anything, anything)
expect(EventTrackingJob).to receive(:perform_later).with("ApplicantSavedPaymentDetails", anything, hash_including(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
session[:flow_type] = :activity
end

describe "#show" do
it "tracks the payroll account in the session" do
get :show, params: { user: { account_id: payroll_account.aggregator_account_id } }

expect(session[:creating_payroll_account]).to eq(payroll_account.aggregator_account_id)
end
end

describe "#update" do
context "when account exists but is not fully synced" do
before do
Expand Down
15 changes: 15 additions & 0 deletions app/spec/controllers/activities/job_training_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
expect(response).to redirect_to(edit_activities_flow_job_training_month_path(job_training_id: created_activity.id, id: 0))
end

it "tracks the new activity in the session" do
post :create, params: job_training_params

activity = activity_flow.job_training_activities.last
expect(session[:creating_activity]).to eq("class_name" => "JobTrainingActivity", "id" => activity.id)
end

it "redirects to month 0 when total hours are below the threshold" do
create(:volunteering_activity, activity_flow: activity_flow, organization_name: "Local Food Bank", hours: 78)

Expand Down Expand Up @@ -144,6 +151,14 @@
expect(job_training_activity.reload.additional_comments).to eq("Some notes")
expect(response).to redirect_to(activities_flow_root_path)
end

it "clears the creating_activity session" do
session[:creating_activity] = { "class_name" => "JobTrainingActivity", "id" => job_training_activity.id }

patch :save_review, params: { id: job_training_activity.id, job_training_activity: { additional_comments: "" } }

expect(session[:creating_activity]).to be_nil
end
end

describe "DELETE #destroy" do
Expand Down
Loading
Loading