Declare how Bank sync loads each provider's items
Merged
JA
2d ago+223+223+012345678901234567890123456789-161-161-012345678901234567890123456789
Summary
Provider kit Track A, A7: how Bank sync loads each family panel provider's items, on the page and in the provider's panel, is declared on its adapter instead of written out twice in Settings::ProvidersController.
Part of #5003
Stacked on #5083 (A6), in Track A's native stack on #5005.
Fork pre-flight: jaysbeekay/sure#692 (same commits, against a mirror of upstream main; its CI, Gatekeeper and review history live there).
What changed
declares_connection ... lists:takes a query per list,settings_page:andsettings_panel:, as scope names (%i[active ordered]) or a lambda over the family's item relation, for the queries that also filter, select or preload.Provider::Base::ITEM_LISTSholds the defaults (pageordered.select(:id), panelordered); an unknown list name raisesArgumentError. This form was chosen over named scopes alone (which cannot express the credential filters,select(:id), preloads or nested includes) and over a class method per list on each item model.load_provider_items(the panel, viaconnect_form) andprepare_show_context(the page) both load throughPANEL_CONNECTIONSandload_items; the 26-branchcaseand the 26 hand-written assignments are gone. 24 adapters declare where they differ from the defaults.- The
provider:familygenerator no longer patchesprepare_show_context(update_settings_controllerdeleted). Its adapter template declareslists: { settings_panel: ->(items) { items.where.not(<secret>: [ nil, "" ]) } }, the query the generated panel used as its fallback, so a generated panel still counts only connections that have their secret field. The generator guide is updated. - Diff: non-test +120 / −158.
No visible change.
Demo data
No demo data needed.
Migration notes
No migration.
Verification
- Old vs new (Rails runner, old methods loaded as a separate class): for all 26 panel providers, page and panel, the SQL,
includes,preload,eager_loadandselectvalues are identical;plaid,financekitand an unknown key still load nothing in the panel. - Fail-first: "each panel provider declares the queries its Bank sync page and panel load items with" (pins all 52 queries), "Bank sync and each panel load items through the declared list queries" and "a list query may be scope names or a lambda, and an unknown list is rejected" failed before the change (no lists on the declarations); the two generator template tests failed before the template change.
- Mutations, each caught: either default changed; only the first scope applied; no unknown-list guard; panel loads the page list and vice versa; Brex's panel without its preloads; Lunch Flow's page without its credential filter; Akahu's page list dropped; SnapTrade's panel without its preload.
eager_load!clean.bin/rails test(full): 15,878 runs, 0 failures; 8 errors inReleaseNotesWorkflowTestfromnodemissing in the test image. After rebasing the stack onto upstreammain(dbeebf14c), the full suite at the top of the stack (A9): 16,246 runs, 0 failures, the same 8 environment errors.bin/rubocopon changed files: no offenses.bin/brakeman: no warnings.
Blast radius
load_provider_itemshas one caller,connect_form, which passes a key only afterFAMILY_PANELS.find;params[:provider_key]is only compared, never used to build a method or variable name.- The page's
@<key>_itemsare read byprovider_summary(A5),family_panel_items(A6) and the panel partials; all receive the same relations as before. ProviderConnectionStatus::PROVIDERSand the A1 declaration tests compare the same frozen declaration hashes, now carryinglists:.- Generated providers: page query unchanged (
ordered.select(:id), as the deleted patch wrote); panel query now declared by the template, equal to the panel's old fallback. - Siblings left for A8: the
/accountsitem loads and sync preload inAccountsController.
Summary by cubic
Declares on each provider's adapter how Bank sync loads that provider's items for the page and for the panel, removing the duplicated hand-written loads in Settings::ProvidersController. Part of #5003.
declares_connectionnow takeslists:with a query per list (settings_page,settings_panel), as scope names or a lambda over the family's items;Provider::Base::ITEM_LISTSholds the defaults.- The
provider:familygenerator no longer patches the controller; its adapter template declares the panel query so a generated panel still counts only connections that have their secret field (the first field marked secret in the generated fields), with tests covering a secret that isn'tapi_key. - No visible behavior change — the SQL, preloads and selected columns match the previous implementation for all 26 panel providers.
Summary by CodeRabbit
- Improvements
- Provider connections are displayed in settings pages and panels according to each provider’s active-status, ordering, and credential requirements.
- Provider panels load related account and sync details alongside connections where needed.
- Documentation
- Updated the provider setup guide with connection-list configuration and troubleshooting guidance.