Serve Brex connections and account linking from ProviderItemsController
JA
5d ago+348+348+012345678901234567890123456789-203-203-012345678901234567890123456789
Summary
Provider kit Track B, B3a: a shared ProviderItemsController and a provider_items route concern take over Brex's connection management and account linking. BrexItemsController becomes a thin subclass naming its permitted params; BrexItems::AccountFlowsController goes. Every route helper and path stays as it is.
Part of jaysbeekay/sure#670 (Track B, item 3, first of two slices: B3a connection and account linking, B3b account setup). Stacked on B2c (jaysbeekay/sure#718) in fork stack #687.
Upstream draft PR: https://github.com/we-promise/sure/pull/5230 (same branch, same commit), in native stack we-promise/sure#5268 on refactor/provider-kit.
What changed
ProviderItemsController(new): index, show, new, create, edit, update, destroy and sync fromBrexItemsController, and preload, select and link fromBrexItems::AccountFlowsController, moved with the provider named by its declaration:- the connection is found from the adapter's
declares_connectionwhose association matches the controller (brex_items), so the item class, key and accounts association come from Track A's declaration; - views and partials stay the provider's own (
<key>_items/select_accounts,…/setup_required,…/api_error), messages come from<key>_items.*, and the views keep reading@<key>_item/@<key>_items; - the flow is built with the generic
item_id:/provider_account_id:fromparams[:<key>_item_id]/params[:<key>_account_id], the same params as before; - the admin guard covers the same actions as before: everything but index and show.
- the connection is found from the adapter's
BrexItemsController < ProviderItemsControllerkeeps only#item_params(unchanged).config/routes.rb: aprovider_itemsconcern holds the five collection routes andsync;resources :brex_itemsuses it. Brex's setup routes still go toBrexItems::AccountSetupsControlleruntil B3b.
Nothing user-visible changes.
Demo data
No demo data needed: no new records or UI.
Migration notes
No migration.
Verification
- Existing tests unchanged: the
test/diff against B2c only adds two files.BrexItemsControllerTestand the other Brex, settings and provider connection tests pass unedited (210 runs, 0 failures). - Contract (fail-first): a new
ProviderItemsControllerTestsmodule (the integration-test half of the lifecycle contract) adds- "the shared controller serves the connection's routes at their usual paths" (each helper's path, and the route recognised as
<key>_items#<action>), - "a member who is not an admin can neither change the connection nor link accounts" (eight requests, each rejected by
ProviderItemsControllerwith the admin alert; nothing created, renamed or scheduled for deletion), - "syncing a connection that is already syncing starts nothing",
- "removing a connection unlinks its accounts and schedules its deletion".
Before the change the first two fail: the routes recognise asbrex_items/account_flows, and the request is served byBrexItems::AccountFlowsController.
- "the shared controller serves the connection's routes at their usual paths" (each helper's path, and the route recognised as
- Mutations, each caught: the account-linking actions not admin-gated; the item id read from the wrong param; the provider account id read from the wrong param; the
@brex_itemivar not set; syncing while already syncing; creating without the default name; updating without expiring the accounts cache; destroying without unlinking. One survives as equivalent: dropping the///\check insafe_return_to_path, because the host and parse checks after it reject the same paths. bin/rails test(full, at the B3a commit): 16,274 runs, 0 failures; the same 8ReleaseNotesWorkflowTesterrors (nonodein the test image).bin/rubocopon changed files: no offenses.bin/brakeman: no warnings. No ERB or JS changed.- Diff with copy detection (
git diff -Cagainst B2c): non-test +249 / -203. - Checked against upstream AGENTS.md (blob 1a5dbebd, 2026-11-17): no deviations.
Blast radius
- Every Brex route keeps its helper name and path: views, the settings panel and the preload JS hit the same URLs.
render_provider_panelgets the same key and the samebrex_items:local.- Lazy lookups (
t(".success")) still resolve underbrex_items.<action>, because they follow the routed controller's path. - Siblings: the other providers' controllers keep their own copies of these actions and of
safe_return_to_path; they move in their own slices (B7, B8 and later).