Skip to content

Commit

Permalink
skip rabbitmq event callbacks for every update on person and lawful_p…
Browse files Browse the repository at this point in the history
…resence obj (#3735)

* skip rabbitmq event callbacks for every save/update on person and lawful_presence_determination object

* set skip_lawful_presence_determination_callbacks in person model

* skip_consumer_role_callbacks

* fire consumer role change events

* re-arrange the nested code

* rubocop fix

* add spec

* update spec

* add spec consumer role changes

* fix typo

* rubocop fix

* fix spec

* fix rubocop
  • Loading branch information
vkghub authored and jacobkagon committed May 15, 2024
1 parent 3dec505 commit effe740
Show file tree
Hide file tree
Showing 6 changed files with 1,833 additions and 1,765 deletions.
50 changes: 33 additions & 17 deletions app/controllers/insured/consumer_roles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,10 @@ def update
save_and_exit = params['exit_after_method'] == 'true'
mec_check(@person.hbx_id) if EnrollRegistry.feature_enabled?(:mec_check) && @person.send(:mec_check_eligible?)
@shop_coverage_result = EnrollRegistry.feature_enabled?(:shop_coverage_check) ? (check_shop_coverage.success? && check_shop_coverage.success.present?) : nil
@consumer_role.skip_consumer_role_callbacks = true
valid_params = {"skip_person_updated_event_callback" => true, "skip_lawful_presence_determination_callbacks" => true}.merge(params.require(:person).permit(*person_parameters_list))

if update_vlp_documents(@consumer_role, 'person') && @consumer_role.update_by_person(params.require(:person).permit(*person_parameters_list))
if update_vlp_documents(@consumer_role, 'person') && @consumer_role.update_by_person(valid_params)
@consumer_role.update_attribute(:is_applying_coverage, params[:person][:is_applying_coverage]) unless params[:person][:is_applying_coverage].nil?
@person.active_employee_roles.each { |role| role.update_attributes(contact_method: params[:person][:consumer_role_attributes][:contact_method]) } if @person.has_multiple_roles?
@person.primary_family.update_attributes(application_type: params["person"]["family"]["application_type"]) if current_user.has_hbx_staff_role?
Expand All @@ -241,22 +243,10 @@ def update
format.html {redirect_to destroy_user_session_path}
end
else
if current_user.has_hbx_staff_role? && (@person.primary_family.application_type == "Paper" || @person.primary_family.application_type == "In Person")
redirect_to upload_ridp_document_insured_consumer_role_index_path
elsif is_new_paper_application?(current_user, session[:original_application_type]) || @person.primary_family.has_curam_or_mobile_application_type?
@person.consumer_role.move_identity_documents_to_verified(@person.primary_family.application_type)
# rubocop:disable Metrics/BlockNesting
consumer_redirection_path = if EnrollRegistry.feature_enabled?(:financial_assistance)
help_paying_coverage_insured_consumer_role_index_path(shop_coverage_result: @shop_coverage_result)
else
insured_family_members_path(:consumer_role_id => @person.consumer_role.id)
end
redirect_path = @consumer_role.admin_bookmark_url.present? ? @consumer_role.admin_bookmark_url : consumer_redirection_path
redirect_to URI.parse(redirect_path).to_s
# rubocop:enable Metrics/BlockNesting
else
redirect_to ridp_agreement_insured_consumer_role_index_path
end
redirect_path = redirect_path_for_update

fire_consumer_roles_update_for_vlp_docs(@consumer_role, @consumer_role.is_applying_coverage)
redirect_to redirect_path
end
else
if save_and_exit
Expand Down Expand Up @@ -350,6 +340,32 @@ def help_paying_coverage_response

private

def redirect_path_for_update
if staff_and_paper_or_in_person_application?
upload_ridp_document_insured_consumer_role_index_path
elsif new_paper_or_cruam_or_mobile_application?
@person.consumer_role.move_identity_documents_to_verified(@person.primary_family.application_type)
admin_bookmark_url_or_help_paying_coverage_path
else
ridp_agreement_insured_consumer_role_index_path
end
end

def staff_and_paper_or_in_person_application?
current_user.has_hbx_staff_role? && (@person.primary_family.application_type == "Paper" || @person.primary_family.application_type == "In Person")
end

def new_paper_or_cruam_or_mobile_application?
is_new_paper_application?(current_user, session[:original_application_type]) || @person.primary_family.has_curam_or_mobile_application_type?
end

def admin_bookmark_url_or_help_paying_coverage_path
return URI.parse(@consumer_role.admin_bookmark_url).to_s if @consumer_role.admin_bookmark_url.present?
return help_paying_coverage_insured_consumer_role_index_path(shop_coverage_result: @shop_coverage_result) if EnrollRegistry.feature_enabled?(:financial_assistance)

insured_family_members_path(consumer_role_id: @person.consumer_role.id)
end

def validate_person_match
first_name = params[:person][:first_name]
last_name = params[:person][:last_name]
Expand Down
2 changes: 1 addition & 1 deletion app/models/consumer_role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ def tribal_with_ssn?
end

def update_by_person(*args)
person.consumer_role.update_attributes(is_applying_coverage: args[0]["is_applying_coverage"])
update_attributes(is_applying_coverage: args[0]["is_applying_coverage"])
args[0].delete("is_applying_coverage")
person.update_attributes(args[0])
end
Expand Down
8 changes: 7 additions & 1 deletion app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,10 @@ def us_citizen=(val)
@naturalized_citizen = false if val.to_s == "false"
end

def skip_lawful_presence_determination_callbacks=(val)
@skip_lawful_presence_determination_callbacks = true if val.to_s == "true"
end

def naturalized_citizen=(val)
@naturalized_citizen = (val.to_s == "true")
end
Expand Down Expand Up @@ -1276,7 +1280,9 @@ def assign_citizen_status
elsif
self.errors.add(:base, "Citizenship status can't be nil.")
end
self.consumer_role.lawful_presence_determination.assign_citizen_status(new_status) if new_status
lawful_presence_determination = self.consumer_role.lawful_presence_determination
lawful_presence_determination.skip_lawful_presence_determination_callbacks = @skip_lawful_presence_determination_callbacks if @skip_lawful_presence_determination_callbacks == true
lawful_presence_determination.assign_citizen_status(new_status) if new_status
end

def agent?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe Insured::ConsumerRolesController do
Expand Down Expand Up @@ -48,7 +50,8 @@
before(:each) do
sign_in(user)
allow(ConsumerRole).to receive(:find).with(consumer_role_id).and_return(consumer_role)
allow(consumer_role).to receive(:update_by_person).with(person_controller_parameters).and_return(true)
allow(consumer_role).to receive(:skip_consumer_role_callbacks=).and_return(true)
allow(consumer_role).to receive(:update_by_person).with({"skip_person_updated_event_callback" => true, "skip_lawful_presence_determination_callbacks" => true}.merge(person_controller_parameters)).and_return(true)
allow(EnrollRegistry[:mec_check].feature).to receive(:is_enabled).and_return(false)
allow(EnrollRegistry[:shop_coverage_check].feature).to receive(:is_enabled).and_return(false)
allow(person).to receive(:mec_check_eligible?).and_return(false)
Expand Down
Loading

0 comments on commit effe740

Please sign in to comment.