fix(sharing): scope import account selects to accessible_by (#1803)

Three CSV / QIF account selects in import/uploads/show.html.erb and one
PDF-import account select in imports/_pdf_import.html.erb pulled their
options from `@import.family.accounts`. That listed every account in
the family — including the family admin's unshared personal accounts —
in the dropdown shown to any member running an import. Swap each call
site to `Current.user.accessible_accounts` (owned + explicitly shared
accounts only), matching the existing scoping used by the dashboard
sidebar, transactions controller, transfers controller, etc.

Adds a regression test that signs in as family_member and asserts the
unshared-account names from the dylan_family fixtures never appear in
the rendered upload page.
This commit is contained in:
dripsmvcp
2026-06-05 10:28:43 +09:00
parent 96079188a2
commit e4e64ec82f
3 changed files with 20 additions and 4 deletions

View File

@@ -56,7 +56,7 @@
<%= styled_form_with model: @import, scope: :import, url: import_upload_path(@import), multipart: true, class: "space-y-4" do |form| %>
<%= form.select :account_id,
@import.family.accounts.visible.alphabetically.pluck(:name, :id),
Current.user.accessible_accounts.visible.alphabetically.pluck(:name, :id),
{ label: t(".qif_account_label"), include_blank: t(".qif_account_placeholder"), selected: @import.account_id },
required: true %>
@@ -112,7 +112,7 @@
<%= form.select :col_sep, Import.separator_options, label: true %>
<% if @import.type == "TransactionImport" || @import.type == "TradeImport" %>
<%= form.select :account_id, @import.family.accounts.visible.alphabetically.pluck(:name, :id), { label: t(".account_optional_label"), include_blank: t(".multi_account_import"), selected: @import.account_id } %>
<%= form.select :account_id, Current.user.accessible_accounts.visible.alphabetically.pluck(:name, :id), { label: t(".account_optional_label"), include_blank: t(".multi_account_import"), selected: @import.account_id } %>
<% end %>
<label for="import_import_file_csv" class="flex flex-col items-center justify-center w-full h-64 border border-secondary border-dashed rounded-xl cursor-pointer" data-controller="file-upload" data-file-upload-target="uploadArea">
@@ -144,7 +144,7 @@
<%= form.select :col_sep, Import.separator_options, label: true %>
<% if @import.type == "TransactionImport" || @import.type == "TradeImport" %>
<%= form.select :account_id, @import.family.accounts.visible.alphabetically.pluck(:name, :id), { label: t(".account_optional_label"), include_blank: t(".multi_account_import"), selected: @import.account_id } %>
<%= form.select :account_id, Current.user.accessible_accounts.visible.alphabetically.pluck(:name, :id), { label: t(".account_optional_label"), include_blank: t(".multi_account_import"), selected: @import.account_id } %>
<% end %>
<%= form.text_area :raw_file_str,

View File

@@ -40,7 +40,7 @@
<div class="space-y-2">
<h2 class="font-medium text-primary"><%= t("imports.pdf_import.select_account", default: "Import to Account") %></h2>
<%= form_with model: import, url: import_path(import), method: :patch, class: "space-y-2" do |f| %>
<% accounts = import.family.accounts.manual.alphabetically %>
<% accounts = Current.user.accessible_accounts.manual.alphabetically %>
<% if accounts.any? %>
<%= f.select :account_id, options_for_select(accounts.map { |a| [a.name, a.id] }, import.account_id), { include_blank: t("imports.pdf_import.select_account_placeholder", default: "Select an account...") }, class: "form-field__input" %>
<% if import.account.nil? %>

View File

@@ -35,6 +35,22 @@ class Import::UploadsControllerTest < ActionDispatch::IntegrationTest
assert_equal "CSV uploaded successfully.", flash[:notice]
end
test "account select does not leak unshared family accounts (#1803)" do
sign_in users(:family_member)
get import_upload_url(@import)
assert_response :success
assert_match "Checking Account", response.body,
"Expected the shared account to appear in the account select"
refute_match "Collectable Account", response.body,
"Account select must not leak unshared assets to a non-owner family member"
refute_match "IOU (personal debt to friend)", response.body,
"Account select must not leak unshared liabilities to a non-owner family member"
refute_match "Plaid Depository Account", response.body,
"Account select must not leak unshared connected accounts to a non-owner family member"
end
test "invalid csv cannot be uploaded" do
patch import_upload_url(@import), params: {
import: {