Show a member only the provider accounts shared with them
Summary
/accounts shows a member a provider connection's card as soon as one of its accounts is shared with them (AccountsController#visible_provider_items). The card partials then list every account on the connection, so the member reads the names and balances of accounts nobody shared with them. This PR passes each card the accounts the viewer may see, and the card lists only those. Admins still see every account.
Part of #3630
#4046 (merged) closed the stream side. This PR closes the HTTP side: the card a member is served lists only their accounts. Account rows are a third route, closed by #4050.
Fork pre-flight PR: jaysbeekay/sure#353 (same branch, same commit; its CI and review history are there).
What changed
AccountsController#visible_card_accounts(item)(ahelper_method) returns the item's accounts filtered to@accessible_account_ids, or all of them for an admin.accounts/index.html.erbrenders every provider card withvisible_accounts: visible_card_accounts(item).- Every
*_items/_*_itemcard partial requires avisible_accounts:local (a strict-locals declaration with no default) and passes it toaccounts/index/account_groups. A render that leaves it out raisesActionView::StrictLocalsErrorinstead of listing every account on the connection, so the filter fails closed. - Every other render site passes
visible_accountsexplicitly. The admin-only Turbo Stream responses in the Binance, Brex, Coinbase, Enable Banking, Lunch Flow, Mercury, SimpleFIN and Sophtron controllers (12 sites, all behindrequire_admin!) pass the item's full accounts, with a comment saying why. These are the only render sites left: #4046 removed the sync broadcasts. ProviderSyncSummarytakesshow_account_details:. When the viewer can't see every account on the connection, the summary shows counts but not the other accounts' names. It still shows totals across every account on the connection (transactions seen and imported, holdings found, errors, institution count), with no account names or amounts. That is intended.- SimpleFIN, Sophtron and SnapTrade hide their institution and brokerage lines, and SimpleFIN its stale-pending and replacement banners, from a viewer who can't see every account, because those lines are built from all of them.
- Trading212: its inline
Current.userfilter moves to the same local, so the card no longer raises when rendered without a viewer. - Generator: the provider generator's item partial template requires
visible_accountstoo, and the index section it inserts passes it. - Other per-connection figures: the Kraken, CoinSpot and Binance stale-rate warnings cover only the visible accounts. Trade Republic's data-quality panel (positions, events, expenses, reconciliation) is a total over every account, so it's shown only to a viewer who can see them all.
Deliberately not changed:
- The family-wide card broadcasts on sync completion. #4046 removed them; it is the other half of #3630.
visible_provider_items, which decides whether a card appears at all. Only a comment changes.- Group totals across cards.
Demo data
No demo data needed: demo families have no shared provider connections.
Screenshots
For an admin, nothing changes. For a member shared one account of a two-account connection, the card lists one account instead of two, and the sync summary and institution line are hidden. The layout is the same in both cases.
Migration notes
No migration.
Verification
Tests were written first. On main (a92dec1e6), 8 of the new AccountsControllerTest and Trading212ItemBroadcastRenderTest cases fail:
- a partially shared member sees only their account on a Plaid, SimpleFIN and Kraken card;
- doesn't see account names in the sync summary;
- doesn't see the institution name, the SnapTrade brokerage, or SimpleFIN's banners;
- the trading212 card renders with no current user.
The admin counterparts pass before and after, as guards should.
Two more fail on main: "a partially shared member does not see stale-rate warnings for an unshared Kraken account" and "...does not see a Trade Republic connection's data-quality totals". Each also checks that the admin still sees them.
ProviderItemCardsTest finds every card partial by file name (24 of them, so a newly added provider is covered too). Each must declare visible_accounts, render only it, and refuse to render without it: the test renders each card with only its item and expects missing local: :visible_accounts. The test also scans app/ and lib/ for every render of a card partial (12 sites, the admin-only controller responses) and requires visible_accounts: in each, rejects rendering a card by model, and checks that the index gives every card visible_card_accounts(item) and that the on-chain wallet card, built in the controller, renders only card[:accounts]. On the previous head (ff432dcd9), 25 of its 53 cases fail: the 24 cards (each fails with undefined method 'accounts', its default being evaluated) and the render-site scan (binance_items_controller.rb:151 renders a provider card without visible_accounts). Provider::FamilyGeneratorTest checks the generator's card template requires the local, and that its job template sends the toast rather than rendering the card.
Mutations, each caught: restoring the default on the Plaid card; dropping the local at the Mercury controller site; restoring the default in the generator's card template; rendering @plaid_items by model in the index. After the rebase onto #4046, re-checked on 184a46bcb: dropping the local at the Mercury controller site, adding a card broadcast without it back into the Plaid sync event, and putting a card broadcast back into the generator's job template each fail a test.
Commands:
bin/rails teston184a46bcb(rebased ontomainat275f2f994): 11,418 runs, 52,748 assertions, 0 failures, 0 errors, 34 skips.bin/rubocopon the changed Ruby files: no offenses.erb_linton the changed ERB: no errors.bin/brakeman --no-pager: 0 warnings.- No JavaScript changed.
Blast radius
- The card partials are also rendered by provider controllers' Turbo Stream responses, every one of them behind
require_admin!. They now passvisible_accounts: item.accountsexplicitly. For an admin that's the same listvisible_card_accountsreturns. The sync broadcasts that used to render them were removed by #4046; the rebase onto it kept its deletions. ProviderSyncSummarydefaultsshow_account_details:totrue, so its other callers are unchanged.
Summary by CodeRabbit
- Bug Fixes
- Provider connection cards now show only accounts a viewer is permitted to access. Account names, sync details, warnings, and other account-specific information are hidden when they include accounts outside the viewer’s access.
- Administrators retain access to all account details, and aggregate sync statistics remain available.