Add PATCH /api/v1/accounts/:id

AR
13m ago
+549-14

Problem

The accounts API is read-only (index/show). A client can list accounts but cannot change an account's name, institution or icon; that has to be done in the web UI.

Change

Adds PATCH /api/v1/accounts/:id, which edits what the account form edits, except balance, currency and type, whose changes restate the account's history:

  • name, institution_name, institution_domain, exclude_from_reports
  • logo, as a multipart/form-data upload in account[logo]

It behaves like the account form: a new institution domain queues the icon fetch unless a logo is uploaded in the same request, an uploaded logo takes over from Brandfetch, and the edited fields are locked so a provider sync does not overwrite them.

Requires the read_write scope and full access to the account (owner or full_control share). An account the caller cannot see is a 404, one shared read-only is a 403, and a validation error saves nothing. A null or blank exclude_from_reports is a 422. A missing or non-object account param, or one with no editable fields, is a 400.

No migration.

Related: #5834 adds POST /api/v1/accounts. This PR covers updating only and does not depend on it, but both edit the accounts API controller and routes, so whichever merges second may need a rebase.

Validation

  • New Minitest coverage in test/controllers/api/v1/accounts_controller_test.rb; documentation-only rswag spec added and docs/api/openapi.yaml regenerated.
  • Full bin/rails test: 20,313 runs, 0 failures, 0 errors, 9 skips.
  • RuboCop, ERB lint, Biome, Brakeman, bundler-audit and test/support/verify_api_endpoint_consistency.rb clean.
  • Not run: system tests (API-only change).

🤖 Generated with Claude Code


Summary by cubic

Adds PATCH /api/v1/accounts/:id so the API can edit account details that previously required the app UI.

  • Updates name, institution_name, institution_domain, exclude_from_reports, and logo (as a multipart/form-data upload in account[logo]); balance, currency, and type are intentionally not editable through this endpoint.
  • Behaves like the account form: a new institution domain queues an icon fetch unless a logo is uploaded in the same request, and an uploaded logo overrides Brandfetch.
  • Requires the read_write scope and full access (owner or full_control share); accounts the caller cannot see return 404, read-only shares return 403, and validation errors save nothing.
  • The update runs under a row lock and locks the edited fields, so overlapping PATCH requests can't drop each other's locks and a provider sync can't overwrite an edit.
  • Malformed requests are client errors: blank exclude_from_reports returns 422 (now validated on Account), and an account param that is not an object or contains no editable fields returns 400.

Summary by CodeRabbit

  • New Features
    • Update account names, institution details, report exclusion settings, and logos through the API.
    • Updates require write access and full account access. Accounts unavailable to the caller return not found, and invalid changes return validation errors.
    • Edited fields are protected from later provider-sync updates, and uploaded logos are validated before being saved.
  • Documentation
    • Added API documentation covering account updates, editable fields, access requirements, and possible responses.