Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Do not offer a guest a provider link the controller refuses (#3656)

jaysbeekayde530f7f595b
diff --git a/app/views/accounts/new/_method_selector.html.erb b/app/views/accounts/new/_method_selector.html.erb
index 55dd6912c5..bc5aa31577 100644
--- a/app/views/accounts/new/_method_selector.html.erb
+++ b/app/views/accounts/new/_method_selector.html.erb
@@ -22,7 +22,11 @@
connect providers whose credential is scoped to the single connection
they authenticate (see ProviderItemOwnable). %>
<% provider_configs.each do |config| %>
- <% next unless Current.user&.admin? || config[:member_connectable] %>
+ <%# The controller gate is `member_connectable? && Current.user&.member?`
+ (ConnectorAuthorizable#require_connector_create!). Without the role
+ check here a GUEST is offered the link and refused on submit, which
+ reads as a broken control rather than an absent one. %>
+ <% next unless Current.user&.admin? || (Current.user&.member? && config[:member_connectable]) %>
<% link_path = config[:new_account_path].call(accountable_type, params[:return_to]) %>
<% is_lunchflow = config[:key] == "lunchflow" %>
diff --git a/test/controllers/depositories_controller_test.rb b/test/controllers/depositories_controller_test.rb
index d340d2c16b..5a33bb11ce 100644
--- a/test/controllers/depositories_controller_test.rb
+++ b/test/controllers/depositories_controller_test.rb
@@ -8,6 +8,38 @@ class DepositoriesControllerTest < ActionDispatch::IntegrationTest
@account = accounts(:depository)
end
+ # The provider link's visibility and the controller's gate are two
+ # expressions of one rule, and they disagreed. ConnectorAuthorizable requires
+ # `member_connectable? && Current.user&.member?`; the selector asked only
+ # `admin? || member_connectable`, so a GUEST was shown the link and refused
+ # on submit -- a control that looks broken rather than one that is absent.
+ #
+ # One user, one family, one variable: the role changes between the two
+ # requests and nothing else does, so a difference can only be the role.
+ test "a member-connectable provider is offered to a member and withheld from a guest" do
+ config = {
+ key: "test_provider",
+ name: "Test Provider",
+ member_connectable: true,
+ new_account_path: ->(_accountable_type, _return_to) { "/test-provider/new" }
+ }
+ Provider::Factory.stubs(:connection_configs_for_account_type).returns([ config ])
+
+ sign_in user = users(:family_member)
+
+ get new_depository_url(step: "method_select")
+ assert_response :success
+ assert_select "a[href='/test-provider/new']", { minimum: 1 },
+ "a member may connect this provider and must be offered it"
+
+ user.update!(role: :guest)
+
+ get new_depository_url(step: "method_select")
+ assert_response :success
+ assert_select "a[href='/test-provider/new']", { count: 0 },
+ "a guest was offered a link require_connector_create! refuses"
+ end
+
test "create falls back to the stored return_to when no form param is present" do
get new_account_path(return_to: transactions_path) # StoreLocation captures it into the session