← Back to Pull requests

Add PATCH /api/v1/accounts/:id #6148

Open
unknown opened this pull request with 534 lines diff across 6 files
View on GitHub
unknown unknown commented on Dec 04, 2026 17:17 UTC
Author

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

    <!-- This is an auto-generated description by cubic. -->
    ---

    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.
  • <sup>Written for commit 4b7cce61620c026ea6222585cf24356640ffc188. Summary will update on new commits.</sup>

    <a href="https://cubic.dev/pr/we-promise/sure/pull/6148?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>

    <!-- End of auto-generated description by cubic. -->

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    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 the caller cannot access return not found; invalid changes return validation errors.
    Changed fields are protected from later provider-sync updates. Logo uploads are validated before being saved.
    Documentation
    Added API documentation for account updates, editable fields, access requirements, and response codes.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 534 lines (+400 / -134) across 6 files Reviewer: jjmata Review duration: 1282m
    All Vouch review confidence checks passed
    Residual risk 0.26 = Change Risk (0.48) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 534 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.376
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #6148"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.9% (MEDIUM) · Higher = larger blast radius
    47.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 25.5% · Safe to merge
    25.5%