The personal finance app for everyone (by everyone)
Ruby
Keep Add Account errors visible when provider setup can't open (#4278)
alexcastgonz59b65e0d5382
diff --git a/app/controllers/akahu_items_controller.rb b/app/controllers/akahu_items_controller.rbindex 6cfbd8c9da..dfbe969255 100644--- a/app/controllers/akahu_items_controller.rb+++ b/app/controllers/akahu_items_controller.rb@@ -74,7 +74,7 @@ class AkahuItemsController < ApplicationController@akahu_item = requested_akahu_itemunless @akahu_item.credentials_configured?- redirect_to settings_providers_path, alert: t(".no_credentials_configured")+ frame_redirect_to settings_providers_path, alert: t(".no_credentials_configured")returnenddiff --git a/app/controllers/concerns/stream_extensions.rb b/app/controllers/concerns/stream_extensions.rbindex 978d5bfbca..4a1a62c61b 100644--- a/app/controllers/concerns/stream_extensions.rb+++ b/app/controllers/concerns/stream_extensions.rb@@ -9,6 +9,22 @@ module StreamExtensionscustom_stream_redirect(path, redirect_back: true, notice: notice, alert: alert)end+ # A request made inside a turbo frame (such as the Add Account "modal" frame)+ # follows a plain redirect within the frame, so the page stays behind the+ # frame and its flash is never shown. Answer such requests with the frame+ # carrying a redirect stream action, which performs a full-page visit; other+ # requests get a normal redirect.+ def frame_redirect_to(path, notice: nil, alert: nil)+ return redirect_to(path, notice: notice, alert: alert) unless turbo_frame_request?++ flash[:notice] = notice if notice.present?+ flash[:alert] = alert if alert.present?++ render html: helpers.turbo_frame_tag(turbo_frame_request_id) {+ helpers.turbo_stream.action(:redirect, path)+ }+ end+privatedef custom_stream_redirect(path, redirect_back: false, notice: nil, alert: nil)flash[:notice] = notice if notice.present?diff --git a/app/controllers/fio_items_controller.rb b/app/controllers/fio_items_controller.rbindex 4316cebd81..69f6b39e34 100644--- a/app/controllers/fio_items_controller.rb+++ b/app/controllers/fio_items_controller.rb@@ -116,7 +116,7 @@ class FioItemsController < ApplicationController@fio_item = requested_fio_itemunless @fio_item.credentials_configured?- redirect_to settings_providers_path, alert: t(".no_credentials_configured")+ frame_redirect_to settings_providers_path, alert: t(".no_credentials_configured")returnenddiff --git a/app/controllers/ibkr_items_controller.rb b/app/controllers/ibkr_items_controller.rbindex 4579f44e20..0a859f76cb 100644--- a/app/controllers/ibkr_items_controller.rb+++ b/app/controllers/ibkr_items_controller.rb@@ -53,7 +53,7 @@ class IbkrItemsController < ApplicationControllerdef select_accountsibkr_item = current_ibkr_itemunless ibkr_item- redirect_to settings_providers_path, alert: t(".not_configured")+ frame_redirect_to settings_providers_path, alert: t(".not_configured")returnenddiff --git a/app/controllers/indexa_capital_items_controller.rb b/app/controllers/indexa_capital_items_controller.rbindex 8649ff39b2..58a3310b3c 100644--- a/app/controllers/indexa_capital_items_controller.rb+++ b/app/controllers/indexa_capital_items_controller.rb@@ -75,7 +75,7 @@ class IndexaCapitalItemsController < ApplicationControllerindexa_capital_item = Current.family.indexa_capital_items.firstunless indexa_capital_item&.credentials_configured?- redirect_to settings_providers_path, alert: t(".no_credentials_configured")+ frame_redirect_to settings_providers_path, alert: t(".no_credentials_configured")returnenddiff --git a/app/controllers/monobank_items_controller.rb b/app/controllers/monobank_items_controller.rbindex 21b2c8fa99..ee9fbe7d25 100644--- a/app/controllers/monobank_items_controller.rb+++ b/app/controllers/monobank_items_controller.rb@@ -92,7 +92,7 @@ class MonobankItemsController < ApplicationController@monobank_item = requested_monobank_itemunless @monobank_item.credentials_configured?- redirect_to settings_providers_path, alert: t(".no_credentials_configured")+ frame_redirect_to settings_providers_path, alert: t(".no_credentials_configured")returnenddiff --git a/app/controllers/trade_republic_items_controller.rb b/app/controllers/trade_republic_items_controller.rbindex 30b3c56d4b..0f2d529214 100644--- a/app/controllers/trade_republic_items_controller.rb+++ b/app/controllers/trade_republic_items_controller.rb@@ -339,7 +339,7 @@ class TradeRepublicItemsController < ApplicationControllerdef select_accountsitem = current_trade_republic_itemunless item- redirect_to settings_providers_path, alert: t(".not_configured")+ frame_redirect_to settings_providers_path, alert: t(".not_configured")returnenddiff --git a/app/controllers/trading212_items_controller.rb b/app/controllers/trading212_items_controller.rbindex f05a604797..d171c6f144 100644--- a/app/controllers/trading212_items_controller.rb+++ b/app/controllers/trading212_items_controller.rb@@ -49,7 +49,7 @@ class Trading212ItemsController < ApplicationControllerdef select_accountsitem = current_trading212_itemunless item- redirect_to settings_providers_path, alert: t(".not_configured")+ frame_redirect_to settings_providers_path, alert: t(".not_configured")returnenddiff --git a/app/controllers/up_items_controller.rb b/app/controllers/up_items_controller.rbindex 310c855a79..752f2a742a 100644--- a/app/controllers/up_items_controller.rb+++ b/app/controllers/up_items_controller.rb@@ -107,7 +107,7 @@ class UpItemsController < ApplicationController@up_item = requested_up_itemunless @up_item.credentials_configured?- redirect_to settings_providers_path, alert: t(".no_credentials_configured")+ frame_redirect_to settings_providers_path, alert: t(".no_credentials_configured")returnenddiff --git a/app/controllers/wise_items_controller.rb b/app/controllers/wise_items_controller.rbindex be0f316c72..d970a3fc80 100644--- a/app/controllers/wise_items_controller.rb+++ b/app/controllers/wise_items_controller.rb@@ -180,7 +180,7 @@ class WiseItemsController < ApplicationController@wise_item = resolve_wise_item_for_selectionunless @wise_item- redirect_to settings_providers_path, alert: t("wise_items.select_accounts.no_connection") and return+ frame_redirect_to settings_providers_path, alert: t("wise_items.select_accounts.no_connection") and returnend@available_accounts = @wise_item.wise_accounts.unlinkeddiff --git a/test/controllers/akahu_items_controller_test.rb b/test/controllers/akahu_items_controller_test.rbindex b409abe7ec..9cd91a47aa 100644--- a/test/controllers/akahu_items_controller_test.rb+++ b/test/controllers/akahu_items_controller_test.rb@@ -332,6 +332,17 @@ class AkahuItemsControllerTest < ActionDispatch::IntegrationTestrefute_includes flash[:alert], raw_messageend+ test "select accounts leaves the Add Account modal for Settings at the top level" do+ AkahuItem.any_instance.stubs(:credentials_configured?).returns(false)++ get select_accounts_akahu_items_url, params: { akahu_item_id: @akahu_item.id }, headers: { "Turbo-Frame" => "modal" }++ # A redirect would be followed inside the frame and the flash lost.+ assert_response :success+ assert_select "turbo-frame#modal turbo-stream[action=redirect][target=?]", settings_providers_path+ assert_equal I18n.t("akahu_items.select_accounts.no_credentials_configured"), flash[:alert]+ end+privatedef unsafe_return_pathsdiff --git a/test/controllers/fio_items_controller_test.rb b/test/controllers/fio_items_controller_test.rbindex 8cb67d535a..0a8787eaf3 100644--- a/test/controllers/fio_items_controller_test.rb+++ b/test/controllers/fio_items_controller_test.rb@@ -250,4 +250,15 @@ class FioItemsControllerTest < ActionDispatch::IntegrationTestselected_option = css_select("select[name='account_type'] option[selected='selected']").firstassert_equal "Depository", selected_option["value"]end++ test "select accounts leaves the Add Account modal for Settings at the top level" do+ FioItem.any_instance.stubs(:credentials_configured?).returns(false)++ get select_accounts_fio_items_url, params: { fio_item_id: @fio_item.id }, headers: { "Turbo-Frame" => "modal" }++ # A redirect would be followed inside the frame and the flash lost.+ assert_response :success+ assert_select "turbo-frame#modal turbo-stream[action=redirect][target=?]", settings_providers_path+ assert_equal I18n.t("fio_items.select_accounts.no_credentials_configured"), flash[:alert]+ endenddiff --git a/test/controllers/ibkr_items_controller_test.rb b/test/controllers/ibkr_items_controller_test.rbindex ab5c2b797e..d76d54c4f7 100644--- a/test/controllers/ibkr_items_controller_test.rb+++ b/test/controllers/ibkr_items_controller_test.rb@@ -132,4 +132,15 @@ class IbkrItemsControllerTest < ActionDispatch::IntegrationTestibkr_account.reloadassert_equal original_account, ibkr_account.current_accountend++ test "select accounts leaves the Add Account modal for Settings at the top level" do+ families(:dylan_family).ibkr_items.update_all(scheduled_for_deletion: true)++ get select_accounts_ibkr_items_url, headers: { "Turbo-Frame" => "modal" }++ # A redirect would be followed inside the frame and the flash lost.+ assert_response :success+ assert_select "turbo-frame#modal turbo-stream[action=redirect][target=?]", settings_providers_path+ assert_equal I18n.t("ibkr_items.select_accounts.not_configured"), flash[:alert]+ endenddiff --git a/test/controllers/indexa_capital_items_controller_test.rb b/test/controllers/indexa_capital_items_controller_test.rbindex fee57a0edd..cd525a35cf 100644--- a/test/controllers/indexa_capital_items_controller_test.rb+++ b/test/controllers/indexa_capital_items_controller_test.rb@@ -179,4 +179,15 @@ class IndexaCapitalItemsControllerTest < ActionDispatch::IntegrationTest}endend++ test "select accounts leaves the Add Account modal for Settings at the top level" do+ IndexaCapitalItem.any_instance.stubs(:credentials_configured?).returns(false)++ get select_accounts_indexa_capital_items_url, headers: { "Turbo-Frame" => "modal" }++ # A redirect would be followed inside the frame and the flash lost.+ assert_response :success+ assert_select "turbo-frame#modal turbo-stream[action=redirect][target=?]", settings_providers_path+ assert_equal I18n.t("indexa_capital_items.select_accounts.no_credentials_configured"), flash[:alert]+ endenddiff --git a/test/controllers/monobank_items_controller_test.rb b/test/controllers/monobank_items_controller_test.rbindex a235798258..441713fa8c 100644--- a/test/controllers/monobank_items_controller_test.rb+++ b/test/controllers/monobank_items_controller_test.rb@@ -191,6 +191,17 @@ class MonobankItemsControllerTest < ActionDispatch::IntegrationTestassert @monobank_item.reload.scheduled_for_deletion?end+ test "select accounts leaves the Add Account modal for Settings at the top level" do+ MonobankItem.any_instance.stubs(:credentials_configured?).returns(false)++ get select_accounts_monobank_items_url, params: { monobank_item_id: @monobank_item.id }, headers: { "Turbo-Frame" => "modal" }++ # A redirect would be followed inside the frame and the flash lost.+ assert_response :success+ assert_select "turbo-frame#modal turbo-stream[action=redirect][target=?]", settings_providers_path+ assert_equal I18n.t("monobank_items.select_accounts.no_credentials_configured"), flash[:alert]+ end+privatedef unsafe_return_pathsdiff --git a/test/controllers/trade_republic_items_controller_test.rb b/test/controllers/trade_republic_items_controller_test.rbindex c024acd652..f5726c7611 100644--- a/test/controllers/trade_republic_items_controller_test.rb+++ b/test/controllers/trade_republic_items_controller_test.rb@@ -735,6 +735,17 @@ class TradeRepublicItemsControllerTest < ActionDispatch::IntegrationTestassert_not item.scheduled_for_deletion?end+ test "select accounts leaves the Add Account modal for Settings at the top level" do+ families(:dylan_family).trade_republic_items.update_all(scheduled_for_deletion: true)++ get select_accounts_trade_republic_items_url, headers: { "Turbo-Frame" => "modal" }++ # A redirect would be followed inside the frame and the flash lost.+ assert_response :success+ assert_select "turbo-frame#modal turbo-stream[action=redirect][target=?]", settings_providers_path+ assert_equal I18n.t("trade_republic_items.select_accounts.not_configured"), flash[:alert]+ end+privatedef login_poller_headersdiff --git a/test/controllers/trading212_items_controller_test.rb b/test/controllers/trading212_items_controller_test.rbnew file mode 100644index 0000000000..2abb53775b--- /dev/null+++ b/test/controllers/trading212_items_controller_test.rb@@ -0,0 +1,20 @@+# frozen_string_literal: true++require "test_helper"++class Trading212ItemsControllerTest < ActionDispatch::IntegrationTest+ setup do+ sign_in users(:family_admin)+ end++ test "select accounts leaves the Add Account modal for Settings at the top level" do+ families(:dylan_family).trading212_items.update_all(scheduled_for_deletion: true)++ get select_accounts_trading212_items_url, headers: { "Turbo-Frame" => "modal" }++ # A redirect would be followed inside the frame and the flash lost.+ assert_response :success+ assert_select "turbo-frame#modal turbo-stream[action=redirect][target=?]", settings_providers_path+ assert_equal I18n.t("trading212_items.select_accounts.not_configured"), flash[:alert]+ end+enddiff --git a/test/controllers/up_items_controller_test.rb b/test/controllers/up_items_controller_test.rbindex 2fe01afb8a..ae2df3f8cb 100644--- a/test/controllers/up_items_controller_test.rb+++ b/test/controllers/up_items_controller_test.rb@@ -58,4 +58,15 @@ class UpItemsControllerTest < ActionDispatch::IntegrationTestassert_redirected_to settings_providers_pathend++ test "select accounts leaves the Add Account modal for Settings at the top level" do+ UpItem.any_instance.stubs(:credentials_configured?).returns(false)++ get select_accounts_up_items_url, params: { up_item_id: @up_item.id }, headers: { "Turbo-Frame" => "modal" }++ # A redirect would be followed inside the frame and the flash lost.+ assert_response :success+ assert_select "turbo-frame#modal turbo-stream[action=redirect][target=?]", settings_providers_path+ assert_equal I18n.t("up_items.select_accounts.no_credentials_configured"), flash[:alert]+ endenddiff --git a/test/controllers/wise_items_controller_test.rb b/test/controllers/wise_items_controller_test.rbindex f0647fbe86..180d7e5618 100644--- a/test/controllers/wise_items_controller_test.rb+++ b/test/controllers/wise_items_controller_test.rb@@ -207,4 +207,24 @@ class WiseItemsControllerTest < ActionDispatch::IntegrationTestassert_redirected_to settings_providers_pathend++ test "select accounts leaves the Add Account modal for Settings at the top level" do+ families(:dylan_family).wise_items.update_all(scheduled_for_deletion: true)++ get select_accounts_wise_items_url, headers: { "Turbo-Frame" => "modal" }++ # A redirect would be followed inside the frame and the flash lost.+ assert_response :success+ assert_select "turbo-frame#modal turbo-stream[action=redirect][target=?]", settings_providers_path+ assert_equal I18n.t("wise_items.select_accounts.no_connection"), flash[:alert]+ end++ test "select accounts redirects to Settings outside a turbo frame" do+ families(:dylan_family).wise_items.update_all(scheduled_for_deletion: true)++ get select_accounts_wise_items_url++ assert_redirected_to settings_providers_path+ assert_equal I18n.t("wise_items.select_accounts.no_connection"), flash[:alert]+ endend