Serve Brex connections and account linking from ProviderItemsController

JA
5d ago
+348-203

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 from BrexItemsController, and preload, select and link from BrexItems::AccountFlowsController, moved with the provider named by its declaration:
    • the connection is found from the adapter's declares_connection whose 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: from params[:<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.
  • BrexItemsController < ProviderItemsController keeps only #item_params (unchanged).
  • config/routes.rb: a provider_items concern holds the five collection routes and sync; resources :brex_items uses it. Brex's setup routes still go to BrexItems::AccountSetupsController until 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. BrexItemsControllerTest and the other Brex, settings and provider connection tests pass unedited (210 runs, 0 failures).
  • Contract (fail-first): a new ProviderItemsControllerTests module (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 ProviderItemsController with 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 as brex_items/account_flows, and the request is served by BrexItems::AccountFlowsController.
  • 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_item ivar 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 in safe_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 8 ReleaseNotesWorkflowTest errors (no node in the test image).
  • bin/rubocop on changed files: no offenses. bin/brakeman: no warnings. No ERB or JS changed.
  • Diff with copy detection (git diff -C against 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_panel gets the same key and the same brex_items: local.
  • Lazy lookups (t(".success")) still resolve under brex_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).