diff --git a/app/views/import/uploads/show.html.erb b/app/views/import/uploads/show.html.erb index 7cf51d651..7d19818c6 100644 --- a/app/views/import/uploads/show.html.erb +++ b/app/views/import/uploads/show.html.erb @@ -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 %> @@ -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, diff --git a/app/views/imports/_pdf_import.html.erb b/app/views/imports/_pdf_import.html.erb index 4d82ce324..421eed656 100644 --- a/app/views/imports/_pdf_import.html.erb +++ b/app/views/imports/_pdf_import.html.erb @@ -40,7 +40,7 @@ <%= t("imports.pdf_import.select_account", default: "Import to Account") %> <%= 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? %> diff --git a/test/controllers/import/uploads_controller_test.rb b/test/controllers/import/uploads_controller_test.rb index 6aa3be8b6..ded4f2e4f 100644 --- a/test/controllers/import/uploads_controller_test.rb +++ b/test/controllers/import/uploads_controller_test.rb @@ -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: {