Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Show a member only the provider accounts shared with them (#4048)

jaysbeekay808cd25f5f1d
diff --git a/app/components/provider_sync_summary.rb b/app/components/provider_sync_summary.rb
index 8ef745719c..f1515cb24c 100644
--- a/app/components/provider_sync_summary.rb
+++ b/app/components/provider_sync_summary.rb
@@ -19,17 +19,22 @@
# ) %>
#
class ProviderSyncSummary < ViewComponent::Base
- attr_reader :stats, :provider_item, :institutions_count, :activities_pending
+ attr_reader :stats, :provider_item, :institutions_count, :activities_pending, :show_account_details
# @param stats [Hash] The sync statistics hash from sync.sync_stats
# @param provider_item [Object] The provider item (must respond to last_synced_at)
# @param institutions_count [Integer, nil] Optional count of connected institutions
# @param activities_pending [Boolean] Whether activities are still being fetched in background
- def initialize(stats:, provider_item:, institutions_count: nil, activities_pending: false)
+ # @param show_account_details [Boolean] Whether the viewer may see every account on
+ # the connection. The detail lists name accounts and transactions from the last
+ # sync, so a member shared only some of them gets the counts without the names
+ # (#3630).
+ def initialize(stats:, provider_item:, institutions_count: nil, activities_pending: false, show_account_details: true)
@stats = stats || {}
@provider_item = provider_item
@institutions_count = institutions_count
@activities_pending = activities_pending
+ @show_account_details = show_account_details
end
def activities_pending?
@@ -84,6 +89,7 @@ class ProviderSyncSummary < ViewComponent::Base
end
def skip_details
+ return [] unless show_account_details
stats["skip_details"] || []
end
@@ -160,6 +166,7 @@ class ProviderSyncSummary < ViewComponent::Base
end
def error_details
+ return [] unless show_account_details
stats["errors"] || []
end
@@ -177,6 +184,7 @@ class ProviderSyncSummary < ViewComponent::Base
end
def stale_pending_details
+ return [] unless show_account_details
stats["stale_pending_details"] || []
end
@@ -190,6 +198,7 @@ class ProviderSyncSummary < ViewComponent::Base
end
def stale_unmatched_details
+ return [] unless show_account_details
stats["stale_unmatched_details"] || []
end
@@ -203,6 +212,7 @@ class ProviderSyncSummary < ViewComponent::Base
end
def pending_reconciled_details
+ return [] unless show_account_details
stats["pending_reconciled_details"] || []
end
@@ -216,6 +226,7 @@ class ProviderSyncSummary < ViewComponent::Base
end
def duplicate_suggestions_details
+ return [] unless show_account_details
stats["duplicate_suggestions_details"] || []
end
@@ -229,6 +240,7 @@ class ProviderSyncSummary < ViewComponent::Base
end
def data_quality_details
+ return [] unless show_account_details
stats["data_quality_details"] || []
end
diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb
index 101d822123..a126954652 100644
--- a/app/controllers/accounts_controller.rb
+++ b/app/controllers/accounts_controller.rb
@@ -6,6 +6,8 @@ class AccountsController < ApplicationController
before_action :ensure_linked_account, only: %i[confirm_unlink unlink]
include Periodable
+ helper_method :visible_card_accounts
+
def index
@accessible_account_ids = Current.user.accessible_accounts.pluck(:id)
@manual_accounts = family.accounts
@@ -401,6 +403,16 @@ class AccountsController < ApplicationController
end
end
+ # The accounts a provider card on this page may list. A card is admitted
+ # by visible_provider_items as soon as ONE of its accounts is accessible,
+ # so it must not then render the rest (#3630). Admins see every account.
+ def visible_card_accounts(item)
+ return item.accounts if Current.user.admin?
+
+ @accessible_account_id_set ||= @accessible_account_ids.to_set
+ item.accounts.select { |account| @accessible_account_id_set.include?(account.id) }
+ end
+
def visible_provider_items(items)
accessible_ids = @accessible_account_ids.to_a
@@ -411,10 +423,8 @@ class AccountsController < ApplicationController
# Ownership shows a member their own connection, importantly including
# one just created that has not synced any accounts yet. It must not
- # widen what they can see: the card renders the item's accounts
- # unfiltered, and is re-rendered by a family-wide broadcast with no
- # viewer, so an owner is shown the card only while every account on it
- # is already accessible to them.
+ # widen what they can see, so an owner is shown the card only while
+ # every account on it is already accessible to them.
if item.respond_to?(:owned_by?) && item.owned_by?(Current.user)
next true if (account_ids - accessible_ids).empty?
end
diff --git a/app/controllers/binance_items_controller.rb b/app/controllers/binance_items_controller.rb
index c391678602..093c744291 100644
--- a/app/controllers/binance_items_controller.rb
+++ b/app/controllers/binance_items_controller.rb
@@ -146,10 +146,11 @@ class BinanceItemsController < ApplicationController
end
render turbo_stream: [
+ # Admin-only action (require_admin!), so the card lists every account.
turbo_stream.replace(
ActionView::RecordIdentifier.dom_id(item),
partial: "binance_items/binance_item",
- locals: { binance_item: item }
+ locals: { binance_item: item, visible_accounts: item.accounts }
),
manual_accounts_stream,
*Array(flash_notification_stream_items)
@@ -236,10 +237,11 @@ class BinanceItemsController < ApplicationController
if turbo_frame_request?
@binance_items = Current.family.binance_items.ordered.includes(:syncs)
render turbo_stream: [
+ # Admin-only action (require_admin!), so the card lists every account.
turbo_stream.replace(
ActionView::RecordIdentifier.dom_id(@binance_item),
partial: "binance_items/binance_item",
- locals: { binance_item: @binance_item }
+ locals: { binance_item: @binance_item, visible_accounts: @binance_item.accounts }
)
] + Array(flash_notification_stream_items)
else
diff --git a/app/controllers/brex_items/account_setups_controller.rb b/app/controllers/brex_items/account_setups_controller.rb
index 45678aef0e..d1d074b7a0 100644
--- a/app/controllers/brex_items/account_setups_controller.rb
+++ b/app/controllers/brex_items/account_setups_controller.rb
@@ -59,10 +59,11 @@ class BrexItems::AccountSetupsController < ApplicationController
render turbo_stream: [
manual_accounts_stream,
+ # Admin-only action (require_admin!), so the card lists every account.
turbo_stream.replace(
ActionView::RecordIdentifier.dom_id(@brex_item),
partial: "brex_items/brex_item",
- locals: { brex_item: @brex_item }
+ locals: { brex_item: @brex_item, visible_accounts: @brex_item.accounts }
)
] + Array(flash_notification_stream_items)
end
diff --git a/app/controllers/coinbase_items_controller.rb b/app/controllers/coinbase_items_controller.rb
index 7c23edc7bf..b07c3078ac 100644
--- a/app/controllers/coinbase_items_controller.rb
+++ b/app/controllers/coinbase_items_controller.rb
@@ -170,10 +170,11 @@ class CoinbaseItemsController < ApplicationController
end
render turbo_stream: [
+ # Admin-only action (require_admin!), so the card lists every account.
turbo_stream.replace(
ActionView::RecordIdentifier.dom_id(item),
partial: "coinbase_items/coinbase_item",
- locals: { coinbase_item: item }
+ locals: { coinbase_item: item, visible_accounts: item.accounts }
),
manual_accounts_stream,
*Array(flash_notification_stream_items)
@@ -253,10 +254,11 @@ class CoinbaseItemsController < ApplicationController
@coinbase_items = Current.family.coinbase_items.ordered.includes(:syncs)
render turbo_stream: [
+ # Admin-only action (require_admin!), so the card lists every account.
turbo_stream.replace(
ActionView::RecordIdentifier.dom_id(@coinbase_item),
partial: "coinbase_items/coinbase_item",
- locals: { coinbase_item: @coinbase_item }
+ locals: { coinbase_item: @coinbase_item, visible_accounts: @coinbase_item.accounts }
)
] + Array(flash_notification_stream_items)
else
diff --git a/app/controllers/enable_banking_items_controller.rb b/app/controllers/enable_banking_items_controller.rb
index 277ae7e991..939c62fa34 100644
--- a/app/controllers/enable_banking_items_controller.rb
+++ b/app/controllers/enable_banking_items_controller.rb
@@ -498,10 +498,11 @@ class EnableBankingItemsController < ApplicationController
# Optimistic removal of the specific account row if it exists in the DOM
turbo_stream.remove(ActionView::RecordIdentifier.dom_id(@account)),
manual_accounts_stream,
+ # Admin-only action (require_admin!), so the card lists every account.
turbo_stream.replace(
ActionView::RecordIdentifier.dom_id(item),
partial: "enable_banking_items/enable_banking_item",
- locals: { enable_banking_item: item }
+ locals: { enable_banking_item: item, visible_accounts: item.accounts }
),
turbo_stream.replace("modal", view_context.turbo_frame_tag("modal"))
] + Array(flash_notification_stream_items)
diff --git a/app/controllers/lunchflow_items_controller.rb b/app/controllers/lunchflow_items_controller.rb
index ca58dde0ed..88533a13d3 100644
--- a/app/controllers/lunchflow_items_controller.rb
+++ b/app/controllers/lunchflow_items_controller.rb
@@ -637,10 +637,11 @@ class LunchflowItemsController < ApplicationController
render turbo_stream: [
manual_accounts_stream,
+ # Admin-only action (require_admin!), so the card lists every account.
turbo_stream.replace(
ActionView::RecordIdentifier.dom_id(@lunchflow_item),
partial: "lunchflow_items/lunchflow_item",
- locals: { lunchflow_item: @lunchflow_item }
+ locals: { lunchflow_item: @lunchflow_item, visible_accounts: @lunchflow_item.accounts }
)
] + Array(flash_notification_stream_items)
else
diff --git a/app/controllers/mercury_items_controller.rb b/app/controllers/mercury_items_controller.rb
index 653d733fea..f8b8dc7ff6 100644
--- a/app/controllers/mercury_items_controller.rb
+++ b/app/controllers/mercury_items_controller.rb
@@ -635,10 +635,11 @@ class MercuryItemsController < ApplicationController
render turbo_stream: [
manual_accounts_stream,
+ # Admin-only action (require_admin!), so the card lists every account.
turbo_stream.replace(
ActionView::RecordIdentifier.dom_id(@mercury_item),
partial: "mercury_items/mercury_item",
- locals: { mercury_item: @mercury_item }
+ locals: { mercury_item: @mercury_item, visible_accounts: @mercury_item.accounts }
)
] + Array(flash_notification_stream_items)
else
diff --git a/app/controllers/simplefin_items_controller.rb b/app/controllers/simplefin_items_controller.rb
index 7007fd4408..ed32dfe844 100644
--- a/app/controllers/simplefin_items_controller.rb
+++ b/app/controllers/simplefin_items_controller.rb
@@ -335,10 +335,11 @@ class SimplefinItemsController < ApplicationController
render turbo_stream: [
manual_accounts_stream,
+ # Admin-only action (require_admin!), so the card lists every account.
turbo_stream.replace(
ActionView::RecordIdentifier.dom_id(@simplefin_item),
partial: "simplefin_items/simplefin_item",
- locals: { simplefin_item: @simplefin_item }
+ locals: { simplefin_item: @simplefin_item, visible_accounts: @simplefin_item.accounts }
)
] + Array(flash_notification_stream_items)
else
@@ -484,10 +485,11 @@ class SimplefinItemsController < ApplicationController
# Optimistic removal of the specific account row if it exists in the DOM
turbo_stream.remove(ActionView::RecordIdentifier.dom_id(@account)),
manual_accounts_stream,
+ # Admin-only action (require_admin!), so the card lists every account.
turbo_stream.replace(
ActionView::RecordIdentifier.dom_id(item),
partial: "simplefin_items/simplefin_item",
- locals: { simplefin_item: item }
+ locals: { simplefin_item: item, visible_accounts: item.accounts }
),
turbo_stream.replace("modal", view_context.turbo_frame_tag("modal"))
] + Array(flash_notification_stream_items)
diff --git a/app/controllers/sophtron_items_controller.rb b/app/controllers/sophtron_items_controller.rb
index 9735cbbdd4..69d9ec22da 100644
--- a/app/controllers/sophtron_items_controller.rb
+++ b/app/controllers/sophtron_items_controller.rb
@@ -470,10 +470,11 @@ class SophtronItemsController < ApplicationController
format.turbo_stream do
flash.now[:notice] = t(".success_#{enabled ? 'enabled' : 'disabled'}")
render turbo_stream: [
+ # Admin-only action (require_admin!), so the card lists every account.
turbo_stream.replace(
ActionView::RecordIdentifier.dom_id(@sophtron_item),
partial: "sophtron_items/sophtron_item",
- locals: { sophtron_item: @sophtron_item.reload }
+ locals: { sophtron_item: @sophtron_item.reload, visible_accounts: @sophtron_item.accounts }
),
*flash_notification_stream_items
]
@@ -625,10 +626,11 @@ class SophtronItemsController < ApplicationController
render turbo_stream: [
manual_accounts_stream,
+ # Admin-only action (require_admin!), so the card lists every account.
turbo_stream.replace(
ActionView::RecordIdentifier.dom_id(@sophtron_item),
partial: "sophtron_items/sophtron_item",
- locals: { sophtron_item: @sophtron_item }
+ locals: { sophtron_item: @sophtron_item, visible_accounts: @sophtron_item.accounts }
)
] + Array(flash_notification_stream_items)
else
diff --git a/app/views/accounts/index.html.erb b/app/views/accounts/index.html.erb
index b9bb037e32..83bbcf5b94 100644
--- a/app/views/accounts/index.html.erb
+++ b/app/views/accounts/index.html.erb
@@ -19,39 +19,57 @@
<% end %>
<% if @plaid_items.any? %>
- <%= render @plaid_items.sort_by(&:created_at) %>
+ <% @plaid_items.sort_by(&:created_at).each do |item| %>
+ <%= render item, visible_accounts: visible_card_accounts(item) %>
+ <% end %>
<% end %>
<% if @simplefin_items.any? %>
- <%= render @simplefin_items.sort_by(&:created_at) %>
+ <% @simplefin_items.sort_by(&:created_at).each do |item| %>
+ <%= render item, visible_accounts: visible_card_accounts(item) %>
+ <% end %>
<% end %>
<% if @lunchflow_items.any? %>
- <%= render @lunchflow_items.sort_by(&:created_at) %>
+ <% @lunchflow_items.sort_by(&:created_at).each do |item| %>
+ <%= render item, visible_accounts: visible_card_accounts(item) %>
+ <% end %>
<% end %>
<% if @redbark_items.any? %>
- <%= render @redbark_items.sort_by(&:created_at) %>
+ <% @redbark_items.sort_by(&:created_at).each do |item| %>
+ <%= render item, visible_accounts: visible_card_accounts(item) %>
+ <% end %>
<% end %>
<% if @akahu_items.any? %>
- <%= render @akahu_items.sort_by(&:created_at) %>
+ <% @akahu_items.sort_by(&:created_at).each do |item| %>
+ <%= render item, visible_accounts: visible_card_accounts(item) %>
+ <% end %>
<% end %>
<% if @up_items.any? %>
- <%= render @up_items.sort_by(&:created_at) %>
+ <% @up_items.sort_by(&:created_at).each do |item| %>
+ <%= render item, visible_accounts: visible_card_accounts(item) %>
+ <% end %>
<% end %>
<% if @monobank_items.any? %>
- <%= render @monobank_items.sort_by(&:created_at) %>
+ <% @monobank_items.sort_by(&:created_at).each do |item| %>
+ <%= render item, visible_accounts: visible_card_accounts(item) %>
+ <% end %>
<% end %>
<% if @enable_banking_items.any? %>
- <%= render @enable_banking_items.sort_by(&:created_at) %>
+ <% @enable_banking_items.sort_by(&:created_at).each do |item| %>
+ <%= render item, visible_accounts: visible_card_accounts(item) %>
+ <% end %>
<% end %>
<% if @coinstats_items.any? %>
- <%= render @coinstats_items.sort_by(&:created_at) %>
+ <% @coinstats_items.sort_by(&:created_at).each do |item| %>
+ <%= render item, visible_accounts: visible_card_accounts(item) %>
+ <% end %>
<% end %>
<% if @onchain_wallet_items.any? %>
@@ -65,63 +83,93 @@
<% end %>
<% if @sophtron_items.any? %>
- <%= render @sophtron_items.sort_by(&:created_at) %>
+ <% @sophtron_items.sort_by(&:created_at).each do |item| %>
+ <%= render item, visible_accounts: visible_card_accounts(item) %>
+ <% end %>
<% end %>
<% if @mercury_items.any? %>
- <%= render @mercury_items.sort_by(&:created_at) %>
+ <% @mercury_items.sort_by(&:created_at).each do |item| %>
+ <%= render item, visible_accounts: visible_card_accounts(item) %>
+ <% end %>
<% end %>
<% if @brex_items.any? %>
- <%= render @brex_items.sort_by(&:created_at) %>
+ <% @brex_items.sort_by(&:created_at).each do |item| %>
+ <%= render item, visible_accounts: visible_card_accounts(item) %>
+ <% end %>
<% end %>
<% if @coinbase_items.any? %>
- <%= render @coinbase_items.sort_by(&:created_at) %>
+ <% @coinbase_items.sort_by(&:created_at).each do |item| %>
+ <%= render item, visible_accounts: visible_card_accounts(item) %>
+ <% end %>
<% end %>
<% if @binance_items.any? %>
- <%= render @binance_items.sort_by(&:created_at) %>
+ <% @binance_items.sort_by(&:created_at).each do |item| %>
+ <%= render item, visible_accounts: visible_card_accounts(item) %>
+ <% end %>
<% end %>
<% if @kraken_items.any? %>
- <%= render @kraken_items.sort_by(&:created_at) %>
+ <% @kraken_items.sort_by(&:created_at).each do |item| %>
+ <%= render item, visible_accounts: visible_card_accounts(item) %>
+ <% end %>
<% end %>
<% if @coinspot_items.any? %>
- <%= render @coinspot_items.sort_by(&:created_at) %>
+ <% @coinspot_items.sort_by(&:created_at).each do |item| %>
+ <%= render item, visible_accounts: visible_card_accounts(item) %>
+ <% end %>
<% end %>
<% if @trading212_items.any? %>
- <%= render @trading212_items %>
+ <% @trading212_items.each do |item| %>
+ <%= render item, visible_accounts: visible_card_accounts(item) %>
+ <% end %>
<% end %>
<% if @wise_items.any? %>
- <%= render @wise_items.sort_by(&:created_at) %>
+ <% @wise_items.sort_by(&:created_at).each do |item| %>
+ <%= render item, visible_accounts: visible_card_accounts(item) %>
+ <% end %>
<% end %>
<% if @trade_republic_items.any? %>
- <%= render @trade_republic_items.sort_by(&:created_at) %>
+ <% @trade_republic_items.sort_by(&:created_at).each do |item| %>
+ <%= render item, visible_accounts: visible_card_accounts(item) %>
+ <% end %>
<% end %>
<% if @snaptrade_items.any? %>
- <%= render @snaptrade_items.sort_by(&:created_at) %>
+ <% @snaptrade_items.sort_by(&:created_at).each do |item| %>
+ <%= render item, visible_accounts: visible_card_accounts(item) %>
+ <% end %>
<% end %>
<% if @ibkr_items.any? %>
- <%= render @ibkr_items.sort_by(&:created_at) %>
+ <% @ibkr_items.sort_by(&:created_at).each do |item| %>
+ <%= render item, visible_accounts: visible_card_accounts(item) %>
+ <% end %>
<% end %>
<% if @indexa_capital_items.any? %>
- <%= render @indexa_capital_items.sort_by(&:created_at) %>
+ <% @indexa_capital_items.sort_by(&:created_at).each do |item| %>
+ <%= render item, visible_accounts: visible_card_accounts(item) %>
+ <% end %>
<% end %>
<% if @questrade_items.any? %>
- <%= render @questrade_items.sort_by(&:created_at) %>
+ <% @questrade_items.sort_by(&:created_at).each do |item| %>
+ <%= render item, visible_accounts: visible_card_accounts(item) %>
+ <% end %>
<% end %>
<% if @fio_items.any? %>
- <%= render @fio_items.sort_by(&:created_at) %>
+ <% @fio_items.sort_by(&:created_at).each do |item| %>
+ <%= render item, visible_accounts: visible_card_accounts(item) %>
+ <% end %>
<% end %>
<% if @manual_accounts.any? %>
diff --git a/app/views/akahu_items/_akahu_item.html.erb b/app/views/akahu_items/_akahu_item.html.erb
index 1e8838b06b..9d9475fc11 100644
--- a/app/views/akahu_items/_akahu_item.html.erb
+++ b/app/views/akahu_items/_akahu_item.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (akahu_item:) %>
+<%# locals: (akahu_item:, visible_accounts:) %>
<%= tag.div id: dom_id(akahu_item) do %>
<%= render DS::Disclosure.new(variant: :card, open: true) do |disclosure| %>
@@ -17,7 +17,9 @@
<% end %>
</div>
- <% if akahu_item.accounts.any? %>
+ <%# The institution belongs to every account on the connection, so it is
+ shown only to a viewer who can see them all (#3630). %>
+ <% if akahu_item.accounts.any? && visible_accounts.size == akahu_item.accounts.size %>
<p class="text-xs text-secondary"><%= akahu_item.institution_summary %></p>
<% end %>
@@ -62,8 +64,8 @@
<% unless akahu_item.scheduled_for_deletion? %>
<div class="space-y-4 mt-4">
- <% if akahu_item.accounts.any? %>
- <%= render "accounts/index/account_groups", accounts: akahu_item.accounts %>
+ <% if visible_accounts.any? %>
+ <%= render "accounts/index/account_groups", accounts: visible_accounts %>
<% end %>
<% stats = if defined?(@akahu_sync_stats_map) && @akahu_sync_stats_map
@@ -73,7 +75,7 @@
end %>
<%= render ProviderSyncSummary.new(
stats: stats,
- provider_item: akahu_item,
+ provider_item: akahu_item, show_account_details: visible_accounts.size == akahu_item.accounts.size,
institutions_count: akahu_item.connected_institutions.size
) %>
diff --git a/app/views/binance_items/_binance_item.html.erb b/app/views/binance_items/_binance_item.html.erb
index 9c3894b922..492af333c1 100644
--- a/app/views/binance_items/_binance_item.html.erb
+++ b/app/views/binance_items/_binance_item.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (binance_item:, unlinked_count: binance_item.unlinked_accounts_count) %>
+<%# locals: (binance_item:, unlinked_count: binance_item.unlinked_accounts_count, visible_accounts:) %>
<%= tag.div id: dom_id(binance_item) do %>
<%= render DS::Disclosure.new(variant: :card, open: true) do |disclosure| %>
@@ -86,9 +86,9 @@
<% unless binance_item.scheduled_for_deletion? %>
<div class="space-y-4 mt-4">
- <% if binance_item.accounts.any? %>
- <%= render "accounts/index/account_groups", accounts: binance_item.accounts %>
- <% binance_item.stale_rate_accounts.each do |ba| %>
+ <% if visible_accounts.any? %>
+ <%= render "accounts/index/account_groups", accounts: visible_accounts %>
+ <% binance_item.stale_rate_accounts.where(accounts: { id: visible_accounts.map(&:id) }).each do |ba| %>
<div class="flex items-center gap-2 text-xs text-warning px-1">
<span class="font-mono">~</span>
<%= icon "triangle-alert", size: "sm" %>
@@ -103,7 +103,7 @@
<% stats = binance_item.syncs.ordered.first&.sync_stats || {} %>
<%= render ProviderSyncSummary.new(
stats: stats,
- provider_item: binance_item
+ provider_item: binance_item, show_account_details: visible_accounts.size == binance_item.accounts.size
) %>
<% if binance_item.unlinked_accounts_count > 0 %>
diff --git a/app/views/brex_items/_brex_item.html.erb b/app/views/brex_items/_brex_item.html.erb
index 5fcaf6271f..cb61ed8631 100644
--- a/app/views/brex_items/_brex_item.html.erb
+++ b/app/views/brex_items/_brex_item.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (brex_item:) %>
+<%# locals: (brex_item:, visible_accounts:) %>
<% render_locals = brex_item_render_locals(
brex_item,
sync_stats_map: @brex_sync_stats_map,
@@ -27,7 +27,9 @@
<%= tag.p t(".deletion_in_progress"), class: "text-destructive text-sm animate-pulse" %>
<% end %>
</div>
- <% if brex_item.accounts.any? %>
+ <%# The institution belongs to every account on the connection, so it is
+ shown only to a viewer who can see them all (#3630). %>
+ <% if brex_item.accounts.any? && visible_accounts.size == brex_item.accounts.size %>
<p class="text-xs text-secondary">
<%= brex_item.institution_summary %>
</p>
@@ -85,13 +87,13 @@
<% unless brex_item.scheduled_for_deletion? %>
<div class="space-y-4 mt-4">
- <% if brex_item.accounts.any? %>
- <%= render "accounts/index/account_groups", accounts: brex_item.accounts %>
+ <% if visible_accounts.any? %>
+ <%= render "accounts/index/account_groups", accounts: visible_accounts %>
<% end %>
<%= render ProviderSyncSummary.new(
stats: stats,
- provider_item: brex_item,
+ provider_item: brex_item, show_account_details: visible_accounts.size == brex_item.accounts.size,
institutions_count: institutions_count
) %>
diff --git a/app/views/coinbase_items/_coinbase_item.html.erb b/app/views/coinbase_items/_coinbase_item.html.erb
index e488248f6b..e07c0760c7 100644
--- a/app/views/coinbase_items/_coinbase_item.html.erb
+++ b/app/views/coinbase_items/_coinbase_item.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (coinbase_item:) %>
+<%# locals: (coinbase_item:, visible_accounts:) %>
<%= tag.div id: dom_id(coinbase_item) do %>
<%# Compute unlinked count early so it's available for both menu and bottom section %>
@@ -103,8 +103,8 @@
<% unless coinbase_item.scheduled_for_deletion? %>
<div class="space-y-4 mt-4">
- <% if coinbase_item.accounts.any? %>
- <%= render "accounts/index/account_groups", accounts: coinbase_item.accounts %>
+ <% if visible_accounts.any? %>
+ <%= render "accounts/index/account_groups", accounts: visible_accounts %>
<% end %>
<%# Sync summary (collapsible) - using shared ProviderSyncSummary component %>
@@ -115,7 +115,7 @@
end %>
<%= render ProviderSyncSummary.new(
stats: stats,
- provider_item: coinbase_item
+ provider_item: coinbase_item, show_account_details: visible_accounts.size == coinbase_item.accounts.size
) %>
<% if unlinked_count.to_i > 0 && coinbase_item.accounts.empty? %>
diff --git a/app/views/coinspot_items/_coinspot_item.html.erb b/app/views/coinspot_items/_coinspot_item.html.erb
index efc4757f22..598ab6f2ae 100644
--- a/app/views/coinspot_items/_coinspot_item.html.erb
+++ b/app/views/coinspot_items/_coinspot_item.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (coinspot_item:, unlinked_count: coinspot_item.unlinked_accounts_count) %>
+<%# locals: (coinspot_item:, unlinked_count: coinspot_item.unlinked_accounts_count, visible_accounts:) %>
<%= tag.div id: dom_id(coinspot_item) do %>
<%= render DS::Disclosure.new(variant: :card, open: true) do |disclosure| %>
@@ -77,9 +77,9 @@
<% unless coinspot_item.scheduled_for_deletion? %>
<div class="space-y-4 mt-4">
- <% if coinspot_item.accounts.any? %>
- <%= render "accounts/index/account_groups", accounts: coinspot_item.accounts %>
- <% coinspot_item.stale_rate_accounts.each do |coinspot_account| %>
+ <% if visible_accounts.any? %>
+ <%= render "accounts/index/account_groups", accounts: visible_accounts %>
+ <% coinspot_item.stale_rate_accounts.where(accounts: { id: visible_accounts.map(&:id) }).each do |coinspot_account| %>
<div class="flex items-center gap-2 text-xs text-warning px-1">
<span class="font-mono">~</span>
<%= icon "triangle-alert", size: "sm" %>
@@ -89,7 +89,7 @@
<% end %>
<% stats = coinspot_item.syncs.ordered.first&.sync_stats || {} %>
- <%= render ProviderSyncSummary.new(stats: stats, provider_item: coinspot_item) %>
+ <%= render ProviderSyncSummary.new(stats: stats, provider_item: coinspot_item, show_account_details: visible_accounts.size == coinspot_item.accounts.size) %>
<% if unlinked_count.to_i > 0 && coinspot_item.accounts.empty? %>
<div class="p-4 flex flex-col gap-3 items-center justify-center">
diff --git a/app/views/coinstats_items/_coinstats_item.html.erb b/app/views/coinstats_items/_coinstats_item.html.erb
index c6dfd8873f..8e171269de 100644
--- a/app/views/coinstats_items/_coinstats_item.html.erb
+++ b/app/views/coinstats_items/_coinstats_item.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (coinstats_item:) %>
+<%# locals: (coinstats_item:, visible_accounts:) %>
<%= tag.div id: dom_id(coinstats_item) do %>
<%= render DS::Disclosure.new(variant: :card, open: true) do |disclosure| %>
@@ -78,8 +78,8 @@
<% unless coinstats_item.scheduled_for_deletion? %>
<div class="space-y-4 mt-4">
- <% if coinstats_item.accounts.any? %>
- <%= render "accounts/index/account_groups", accounts: coinstats_item.accounts %>
+ <% if visible_accounts.any? %>
+ <%= render "accounts/index/account_groups", accounts: visible_accounts %>
<% end %>
<%# Sync summary (collapsible) - using shared ProviderSyncSummary component %>
@@ -90,7 +90,7 @@
end %>
<%= render ProviderSyncSummary.new(
stats: stats,
- provider_item: coinstats_item
+ provider_item: coinstats_item, show_account_details: visible_accounts.size == coinstats_item.accounts.size
) %>
<% if coinstats_item.accounts.empty? %>
diff --git a/app/views/enable_banking_items/_enable_banking_item.html.erb b/app/views/enable_banking_items/_enable_banking_item.html.erb
index 5e5f648304..812af5929c 100644
--- a/app/views/enable_banking_items/_enable_banking_item.html.erb
+++ b/app/views/enable_banking_items/_enable_banking_item.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (enable_banking_item:) %>
+<%# locals: (enable_banking_item:, visible_accounts:) %>
<%= tag.div id: dom_id(enable_banking_item) do %>
<%= render DS::Disclosure.new(variant: :card, open: true) do |disclosure| %>
@@ -77,8 +77,8 @@
<% unless enable_banking_item.scheduled_for_deletion? %>
<div class="space-y-4 mt-4">
- <% if enable_banking_item.accounts.any? %>
- <%= render "accounts/index/account_groups", accounts: enable_banking_item.accounts %>
+ <% if visible_accounts.any? %>
+ <%= render "accounts/index/account_groups", accounts: visible_accounts %>
<% end %>
<%# Sync summary (collapsible) - using shared ProviderSyncSummary component %>
@@ -98,7 +98,7 @@
<% end %>
<%= render ProviderSyncSummary.new(
stats: stats,
- provider_item: enable_banking_item
+ provider_item: enable_banking_item, show_account_details: visible_accounts.size == enable_banking_item.accounts.size
) %>
<% if enable_banking_item.unlinked_accounts_count > 0 %>
diff --git a/app/views/fio_items/_fio_item.html.erb b/app/views/fio_items/_fio_item.html.erb
index 5f89335245..1eb5bdb616 100644
--- a/app/views/fio_items/_fio_item.html.erb
+++ b/app/views/fio_items/_fio_item.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (fio_item:) %>
+<%# locals: (fio_item:, visible_accounts:) %>
<%= tag.div id: dom_id(fio_item) do %>
<%= render DS::Disclosure.new(variant: :card, open: true) do |disclosure| %>
@@ -65,8 +65,8 @@
<% unless fio_item.scheduled_for_deletion? %>
<div class="space-y-4 mt-4">
- <% if fio_item.accounts.any? %>
- <%= render "accounts/index/account_groups", accounts: fio_item.accounts %>
+ <% if visible_accounts.any? %>
+ <%= render "accounts/index/account_groups", accounts: visible_accounts %>
<% end %>
<%# The accounts index preloads one stats row per item; a standalone render (the %>
@@ -76,7 +76,7 @@
else
fio_item.latest_sync_record&.sync_stats || {}
end %>
- <%= render ProviderSyncSummary.new(stats: stats, provider_item: fio_item) %>
+ <%= render ProviderSyncSummary.new(stats: stats, provider_item: fio_item, show_account_details: visible_accounts.size == fio_item.accounts.size) %>
<% if fio_item.requires_update? %>
<div class="p-4 flex flex-col gap-3 items-center justify-center">
diff --git a/app/views/ibkr_items/_ibkr_item.html.erb b/app/views/ibkr_items/_ibkr_item.html.erb
index 13dd98b89f..a0b4d54703 100644
--- a/app/views/ibkr_items/_ibkr_item.html.erb
+++ b/app/views/ibkr_items/_ibkr_item.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (ibkr_item:) %>
+<%# locals: (ibkr_item:, visible_accounts:) %>
<%= tag.div id: dom_id(ibkr_item) do %>
<% unlinked_count = ibkr_item.unlinked_accounts_count %>
@@ -81,12 +81,12 @@
<% unless ibkr_item.scheduled_for_deletion? %>
<div class="space-y-4 mt-4">
- <% if ibkr_item.accounts.any? %>
- <%= render "accounts/index/account_groups", accounts: ibkr_item.accounts %>
+ <% if visible_accounts.any? %>
+ <%= render "accounts/index/account_groups", accounts: visible_accounts %>
<% end %>
<% stats = ibkr_item.syncs.ordered.first&.sync_stats || {} %>
- <%= render ProviderSyncSummary.new(stats: stats, provider_item: ibkr_item) %>
+ <%= render ProviderSyncSummary.new(stats: stats, provider_item: ibkr_item, show_account_details: visible_accounts.size == ibkr_item.accounts.size) %>
<% if Current.user&.admin? %>
<% if unlinked_count > 0 && ibkr_item.accounts.empty? %>
diff --git a/app/views/indexa_capital_items/_indexa_capital_item.html.erb b/app/views/indexa_capital_items/_indexa_capital_item.html.erb
index bd2ae5cba5..f82263cc7c 100644
--- a/app/views/indexa_capital_items/_indexa_capital_item.html.erb
+++ b/app/views/indexa_capital_items/_indexa_capital_item.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (indexa_capital_item:) %>
+<%# locals: (indexa_capital_item:, visible_accounts:) %>
<%= tag.div id: dom_id(indexa_capital_item) do %>
<% unlinked_count = indexa_capital_item.unlinked_accounts_count %>
@@ -97,8 +97,8 @@
<% unless indexa_capital_item.scheduled_for_deletion? %>
<div class="space-y-4 mt-4">
- <% if indexa_capital_item.accounts.any? %>
- <%= render "accounts/index/account_groups", accounts: indexa_capital_item.accounts %>
+ <% if visible_accounts.any? %>
+ <%= render "accounts/index/account_groups", accounts: visible_accounts %>
<% end %>
<%# Sync summary (collapsible) - using shared ProviderSyncSummary component %>
@@ -106,7 +106,7 @@
<% activities_pending = indexa_capital_item.indexa_capital_accounts.any?(&:activities_fetch_pending) %>
<%= render ProviderSyncSummary.new(
stats: stats,
- provider_item: indexa_capital_item,
+ provider_item: indexa_capital_item, show_account_details: visible_accounts.size == indexa_capital_item.accounts.size,
activities_pending: activities_pending
) %>
diff --git a/app/views/kraken_items/_kraken_item.html.erb b/app/views/kraken_items/_kraken_item.html.erb
index 70045af049..86c709b37c 100644
--- a/app/views/kraken_items/_kraken_item.html.erb
+++ b/app/views/kraken_items/_kraken_item.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (kraken_item:, unlinked_count: kraken_item.unlinked_accounts_count) %>
+<%# locals: (kraken_item:, unlinked_count: kraken_item.unlinked_accounts_count, visible_accounts:) %>
<%= tag.div id: dom_id(kraken_item) do %>
<%= render DS::Disclosure.new(variant: :card, open: true) do |disclosure| %>
@@ -77,9 +77,9 @@
<% unless kraken_item.scheduled_for_deletion? %>
<div class="space-y-4 mt-4">
- <% if kraken_item.accounts.any? %>
- <%= render "accounts/index/account_groups", accounts: kraken_item.accounts %>
- <% kraken_item.stale_rate_accounts.each do |kraken_account| %>
+ <% if visible_accounts.any? %>
+ <%= render "accounts/index/account_groups", accounts: visible_accounts %>
+ <% kraken_item.stale_rate_accounts.where(accounts: { id: visible_accounts.map(&:id) }).each do |kraken_account| %>
<div class="flex items-center gap-2 text-xs text-warning px-1">
<span class="font-mono">~</span>
<%= icon "triangle-alert", size: "sm" %>
@@ -89,7 +89,7 @@
<% end %>
<% stats = kraken_item.syncs.ordered.first&.sync_stats || {} %>
- <%= render ProviderSyncSummary.new(stats: stats, provider_item: kraken_item) %>
+ <%= render ProviderSyncSummary.new(stats: stats, provider_item: kraken_item, show_account_details: visible_accounts.size == kraken_item.accounts.size) %>
<% if unlinked_count.to_i > 0 && kraken_item.accounts.empty? %>
<div class="p-4 flex flex-col gap-3 items-center justify-center">
diff --git a/app/views/lunchflow_items/_lunchflow_item.html.erb b/app/views/lunchflow_items/_lunchflow_item.html.erb
index 3c550d9354..97ad199092 100644
--- a/app/views/lunchflow_items/_lunchflow_item.html.erb
+++ b/app/views/lunchflow_items/_lunchflow_item.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (lunchflow_item:) %>
+<%# locals: (lunchflow_item:, visible_accounts:) %>
<%= tag.div id: dom_id(lunchflow_item) do %>
<%= render DS::Disclosure.new(variant: :card, open: true) do |disclosure| %>
@@ -16,7 +16,9 @@
<p class="text-destructive text-sm animate-pulse"><%= t(".deletion_in_progress") %></p>
<% end %>
</div>
- <% if lunchflow_item.accounts.any? %>
+ <%# The institution belongs to every account on the connection, so it is
+ shown only to a viewer who can see them all (#3630). %>
+ <% if lunchflow_item.accounts.any? && visible_accounts.size == lunchflow_item.accounts.size %>
<p class="text-xs text-secondary">
<%= lunchflow_item.institution_summary %>
</p>
@@ -74,8 +76,8 @@
<% unless lunchflow_item.scheduled_for_deletion? %>
<div class="space-y-4 mt-4">
- <% if lunchflow_item.accounts.any? %>
- <%= render "accounts/index/account_groups", accounts: lunchflow_item.accounts %>
+ <% if visible_accounts.any? %>
+ <%= render "accounts/index/account_groups", accounts: visible_accounts %>
<% end %>
<%# Sync summary (collapsible) - using shared ProviderSyncSummary component %>
@@ -86,7 +88,7 @@
end %>
<%= render ProviderSyncSummary.new(
stats: stats,
- provider_item: lunchflow_item,
+ provider_item: lunchflow_item, show_account_details: visible_accounts.size == lunchflow_item.accounts.size,
institutions_count: lunchflow_item.connected_institutions.size
) %>
diff --git a/app/views/mercury_items/_mercury_item.html.erb b/app/views/mercury_items/_mercury_item.html.erb
index 851091c421..51296ee398 100644
--- a/app/views/mercury_items/_mercury_item.html.erb
+++ b/app/views/mercury_items/_mercury_item.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (mercury_item:) %>
+<%# locals: (mercury_item:, visible_accounts:) %>
<%= tag.div id: dom_id(mercury_item) do %>
<%= render DS::Disclosure.new(variant: :card, open: true) do |disclosure| %>
@@ -16,7 +16,9 @@
<p class="text-destructive text-sm animate-pulse"><%= t(".deletion_in_progress") %></p>
<% end %>
</div>
- <% if mercury_item.accounts.any? %>
+ <%# The institution belongs to every account on the connection, so it is
+ shown only to a viewer who can see them all (#3630). %>
+ <% if mercury_item.accounts.any? && visible_accounts.size == mercury_item.accounts.size %>
<p class="text-xs text-secondary">
<%= mercury_item.institution_summary %>
</p>
@@ -74,8 +76,8 @@
<% unless mercury_item.scheduled_for_deletion? %>
<div class="space-y-4 mt-4">
- <% if mercury_item.accounts.any? %>
- <%= render "accounts/index/account_groups", accounts: mercury_item.accounts %>
+ <% if visible_accounts.any? %>
+ <%= render "accounts/index/account_groups", accounts: visible_accounts %>
<% end %>
<%# Sync summary (collapsible) - using shared ProviderSyncSummary component %>
@@ -86,7 +88,7 @@
end %>
<%= render ProviderSyncSummary.new(
stats: stats,
- provider_item: mercury_item,
+ provider_item: mercury_item, show_account_details: visible_accounts.size == mercury_item.accounts.size,
institutions_count: mercury_item.connected_institutions.size
) %>
diff --git a/app/views/monobank_items/_monobank_item.html.erb b/app/views/monobank_items/_monobank_item.html.erb
index 50ef26ec89..b4124f42ae 100644
--- a/app/views/monobank_items/_monobank_item.html.erb
+++ b/app/views/monobank_items/_monobank_item.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (monobank_item:) %>
+<%# locals: (monobank_item:, visible_accounts:) %>
<%= tag.div id: dom_id(monobank_item) do %>
<%= render DS::Disclosure.new(variant: :card, open: true) do |disclosure| %>
@@ -17,7 +17,9 @@
<% end %>
</div>
- <% if monobank_item.accounts.any? %>
+ <%# The institution belongs to every account on the connection, so it is
+ shown only to a viewer who can see them all (#3630). %>
+ <% if monobank_item.accounts.any? && visible_accounts.size == monobank_item.accounts.size %>
<p class="text-xs text-secondary"><%= monobank_item.institution_summary %></p>
<% end %>
@@ -62,8 +64,8 @@
<% unless monobank_item.scheduled_for_deletion? %>
<div class="space-y-4 mt-4">
- <% if monobank_item.accounts.any? %>
- <%= render "accounts/index/account_groups", accounts: monobank_item.accounts %>
+ <% if visible_accounts.any? %>
+ <%= render "accounts/index/account_groups", accounts: visible_accounts %>
<% end %>
<% stats = if defined?(@monobank_sync_stats_map) && @monobank_sync_stats_map
@@ -73,7 +75,7 @@
end %>
<%= render ProviderSyncSummary.new(
stats: stats,
- provider_item: monobank_item,
+ provider_item: monobank_item, show_account_details: visible_accounts.size == monobank_item.accounts.size,
institutions_count: monobank_item.connected_institutions.size
) %>
diff --git a/app/views/plaid_items/_plaid_item.html.erb b/app/views/plaid_items/_plaid_item.html.erb
index 5860b7349d..6b93384d1e 100644
--- a/app/views/plaid_items/_plaid_item.html.erb
+++ b/app/views/plaid_items/_plaid_item.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (plaid_item:) %>
+<%# locals: (plaid_item:, visible_accounts:) %>
<%= tag.div id: dom_id(plaid_item) do %>
<%= render DS::Disclosure.new(variant: :card, open: true) do |disclosure| %>
@@ -83,15 +83,12 @@
<% unless plaid_item.scheduled_for_deletion? %>
<div class="space-y-4 mt-4">
- <%# NOTE: no per-viewer filtering here. This partial is also rendered
- by PlaidItem::SyncCompleteEvent from the sync job, where
- Current.user is nil (same gotcha as accounts/_sync_controls), so a
- viewer-dependent filter would empty the list for everyone on every
- broadcast. Visibility is decided in AccountsController#visible_provider_items
- instead, which only shows an owner a card whose accounts they can
- already see. %>
- <% if plaid_item.accounts.any? %>
- <%= render "accounts/index/account_groups", accounts: plaid_item.accounts %>
+ <%# The accounts index passes visible_accounts filtered to the viewer
+ (AccountsController#visible_card_accounts). Nothing here reads
+ Current.user: the partial can be rendered outside a request, where
+ it is nil. %>
+ <% if visible_accounts.any? %>
+ <%= render "accounts/index/account_groups", accounts: visible_accounts %>
<% end %>
<%# Sync summary (collapsible) - using shared ProviderSyncSummary component %>
@@ -102,7 +99,7 @@
end %>
<%= render ProviderSyncSummary.new(
stats: stats,
- provider_item: plaid_item
+ provider_item: plaid_item, show_account_details: visible_accounts.size == plaid_item.accounts.size
) %>
<% if plaid_item.accounts.empty? %>
diff --git a/app/views/questrade_items/_questrade_item.html.erb b/app/views/questrade_items/_questrade_item.html.erb
index 6536fecb92..09ac3a2d0f 100644
--- a/app/views/questrade_items/_questrade_item.html.erb
+++ b/app/views/questrade_items/_questrade_item.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (questrade_item:) %>
+<%# locals: (questrade_item:, visible_accounts:) %>
<%= tag.div id: dom_id(questrade_item) do %>
<%= render DS::Disclosure.new(variant: :card, open: true) do |disclosure| %>
@@ -64,8 +64,8 @@
<% unless questrade_item.scheduled_for_deletion? %>
<div class="space-y-4 mt-4">
- <% if questrade_item.accounts.any? %>
- <%= render "accounts/index/account_groups", accounts: questrade_item.accounts %>
+ <% if visible_accounts.any? %>
+ <%= render "accounts/index/account_groups", accounts: visible_accounts %>
<% end %>
<% stats = if defined?(@questrade_sync_stats_map) && @questrade_sync_stats_map
@@ -75,7 +75,7 @@
end %>
<%= render ProviderSyncSummary.new(
stats: stats,
- provider_item: questrade_item,
+ provider_item: questrade_item, show_account_details: visible_accounts.size == questrade_item.accounts.size,
institutions_count: questrade_item.connected_institutions.size
) %>
diff --git a/app/views/redbark_items/_redbark_item.html.erb b/app/views/redbark_items/_redbark_item.html.erb
index b1e940ee5a..a28cab3152 100644
--- a/app/views/redbark_items/_redbark_item.html.erb
+++ b/app/views/redbark_items/_redbark_item.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (redbark_item:) %>
+<%# locals: (redbark_item:, visible_accounts:) %>
<%= tag.div id: dom_id(redbark_item) do %>
<%= render DS::Disclosure.new(variant: :card, open: true) do |disclosure| %>
@@ -77,8 +77,8 @@
<% unless redbark_item.scheduled_for_deletion? %>
<div class="space-y-4 mt-4">
- <% if redbark_item.accounts.any? %>
- <%= render "accounts/index/account_groups", accounts: redbark_item.accounts %>
+ <% if visible_accounts.any? %>
+ <%= render "accounts/index/account_groups", accounts: visible_accounts %>
<% end %>
<%# Sync summary (collapsible) - using shared ProviderSyncSummary component %>
@@ -89,7 +89,7 @@
end %>
<%= render ProviderSyncSummary.new(
stats: stats,
- provider_item: redbark_item
+ provider_item: redbark_item, show_account_details: visible_accounts.size == redbark_item.accounts.size
) %>
<%# Compute unlinked accounts (no AccountProvider link) %>
diff --git a/app/views/simplefin_items/_simplefin_item.html.erb b/app/views/simplefin_items/_simplefin_item.html.erb
index 5ddcdf040f..1c3e805aa4 100644
--- a/app/views/simplefin_items/_simplefin_item.html.erb
+++ b/app/views/simplefin_items/_simplefin_item.html.erb
@@ -1,7 +1,10 @@
-<%# locals: (simplefin_item:) %>
+<%# locals: (simplefin_item:, visible_accounts:) %>
<%= tag.div id: dom_id(simplefin_item) do %>
<% accounts = simplefin_item.accounts %>
+ <%# The names below come from every account on the connection, so a viewer
+ shared only some of them sees counts, not names (#3630). %>
+ <% all_accounts_visible = visible_accounts.size == accounts.size %>
<%# Compute unlinked count early so it's available for both menu and bottom section %>
<% unlinked_count = if defined?(@simplefin_unlinked_count_map) && @simplefin_unlinked_count_map
@simplefin_unlinked_count_map[simplefin_item.id] || 0
@@ -33,7 +36,7 @@
<p class="text-destructive text-sm animate-pulse"><%= t(".deletion_in_progress") %></p>
<% end %>
</div>
- <% if accounts.any? %>
+ <% if all_accounts_visible && accounts.any? %>
<p class="text-xs text-secondary">
<%= simplefin_item.institution_summary %>
</p>
@@ -96,7 +99,7 @@
<%= tag.span pending_status[:message], class: "text-sm" %>
<span class="text-xs text-subdued"><%= t(".stale_pending_note") %></span>
</div>
- <% if pending_status[:accounts]&.any? %>
+ <% if all_accounts_visible && pending_status[:accounts]&.any? %>
<div class="text-xs text-subdued ml-5">
<%= t(".stale_pending_accounts", accounts: pending_status[:accounts].join(", ")) %>
</div>
@@ -187,14 +190,14 @@
<%# Replacement suggestions from the ReplacementDetector (card-fraud swap, etc.).
Only rendered when the latest sync flagged candidate pairs. %>
<% suggestions = ((@simplefin_sync_stats_map || {})[simplefin_item.id] || {})["replacement_suggestions"] %>
- <% if suggestions.is_a?(Array) && suggestions.any? %>
+ <% if all_accounts_visible && suggestions.is_a?(Array) && suggestions.any? %>
<%= render "simplefin_items/replacement_prompt",
simplefin_item: simplefin_item,
suggestions: suggestions %>
<% end %>
- <% if accounts.any? %>
- <%= render "accounts/index/account_groups", accounts: accounts %>
+ <% if visible_accounts.any? %>
+ <%= render "accounts/index/account_groups", accounts: visible_accounts %>
<% end %>
<%# Sync summary (collapsible) - using shared ProviderSyncSummary component
@@ -209,7 +212,8 @@
<%= render ProviderSyncSummary.new(
stats: stats,
provider_item: simplefin_item,
- institutions_count: simplefin_item.connected_institutions.size
+ institutions_count: simplefin_item.connected_institutions.size,
+ show_account_details: all_accounts_visible
) %>
<% if unlinked_count.to_i > 0 && accounts.empty? %>
diff --git a/app/views/snaptrade_items/_snaptrade_item.html.erb b/app/views/snaptrade_items/_snaptrade_item.html.erb
index 56d722a68e..0e7294cbe5 100644
--- a/app/views/snaptrade_items/_snaptrade_item.html.erb
+++ b/app/views/snaptrade_items/_snaptrade_item.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (snaptrade_item:) %>
+<%# locals: (snaptrade_item:, visible_accounts:) %>
<%= tag.div id: dom_id(snaptrade_item) do %>
<% unlinked_count = snaptrade_item.unlinked_accounts_count %>
@@ -22,7 +22,9 @@
<p class="text-destructive text-sm animate-pulse"><%= t(".deletion_in_progress") %></p>
<% end %>
</div>
- <% if snaptrade_item.snaptrade_accounts.any? %>
+ <%# Built from every account on the connection, so it can name a
+ brokerage behind an account this viewer was never shared. %>
+ <% if snaptrade_item.snaptrade_accounts.any? && visible_accounts.size == snaptrade_item.accounts.size %>
<p class="text-xs text-secondary">
<%= snaptrade_item.brokerage_summary %>
</p>
@@ -112,8 +114,8 @@
<% unless snaptrade_item.scheduled_for_deletion? %>
<div class="space-y-4 mt-4">
- <% if snaptrade_item.accounts.any? %>
- <%= render "accounts/index/account_groups", accounts: snaptrade_item.accounts %>
+ <% if visible_accounts.any? %>
+ <%= render "accounts/index/account_groups", accounts: visible_accounts %>
<% end %>
<%# Sync summary (collapsible) - using shared ProviderSyncSummary component %>
@@ -121,7 +123,7 @@
<% activities_pending = snaptrade_item.snaptrade_accounts.any?(&:activities_fetch_pending) %>
<%= render ProviderSyncSummary.new(
stats: stats,
- provider_item: snaptrade_item,
+ provider_item: snaptrade_item, show_account_details: visible_accounts.size == snaptrade_item.accounts.size,
institutions_count: snaptrade_item.snaptrade_accounts.map(&:brokerage_name).uniq.compact.size,
activities_pending: activities_pending
) %>
diff --git a/app/views/sophtron_items/_sophtron_item.html.erb b/app/views/sophtron_items/_sophtron_item.html.erb
index faa4d14513..6a15d5eca9 100644
--- a/app/views/sophtron_items/_sophtron_item.html.erb
+++ b/app/views/sophtron_items/_sophtron_item.html.erb
@@ -1,9 +1,12 @@
-<%# locals: (sophtron_item:) %>
+<%# locals: (sophtron_item:, visible_accounts:) %>
<%= tag.div id: dom_id(sophtron_item) do %>
<% provider_display_name = sophtron_item.provider_display_name %>
<% manual_sync_required = sophtron_item.manual_sync_required? %>
<% connected_institution_options = sophtron_item.connected_institution_options %>
+ <%# Institution names belong to every account on the connection, so they are
+ shown only to a viewer who can see them all (#3630). %>
+ <% all_accounts_visible = visible_accounts.size == sophtron_item.accounts.size %>
<%= render DS::Disclosure.new(variant: :card, open: true) do |disclosure| %>
<% disclosure.with_summary_content do %>
<div class="flex items-center justify-between gap-2">
@@ -28,7 +31,7 @@
<p class="text-destructive text-sm animate-pulse"><%= t(".deletion_in_progress") %></p>
<% end %>
</div>
- <% if sophtron_item.accounts.any? %>
+ <% if all_accounts_visible && sophtron_item.accounts.any? %>
<p class="text-xs text-secondary">
<%= sophtron_item.institution_summary %>
</p>
@@ -71,7 +74,7 @@
<% end %>
<%= render DS::Menu.new do |menu| %>
- <% if connected_institution_options.many? %>
+ <% if all_accounts_visible && connected_institution_options.many? %>
<% connected_institution_options.each do |institution| %>
<% institution_manual_sync_required = sophtron_item.manual_sync_required_for_institution?(institution[:institution_key]) %>
<% menu.with_item(
@@ -106,8 +109,8 @@
<% unless sophtron_item.scheduled_for_deletion? %>
<div class="space-y-4 mt-4">
- <% if sophtron_item.accounts.any? %>
- <%= render "accounts/index/account_groups", accounts: sophtron_item.accounts %>
+ <% if visible_accounts.any? %>
+ <%= render "accounts/index/account_groups", accounts: visible_accounts %>
<% end %>
<%# Sync summary (collapsible) - using shared ProviderSyncSummary component %>
@@ -118,7 +121,7 @@
end %>
<%= render ProviderSyncSummary.new(
stats: stats,
- provider_item: sophtron_item,
+ provider_item: sophtron_item, show_account_details: visible_accounts.size == sophtron_item.accounts.size,
institutions_count: sophtron_item.connected_institutions.size
) %>
diff --git a/app/views/trade_republic_items/_trade_republic_item.html.erb b/app/views/trade_republic_items/_trade_republic_item.html.erb
index c879255013..0fa507d1f7 100644
--- a/app/views/trade_republic_items/_trade_republic_item.html.erb
+++ b/app/views/trade_republic_items/_trade_republic_item.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (trade_republic_item:) %>
+<%# locals: (trade_republic_item:, visible_accounts:) %>
<%= tag.div id: dom_id(trade_republic_item) do %>
<% unlinked_count = trade_republic_item.unlinked_accounts_count %>
@@ -80,48 +80,52 @@
<% unless trade_republic_item.scheduled_for_deletion? %>
<div class="space-y-4 mt-4">
- <% if trade_republic_item.accounts.any? %>
- <%= render "accounts/index/account_groups", accounts: trade_republic_item.accounts %>
+ <% if visible_accounts.any? %>
+ <%= render "accounts/index/account_groups", accounts: visible_accounts %>
<% end %>
<% stats = trade_republic_item.syncs.ordered.first&.sync_stats || {} %>
- <%= render ProviderSyncSummary.new(stats: stats, provider_item: trade_republic_item) %>
+ <%= render ProviderSyncSummary.new(stats: stats, provider_item: trade_republic_item, show_account_details: visible_accounts.size == trade_republic_item.accounts.size) %>
- <% quality = trade_republic_item.data_quality_summary %>
- <% reconciliation = trade_republic_item.reconciliation_summary %>
- <% expenses = trade_republic_item.expense_summary %>
- <div class="rounded-lg border border-secondary bg-container-inset p-3 space-y-3">
- <div class="flex items-center justify-between gap-2">
- <p class="text-sm font-medium text-primary"><%= t(".data_quality.title") %></p>
- <% if Current.user&.admin? %>
- <%= button_to repair_trade_republic_item_path(trade_republic_item), method: :post,
- class: "text-xs text-primary underline", data: { turbo: false } do %>
- <%= t(".data_quality.repair") %>
+ <%# The data-quality figures are totals over every account on the
+ connection, so a viewer shared only some of them doesn't see them (#3630). %>
+ <% if visible_accounts.size == trade_republic_item.accounts.size %>
+ <% quality = trade_republic_item.data_quality_summary %>
+ <% reconciliation = trade_republic_item.reconciliation_summary %>
+ <% expenses = trade_republic_item.expense_summary %>
+ <div class="rounded-lg border border-secondary bg-container-inset p-3 space-y-3">
+ <div class="flex items-center justify-between gap-2">
+ <p class="text-sm font-medium text-primary"><%= t(".data_quality.title") %></p>
+ <% if Current.user&.admin? %>
+ <%= button_to repair_trade_republic_item_path(trade_republic_item), method: :post,
+ class: "text-xs text-primary underline", data: { turbo: false } do %>
+ <%= t(".data_quality.repair") %>
+ <% end %>
<% end %>
+ </div>
+ <div class="grid gap-2 sm:grid-cols-2 lg:grid-cols-4 text-xs">
+ <span class="text-secondary"><%= t(".data_quality.positions", count: quality[:positions]) %></span>
+ <span class="text-secondary"><%= t(".data_quality.unpriced", count: quality[:unpriced_positions]) %></span>
+ <span class="text-secondary"><%= t(".data_quality.events", count: quality[:events]) %></span>
+ <span class="text-secondary"><%= t(".data_quality.unknown", count: quality[:unknown_events]) %></span>
+ <span class="text-secondary"><%= t(".data_quality.pending_trade_details", count: quality[:pending_trade_details]) %></span>
+ </div>
+ <div class="grid gap-2 sm:grid-cols-2 text-xs">
+ <% expense_money = Money.new(expenses[:total].round(2), trade_republic_item.currency) %>
+ <span class="text-secondary"><%= t(".data_quality.expenses", count: expenses[:count], amount: format_money(expense_money)) %></span>
+ <span class="text-secondary"><%= t(".data_quality.reconciliation", matched: reconciliation.count { |check| check[:reconciled] }, total: reconciliation.size) %></span>
+ </div>
+ <% recent_syncs = trade_republic_item.sync_history(limit: 3) %>
+ <% if recent_syncs.any? %>
+ <div class="border-t border-secondary pt-2 space-y-1">
+ <p class="text-xs font-medium text-primary"><%= t(".data_quality.sync_history") %></p>
+ <% recent_syncs.each do |recent_sync| %>
+ <p class="text-xs text-secondary"><%= l(recent_sync.created_at, format: :short) %> · <%= t(".data_quality.sync_status.#{recent_sync.status}", default: recent_sync.status.to_s.humanize) %></p>
+ <% end %>
+ </div>
<% end %>
</div>
- <div class="grid gap-2 sm:grid-cols-2 lg:grid-cols-4 text-xs">
- <span class="text-secondary"><%= t(".data_quality.positions", count: quality[:positions]) %></span>
- <span class="text-secondary"><%= t(".data_quality.unpriced", count: quality[:unpriced_positions]) %></span>
- <span class="text-secondary"><%= t(".data_quality.events", count: quality[:events]) %></span>
- <span class="text-secondary"><%= t(".data_quality.unknown", count: quality[:unknown_events]) %></span>
- <span class="text-secondary"><%= t(".data_quality.pending_trade_details", count: quality[:pending_trade_details]) %></span>
- </div>
- <div class="grid gap-2 sm:grid-cols-2 text-xs">
- <% expense_money = Money.new(expenses[:total].round(2), trade_republic_item.currency) %>
- <span class="text-secondary"><%= t(".data_quality.expenses", count: expenses[:count], amount: format_money(expense_money)) %></span>
- <span class="text-secondary"><%= t(".data_quality.reconciliation", matched: reconciliation.count { |check| check[:reconciled] }, total: reconciliation.size) %></span>
- </div>
- <% recent_syncs = trade_republic_item.sync_history(limit: 3) %>
- <% if recent_syncs.any? %>
- <div class="border-t border-secondary pt-2 space-y-1">
- <p class="text-xs font-medium text-primary"><%= t(".data_quality.sync_history") %></p>
- <% recent_syncs.each do |recent_sync| %>
- <p class="text-xs text-secondary"><%= l(recent_sync.created_at, format: :short) %> · <%= t(".data_quality.sync_status.#{recent_sync.status}", default: recent_sync.status.to_s.humanize) %></p>
- <% end %>
- </div>
- <% end %>
- </div>
+ <% end %>
<% if Current.user&.admin? %>
<% if unlinked_count > 0 && trade_republic_item.accounts.empty? %>
diff --git a/app/views/trading212_items/_trading212_item.html.erb b/app/views/trading212_items/_trading212_item.html.erb
index 2fb8365283..5b13e7a76f 100644
--- a/app/views/trading212_items/_trading212_item.html.erb
+++ b/app/views/trading212_items/_trading212_item.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (trading212_item:) %>
+<%# locals: (trading212_item:, visible_accounts:) %>
<%= tag.div id: dom_id(trading212_item) do %>
<% unlinked_count = trading212_item.unlinked_accounts_count %>
@@ -81,13 +81,12 @@
<% unless trading212_item.scheduled_for_deletion? %>
<div class="space-y-4 mt-4">
- <% visible_accounts = trading212_item.accounts & Current.user.accessible_accounts.to_a %>
<% if visible_accounts.any? %>
<%= render "accounts/index/account_groups", accounts: visible_accounts %>
<% end %>
<% stats = trading212_item.syncs.ordered.first&.sync_stats || {} %>
- <%= render ProviderSyncSummary.new(stats: stats, provider_item: trading212_item) %>
+ <%= render ProviderSyncSummary.new(stats: stats, provider_item: trading212_item, show_account_details: visible_accounts.size == trading212_item.accounts.size) %>
<% if Current.user&.admin? %>
<% if unlinked_count > 0 && trading212_item.accounts.empty? %>
diff --git a/app/views/up_items/_up_item.html.erb b/app/views/up_items/_up_item.html.erb
index e2365d60f2..0f664aad22 100644
--- a/app/views/up_items/_up_item.html.erb
+++ b/app/views/up_items/_up_item.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (up_item:) %>
+<%# locals: (up_item:, visible_accounts:) %>
<%= tag.div id: dom_id(up_item) do %>
<%= render DS::Disclosure.new(variant: :card, open: true) do |disclosure| %>
@@ -17,7 +17,9 @@
<% end %>
</div>
- <% if up_item.accounts.any? %>
+ <%# The institution belongs to every account on the connection, so it is
+ shown only to a viewer who can see them all (#3630). %>
+ <% if up_item.accounts.any? && visible_accounts.size == up_item.accounts.size %>
<p class="text-xs text-secondary"><%= up_item.institution_summary %></p>
<% end %>
@@ -62,8 +64,8 @@
<% unless up_item.scheduled_for_deletion? %>
<div class="space-y-4 mt-4">
- <% if up_item.accounts.any? %>
- <%= render "accounts/index/account_groups", accounts: up_item.accounts %>
+ <% if visible_accounts.any? %>
+ <%= render "accounts/index/account_groups", accounts: visible_accounts %>
<% end %>
<% stats = if defined?(@up_sync_stats_map) && @up_sync_stats_map
@@ -73,7 +75,7 @@
end %>
<%= render ProviderSyncSummary.new(
stats: stats,
- provider_item: up_item,
+ provider_item: up_item, show_account_details: visible_accounts.size == up_item.accounts.size,
institutions_count: up_item.connected_institutions.size
) %>
diff --git a/app/views/wise_items/_wise_item.html.erb b/app/views/wise_items/_wise_item.html.erb
index 544307a15c..50db852bbb 100644
--- a/app/views/wise_items/_wise_item.html.erb
+++ b/app/views/wise_items/_wise_item.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (wise_item:) %>
+<%# locals: (wise_item:, visible_accounts:) %>
<%= tag.div id: dom_id(wise_item) do %>
<%= render DS::Disclosure.new(variant: :card, open: true) do |disclosure| %>
@@ -64,8 +64,8 @@
<% unless wise_item.scheduled_for_deletion? %>
<div class="space-y-4 mt-4">
- <% if wise_item.accounts.any? %>
- <%= render "accounts/index/account_groups", accounts: wise_item.accounts %>
+ <% if visible_accounts.any? %>
+ <%= render "accounts/index/account_groups", accounts: visible_accounts %>
<% end %>
<% unlinked = wise_item.unlinked_accounts_count %>
diff --git a/lib/generators/provider/family/family_generator.rb b/lib/generators/provider/family/family_generator.rb
index ce197352c5..bb7f88d8db 100644
--- a/lib/generators/provider/family/family_generator.rb
+++ b/lib/generators/provider/family/family_generator.rb
@@ -448,7 +448,9 @@ class Provider::FamilyGenerator < Rails::Generators::NamedBase
section = <<~ERB
<% if #{items_var}.any? %>
- <%= render #{items_var}.sort_by(&:created_at) %>
+ <% #{items_var}.sort_by(&:created_at).each do |item| %>
+ <%= render item, visible_accounts: visible_card_accounts(item) %>
+ <% end %>
<% end %>
ERB
diff --git a/lib/generators/provider/family/templates/item_partial.html.erb.tt b/lib/generators/provider/family/templates/item_partial.html.erb.tt
index d79dcd4834..4e53e5a4be 100644
--- a/lib/generators/provider/family/templates/item_partial.html.erb.tt
+++ b/lib/generators/provider/family/templates/item_partial.html.erb.tt
@@ -1,4 +1,4 @@
-<%%= "<" + "%# locals: (#{file_name}_item:) %" + ">" %>
+<%%= "<" + "%# locals: (#{file_name}_item:, visible_accounts:) %" + ">" %>
<%%= "<" + "%= tag.div id: dom_id(#{file_name}_item) do %" + ">" %>
<details open class="group bg-container p-4 shadow-border-xs rounded-xl">
@@ -75,8 +75,8 @@
<%%= "<" + "% unless #{file_name}_item.scheduled_for_deletion? %" + ">" %>
<div class="space-y-4 mt-4">
- <%%= "<" + "% if #{file_name}_item.accounts.any? %" + ">" %>
- <%%= "<" + "%= render \"accounts/index/account_groups\", accounts: #{file_name}_item.accounts %" + ">" %>
+ <%%= "<" + "% if visible_accounts.any? %" + ">" %>
+ <%%= "<" + "%= render \"accounts/index/account_groups\", accounts: visible_accounts %" + ">" %>
<%%= "<" + "% end %" + ">" %>
<%%= "<" + "%# Sync summary (collapsible) - using shared ProviderSyncSummary component %" + ">" %>
@@ -87,7 +87,8 @@
end <%%= "%" + ">" %>
<%%= "<" + "%= render ProviderSyncSummary.new(" %>
stats: stats,
- provider_item: <%= file_name %>_item
+ provider_item: <%= file_name %>_item,
+ show_account_details: visible_accounts.size == <%= file_name %>_item.accounts.size
) <%%= "%" + ">" %>
<%%= "<" + "%# Compute unlinked accounts (no AccountProvider link) %" + ">" %>
diff --git a/test/controllers/accounts_controller_test.rb b/test/controllers/accounts_controller_test.rb
index abbeb44f84..c5449310f5 100644
--- a/test/controllers/accounts_controller_test.rb
+++ b/test/controllers/accounts_controller_test.rb
@@ -112,6 +112,271 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
unregister_fake_chain!
end
+ # #3630. A provider card is admitted for a member as soon as ONE of its
+ # accounts is shared with them, so the card must list only the accounts this
+ # viewer may see. The unshared account is renamed to something no other part
+ # of the page can print, so its absence proves the card filtered it.
+ test "a partially shared member sees only their account on a Plaid card" do
+ shared, unshared = link_two_accounts_to(plaid_items(:one)) do |item, index|
+ item.plaid_accounts.create!(
+ name: "Second Plaid Account", plaid_id: "acc_235_#{index}", plaid_type: "investment",
+ currency: "USD", current_balance: 10
+ )
+ end
+
+ sign_in users(:family_member)
+ get accounts_url
+
+ assert_response :success
+ assert_select "##{dom_id(plaid_items(:one))}"
+ assert_select "turbo-frame##{dom_id(shared)}", count: 1
+ assert_select "turbo-frame##{dom_id(unshared)}", count: 0
+ assert_not_includes response.body, unshared.name
+ end
+
+ test "an admin still sees every account on a Plaid card" do
+ shared, unshared = link_two_accounts_to(plaid_items(:one)) do |item, index|
+ item.plaid_accounts.create!(
+ name: "Second Plaid Account", plaid_id: "acc_235_#{index}", plaid_type: "investment",
+ currency: "USD", current_balance: 10
+ )
+ end
+
+ get accounts_url
+
+ assert_response :success
+ assert_select "turbo-frame##{dom_id(shared)}", count: 1
+ assert_select "turbo-frame##{dom_id(unshared)}", count: 1
+ end
+
+ test "a partially shared member sees only their account on a SimpleFIN card" do
+ item = SimplefinItem.create!(family: families(:dylan_family), name: "Conn 235", access_url: "https://example.com/access")
+ shared, unshared = link_two_accounts_to(item) do |sf_item, index|
+ sf_item.simplefin_accounts.create!(
+ name: "SF #{index}", account_id: "sf_235_#{index}", currency: "USD",
+ current_balance: 1, account_type: "depository"
+ )
+ end
+
+ sign_in users(:family_member)
+ get accounts_url
+
+ assert_response :success
+ assert_select "##{dom_id(item)}"
+ assert_select "turbo-frame##{dom_id(shared)}", count: 1
+ assert_select "turbo-frame##{dom_id(unshared)}", count: 0
+ assert_not_includes response.body, unshared.name
+ end
+
+ # The card's other name-bearing lists. The sync summary's detail rows come
+ # from the connection's last sync and name the accounts and transactions
+ # involved, so they follow the same rule as the account list: shown only to
+ # a viewer who can see every account on the connection. Counts stay.
+ test "a partially shared member does not see account names in a card's sync summary" do
+ item = plaid_items(:one)
+ _shared, unshared = link_two_accounts_to(item) do |p_item, index|
+ p_item.plaid_accounts.create!(
+ name: "Second Plaid Account", plaid_id: "acc_235_#{index}", plaid_type: "investment",
+ currency: "USD", current_balance: 10
+ )
+ end
+ item.syncs.create!(status: "completed", sync_stats: {
+ "tx_seen" => 1, "tx_skipped" => 1,
+ "skip_details" => [ { "name" => "Secret Txn 235", "reason" => "excluded", "account_name" => unshared.name } ],
+ "total_errors" => 1,
+ "errors" => [ { "name" => unshared.name, "message" => "Import failed 235" } ]
+ })
+
+ sign_in users(:family_member)
+ get accounts_url
+
+ assert_response :success
+ assert_not_includes response.body, unshared.name
+ assert_not_includes response.body, "Secret Txn 235"
+ end
+
+ test "an admin still sees the account names in a card's sync summary" do
+ item = plaid_items(:one)
+ link_two_accounts_to(item) do |p_item, index|
+ p_item.plaid_accounts.create!(
+ name: "Second Plaid Account", plaid_id: "acc_235_#{index}", plaid_type: "investment",
+ currency: "USD", current_balance: 10
+ )
+ end
+ item.syncs.create!(status: "completed", sync_stats: {
+ "tx_seen" => 1, "tx_skipped" => 1,
+ "skip_details" => [ { "name" => "Secret Txn 235", "reason" => "excluded", "account_name" => "x" } ]
+ })
+
+ get accounts_url
+
+ assert_response :success
+ assert_includes response.body, "Secret Txn 235"
+ end
+
+ test "a partially shared member does not see unshared names in SimpleFIN's stale-pending and replacement banners" do
+ item = SimplefinItem.create!(family: families(:dylan_family), name: "Conn 235", access_url: "https://example.com/access")
+ _shared, unshared = link_two_accounts_to(item) do |sf_item, index|
+ sf_item.simplefin_accounts.create!(
+ name: "SF #{index}", account_id: "sf_235_#{index}", currency: "USD",
+ current_balance: 1, account_type: "depository"
+ )
+ end
+ SimplefinItem.any_instance.stubs(:stale_pending_status)
+ .returns({ count: 2, message: "2 pending", accounts: [ unshared.name ] })
+ item.syncs.create!(status: "completed", sync_stats: {
+ "replacement_suggestions" => [ {
+ "dormant_sfa_id" => item.simplefin_accounts.find_by!(account_id: "sf_235_1").id,
+ "active_sfa_id" => item.simplefin_accounts.find_by!(account_id: "sf_235_0").id,
+ "sure_account_id" => unshared.id
+ } ]
+ })
+
+ sign_in users(:family_member)
+ get accounts_url
+
+ assert_response :success
+ assert_select "##{dom_id(item)}"
+ assert_not_includes response.body, unshared.name
+ end
+
+ # The card header names the connected institution when there is only one.
+ # That institution is the unshared account's as much as the shared one's,
+ # so it follows the same rule as the other names on the card.
+ test "a partially shared member does not see the connection's institution name" do
+ item = SimplefinItem.create!(family: families(:dylan_family), name: "Conn 235", access_url: "https://example.com/access")
+ link_two_accounts_to(item) do |sf_item, index|
+ sf_item.simplefin_accounts.create!(
+ name: "SF #{index}", account_id: "sf_235_#{index}", currency: "USD",
+ current_balance: 1, account_type: "depository"
+ )
+ end
+ SimplefinItem.any_instance.stubs(:connected_institutions).returns([ { "name" => "Hidden Bank 235" } ])
+
+ sign_in users(:family_member)
+ get accounts_url
+
+ assert_response :success
+ assert_select "##{dom_id(item)}"
+ assert_not_includes response.body, "Hidden Bank 235"
+ end
+
+ test "an admin still sees the connection's institution name" do
+ item = SimplefinItem.create!(family: families(:dylan_family), name: "Conn 235", access_url: "https://example.com/access")
+ link_two_accounts_to(item) do |sf_item, index|
+ sf_item.simplefin_accounts.create!(
+ name: "SF #{index}", account_id: "sf_235_#{index}", currency: "USD",
+ current_balance: 1, account_type: "depository"
+ )
+ end
+ SimplefinItem.any_instance.stubs(:connected_institutions).returns([ { "name" => "Hidden Bank 235" } ])
+
+ get accounts_url
+
+ assert_response :success
+ assert_includes response.body, "Hidden Bank 235"
+ end
+
+ # The SnapTrade card's brokerage line is built from every
+ # account on the connection. With one brokerage it prints that brokerage's
+ # name, so a member shared only the nameless account would read the other's.
+ test "a partially shared member does not see a SnapTrade connection's brokerage" do
+ item = snaptrade_items(:configured_item)
+ # The fixture accounts name two brokerages, which makes the line a count.
+ # Cleared so the only brokerage left is the unshared account's.
+ item.snaptrade_accounts.update_all(brokerage_name: nil)
+ link_two_accounts_to(item) do |st_item, index|
+ st_item.snaptrade_accounts.create!(
+ name: "ST #{index}", snaptrade_account_id: "st_235_#{index}", currency: "USD",
+ current_balance: 1, brokerage_name: (index.zero? ? nil : "Hidden Broker 235")
+ )
+ end
+
+ sign_in users(:family_member)
+ get accounts_url
+
+ assert_response :success
+ assert_select "##{dom_id(item)}"
+ assert_not_includes response.body, "Hidden Broker 235"
+ end
+
+ test "an admin still sees a SnapTrade connection's brokerage" do
+ item = snaptrade_items(:configured_item)
+ # The fixture accounts name two brokerages, which makes the line a count.
+ # Cleared so the only brokerage left is the unshared account's.
+ item.snaptrade_accounts.update_all(brokerage_name: nil)
+ link_two_accounts_to(item) do |st_item, index|
+ st_item.snaptrade_accounts.create!(
+ name: "ST #{index}", snaptrade_account_id: "st_235_#{index}", currency: "USD",
+ current_balance: 1, brokerage_name: (index.zero? ? nil : "Hidden Broker 235")
+ )
+ end
+
+ get accounts_url
+
+ assert_response :success
+ assert_includes response.body, "Hidden Broker 235"
+ end
+
+ test "a partially shared member sees only their account on a Kraken card" do
+ item = kraken_items(:one)
+ shared, unshared = link_two_accounts_to(item) do |k_item, index|
+ k_item.kraken_accounts.create!(
+ name: "Kraken #{index}", account_id: "kraken_235_#{index}", account_type: "combined",
+ currency: "USD", current_balance: 1, extra: {}
+ )
+ end
+
+ sign_in users(:family_member)
+ get accounts_url
+
+ assert_response :success
+ assert_select "##{dom_id(item)}"
+ assert_select "turbo-frame##{dom_id(shared)}", count: 1
+ assert_select "turbo-frame##{dom_id(unshared)}", count: 0
+ end
+
+ test "a partially shared member does not see stale-rate warnings for an unshared Kraken account" do
+ item = kraken_items(:one)
+ shared, unshared = link_two_accounts_to(item) do |k_item, index|
+ k_item.kraken_accounts.create!(
+ name: "Kraken #{index}", account_id: "kraken_stale_#{index}", account_type: "combined",
+ currency: "USD", current_balance: 1,
+ extra: index.zero? ? {} : { "kraken" => { "stale_rate" => "true", "rate_target_date" => "2001-02-03" } }
+ )
+ end
+
+ sign_in users(:family_member)
+ get accounts_url
+ assert_response :success
+ assert_select "##{dom_id(item)}"
+ assert_not_includes response.body, "2001-02-03"
+
+ sign_in users(:family_admin)
+ get accounts_url
+ assert_includes response.body, "2001-02-03"
+ end
+
+ test "a partially shared member does not see a Trade Republic connection's data-quality totals" do
+ item = trade_republic_items(:configured_item)
+ # The fixture item already has one portfolio and one cash account, and
+ # the database allows one of each kind per connection.
+ link_two_accounts_to(item) do |_item, index|
+ trade_republic_accounts(index.zero? ? :main_account : :cash_account)
+ end
+ title = I18n.t("trade_republic_items.trade_republic_item.data_quality.title")
+
+ sign_in users(:family_member)
+ get accounts_url
+ assert_response :success
+ assert_select "##{dom_id(item)}"
+ assert_not_includes response.body, title
+
+ sign_in users(:family_admin)
+ get accounts_url
+ assert_includes response.body, title
+ end
+
test "index renders trading212 items" do
trading212_item = trading212_items(:configured_item)
get accounts_url
@@ -912,6 +1177,27 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
assert_response :success
assert_select "a[href=?]", edit_plaid_item_path(item, add_accounts: true), count: 0
end
+
+ private
+ # #3630. Links a shared and an unshared account to +item+ through two fresh
+ # provider rows built by the block, and returns them in that order. Shares
+ # are reset first so the member's access is exactly the one granted here.
+ def link_two_accounts_to(item)
+ admin = users(:family_admin)
+ member = users(:family_member)
+ shared = accounts(:depository)
+ unshared = accounts(:investment)
+ unshared.update!(name: "Unshared Brokerage 235")
+
+ [ shared, unshared ].each_with_index do |account, index|
+ account.update!(owner: admin)
+ account.account_shares.destroy_all
+ AccountProvider.create!(account: account, provider: yield(item, index))
+ end
+ shared.account_shares.create!(user: member, permission: "read_only")
+
+ [ shared, unshared ]
+ end
end
class AccountsControllerSimplefinCtaTest < ActionDispatch::IntegrationTest
diff --git a/test/integration/plaid_item_broadcast_render_test.rb b/test/integration/plaid_item_broadcast_render_test.rb
index 4d955c7636..f115962cab 100644
--- a/test/integration/plaid_item_broadcast_render_test.rb
+++ b/test/integration/plaid_item_broadcast_render_test.rb
@@ -15,7 +15,7 @@ class PlaidItemBroadcastRenderTest < ActiveSupport::TestCase
html = ApplicationController.render(
partial: "plaid_items/plaid_item",
- locals: { plaid_item: item }
+ locals: { plaid_item: item, visible_accounts: item.accounts }
)
assert_includes html, account.name
diff --git a/test/integration/trading212_item_broadcast_render_test.rb b/test/integration/trading212_item_broadcast_render_test.rb
new file mode 100644
index 0000000000..e48cbedf71
--- /dev/null
+++ b/test/integration/trading212_item_broadcast_render_test.rb
@@ -0,0 +1,18 @@
+require "test_helper"
+
+class Trading212ItemBroadcastRenderTest < ActiveSupport::TestCase
+ # #3630. The card takes its accounts only from visible_accounts, never from
+ # Current.user. It used to filter with Current.user.accessible_accounts
+ # directly, so any render without a viewer raised.
+ test "the connection card renders with no current user" do
+ Current.reset
+ assert_nil Current.user
+
+ assert_nothing_raised do
+ ApplicationController.render(
+ partial: "trading212_items/trading212_item",
+ locals: { trading212_item: trading212_items(:configured_item), visible_accounts: trading212_items(:configured_item).accounts }
+ )
+ end
+ end
+end
diff --git a/test/lib/generators/provider/family_generator_test.rb b/test/lib/generators/provider/family_generator_test.rb
index 8493a6356d..057b69f3bf 100644
--- a/test/lib/generators/provider/family_generator_test.rb
+++ b/test/lib/generators/provider/family_generator_test.rb
@@ -32,6 +32,20 @@ class Provider::FamilyGeneratorTest < ActiveSupport::TestCase
assert_includes rendered, "does not implement the #{'#{disposition}'} disposition"
end
+ # A generated card must require the accounts it lists, so a render that
+ # forgets them fails instead of showing every account on the connection.
+ # Its job has no viewer to filter for, so it sends the toast, never the card.
+ test "the generated card requires visible_accounts and its job does not broadcast it" do
+ card = render_template("item_partial.html.erb.tt", file_name: "gocardless")
+ job = render_template("activities_fetch_job.rb.tt", class_name: "Gocardless", file_name: "gocardless")
+
+ assert_includes card.lines.first, 'locals: (#{file_name}_item:, visible_accounts:)'
+ assert_includes card, 'render \\"accounts/index/account_groups\\", accounts: visible_accounts'
+ assert_parses job
+ assert_not_includes job, '"gocardless_items/gocardless_item"'
+ assert_includes job, "@gocardless_account.gocardless_item&.family&.broadcast_sync_complete"
+ end
+
test "appends to a single-line enum" do
result = append(<<~RUBY)
class ProviderMerchant < Merchant
diff --git a/test/views/provider_item_cards_test.rb b/test/views/provider_item_cards_test.rb
new file mode 100644
index 0000000000..d61b1fd3a9
--- /dev/null
+++ b/test/views/provider_item_cards_test.rb
@@ -0,0 +1,94 @@
+require "test_helper"
+
+# #3630. The accounts index admits a provider card for a member as soon as
+# one of its accounts is shared with them, so every card must list the
+# accounts it is given, never the connection's own account list. The
+# behaviour is tested per provider in AccountsControllerTest; this keeps
+# every card, including one added later, on the same path.
+class ProviderItemCardsTest < ActiveSupport::TestCase
+ # The on-chain wallet's _item partial is its Settings > Providers row; its
+ # accounts-page card is _wallet_card, checked separately below.
+ NOT_CARDS = %w[app/views/onchain_wallet_items/_onchain_wallet_item.html.erb].freeze
+
+ CARDS = Dir[Rails.root.join("app/views/*_items/_*_item.html.erb")].map { |path| path.delete_prefix("#{Rails.root}/") }.sort - NOT_CARDS
+
+ CARD_PARTIALS = CARDS.map { |card| card.delete_prefix("app/views/").sub(%r{/_}, "/").delete_suffix(".html.erb") }
+
+ RENDER_SOURCES = Dir[Rails.root.join("{app,lib}/**/*.{rb,erb,tt}")].sort
+
+ test "there are cards to check" do
+ assert_operator CARDS.size, :>=, 20
+ end
+
+ CARDS.each do |card|
+ item_local = File.basename(card, ".html.erb").delete_prefix("_").to_sym
+
+ test "#{card} lists only the accounts it is given" do
+ source = Rails.root.join(card).read
+
+ assert_match(/locals:.*visible_accounts:/, source, "#{card} must declare a visible_accounts local")
+ source.scan(/render "accounts\/index\/account_groups", accounts: ([^%,]+)/).flatten.each do |accounts|
+ assert_equal "visible_accounts", accounts.strip, "#{card} renders #{accounts.strip}"
+ end
+ end
+
+ # Fail closed: a render that forgets visible_accounts must raise, not fall
+ # back to every account on the connection.
+ test "#{card} refuses to render without visible_accounts" do
+ error = assert_raises(StandardError) do
+ ApplicationController.render(partial: CARD_PARTIALS[CARDS.index(card)], locals: { item_local => Object.new })
+ end
+
+ assert_match(/missing local: :visible_accounts\b/, error.message, "#{card} must require visible_accounts with no default")
+ end
+ end
+
+ # Every render of a card by partial name, including the provider generator's
+ # template. Each must hand the card its accounts explicitly.
+ CARD_REFERENCE = Regexp.union(*CARD_PARTIALS.map { |partial| %("#{partial}") }, %("<%= file_name %>_items/<%= file_name %>_item"))
+
+ CARD_NAMES = CARD_PARTIALS.map { |partial| partial.split("/").last }
+
+ test "every render of a provider card passes visible_accounts" do
+ sites = RENDER_SOURCES.flat_map do |file|
+ source = File.read(file)
+
+ source.enum_for(:scan, CARD_REFERENCE).map do
+ offset = Regexp.last_match.begin(0)
+ call = source[offset..][/\A[^)]*/]
+ site = "#{file.delete_prefix("#{Rails.root}/")}:#{source[0...offset].count("\n") + 1}"
+
+ assert_includes call, "visible_accounts:", "#{site} renders a provider card without visible_accounts"
+ site
+ end
+ end
+
+ # The 12 admin-only controller responses. Sync completions, jobs and the
+ # SimpleFIN syncer no longer render a card at all.
+ assert_operator sites.size, :>=, 12, "found only #{sites.size} render sites; has the scan stopped matching?"
+ end
+
+ test "no provider card is rendered by model, which cannot pass visible_accounts" do
+ by_model = /render[ (]+@?(?:#{CARD_NAMES.join("|")})s?\b(?!:)/
+
+ RENDER_SOURCES.each do |file|
+ assert_no_match by_model, File.read(file), "#{file.delete_prefix("#{Rails.root}/")} renders a provider card by model"
+ end
+ end
+
+ # The on-chain wallet card is rendered by name with a card built in the
+ # controller from accounts_visible_to, not from the item's own accounts.
+ test "the on-chain wallet card lists only the accounts it is given" do
+ source = Rails.root.join("app/views/onchain_wallet_items/_wallet_card.html.erb").read
+
+ assert_includes source, 'render "accounts/index/account_groups", accounts: card[:accounts]'
+ assert_no_match(/onchain_wallet_item\.accounts\b/, source)
+ end
+
+ test "the accounts index gives every provider card its visible accounts" do
+ index = Rails.root.join("app/views/accounts/index.html.erb").read
+
+ assert_no_match(/render @\w+_items/, index)
+ assert_equal index.scan(/render item\b/).size, index.scan(/render item, visible_accounts: visible_card_accounts\(item\)/).size
+ end
+end