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 jaysbeekay/sure#235 (fork issue). Upstream issue: we-promise/sure#3630.
Depends on we-promise/sure#4046 (fork jaysbeekay/sure#352) for the stream side. This PR closes the HTTP side: the card a member is served lists only their accounts. Until we-promise/sure#4046 merges, the sync-completion broadcasts still send each card with every account to the whole family stream. Account rows are a third route, closed by we-promise/sure#4050.
Upstream PR: we-promise/sure#4048 (same branch, same commit).
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. The sync broadcasts (22SyncCompleteEvents,SimplefinItem::Syncer,SimplefinItem::BalancesOnlyJob, the Questrade and Indexa Capital activity-fetch jobs, and the generator's job template) passitem.accounts, as they effectively did before, until we-promise/sure#4046 removes them. The two activity-fetch jobs relied on Turbo's implicit item local and now pass both locals. 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. They're in jaysbeekay/sure#352 (upstream we-promise/sure#4046), the other half of we-promise/sure#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 (39 sites) 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 its job template passes it.
Mutations, each caught: restoring the default on the Plaid card; dropping the local at the Mercury controller site, at the Plaid sync broadcast, and from the generator's job template; restoring the default in the generator's card template; rendering @plaid_items by model in the index.
Commands:
bin/rails teston93ecc7d4b: 10,901 runs, 50,583 assertions, 0 failures, 0 errors, 33 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!) and by the sync broadcasts. Both now passvisible_accounts: item.accountsexplicitly. For an admin that's the same listvisible_card_accountsreturns. we-promise/sure#4046 removes the broadcasts; whichever of the two PRs merges second resolves the overlap by keeping we-promise/sure#4046's deletions. ProviderSyncSummarydefaultsshow_account_details:totrue, so its other callers are unchanged.