Name a transfer's other account in the API only when the caller can open it
api/v1/transactions/_transaction.json.jbuilder rendered transfer.other_account (id, name, type) for the other leg of a transfer without checking access. A member with a shared account saw the name of an unshared account on the other side. The web transaction list (@accessible_account_ids in transactions/_transaction.html.erb) and the assistant's get_transactions already hide it.
other_account is now null when the caller cannot open that account. The OpenAPI schema already declares it nullable, so the spec does not change.
transfer.amount and transfer.currency came from the inflow leg. When the inflow is the hidden leg they now come from the caller's own leg, so a cross-currency transfer does not reveal the hidden account's currency or the amount it received. Same-currency transfers render the same value as before.
The check is Account.accessible_by(current_resource_owner), the same scope as the transaction lookup, behind api_accessible_account? in Api::V1::BaseController: one query per request, and every API controller that renders the partial (transactions, splits, trades) gets it.
/api/v1/transfers and /api/v1/rejected_transfers already require both legs to be accessible and need no change.
Tests: show and index for a member with a read-only key, transfer from a shared account to an unshared one; the cross-currency amount; the named account when both legs are accessible.
Summary by cubic
Fixes a leak in the transfer API where the account on the other leg of a transfer was named even when the caller could not open it, so the API now matches the web transaction list and the assistant's get_transactions.
other_accountisnullfor unshared counterparties; it no longer exposes the hidden account's id, name, or type.- Transfer
amountandcurrencycome from the caller's own leg, so a cross-currency transfer does not reveal the hidden account's currency or the amount it received. - The OpenAPI schema declares
other_accountasanyOfAccount or null, because a barenullableis ignored by strict OpenAPI 3.0 validators. - Accessibility uses the same
Account.accessible_byscope as the transaction lookup, adding one query per request toapi/v1/transactions,api/v1/splits, andapi/v1/trades.
Summary by CodeRabbit
- Bug Fixes
- Transfer responses include details about the opposite account only when it is accessible. Otherwise, the account is returned as null and its ID is not exposed.
- When the opposite account is unavailable, the transfer amount and currency are taken from the visible transaction, keeping the response consistent with the account information shown.
- Documentation
- API documentation now reflects that the opposite account may be unavailable in transfer responses.