Serve Brex connections and account linking from ProviderItemsController
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 #5003 (Track B, item 3, first of two slices: B3a connection and account linking, B3b account setup).
Stacked on #5229. Fork pre-flight: jaysbeekay/sure#719 (same branch, same commit; its CI, Gatekeeper review and screenshot history live there).
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).
Summary by cubic
Moves Brex connection management and account linking onto a shared ProviderItemsController. BrexItemsController becomes a thin subclass naming its permitted params, and BrexItems::AccountFlowsController is removed. Every route helper and path stays the same, so nothing user-visible changes.
Refactors
- The shared controller reads its item class, provider key, and accounts association from the provider's
declares_connectiondeclaration instead of hardcoding them. - Views, partials, messages, and ivars remain the provider's own (
brex_items.*). - A
provider_itemsroute concern holds the collection routes andsync; Brex's setup routes still go toBrexItems::AccountSetupsControlleruntil the next slice. - The non-admin contract test now also sends
new,create, andedit, so the admin guard covers every mutating action including account linking.
Summary by CodeRabbit
- Updates
- Brex account setup, account selection and linking, connection management, and sync are now handled through the provider connection experience.
- Existing Brex setup and account-linking routes remain available.