The personal finance app for everyone
Make transaction enrichment opt-in for all users (#1552)
Zach Gollwitzer68617514b004
diff --git a/app/controllers/settings/hostings_controller.rb b/app/controllers/settings/hostings_controller.rbindex 97b8de92..222ae018 100644--- a/app/controllers/settings/hostings_controller.rb+++ b/app/controllers/settings/hostings_controller.rb@@ -26,10 +26,6 @@ class Settings::HostingsController < SettingsControllerSetting.synth_api_key = hosting_params[:synth_api_key]end- if hosting_params.key?(:data_enrichment_enabled)- Setting.data_enrichment_enabled = hosting_params[:data_enrichment_enabled]- end-redirect_to settings_hosting_path, notice: t(".success")rescue ActiveRecord::RecordInvalid => errorflash.now[:alert] = t(".failure")@@ -38,7 +34,7 @@ class Settings::HostingsController < SettingsControllerprivatedef hosting_params- params.require(:setting).permit(:render_deploy_hook, :upgrades_setting, :require_invite_for_signup, :synth_api_key, :data_enrichment_enabled)+ params.require(:setting).permit(:render_deploy_hook, :upgrades_setting, :require_invite_for_signup, :synth_api_key)enddef raise_if_not_self_hosteddiff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rbindex beb85197..55b75581 100644--- a/app/controllers/users_controller.rb+++ b/app/controllers/users_controller.rb@@ -41,7 +41,7 @@ class UsersController < ApplicationControllerdef user_paramsparams.require(:user).permit(:first_name, :last_name, :profile_image, :redirect_to, :delete_profile_image, :onboarded_at,- family_attributes: [ :name, :currency, :country, :locale, :date_format, :timezone, :id ]+ family_attributes: [ :name, :currency, :country, :locale, :date_format, :timezone, :id, :data_enrichment_enabled ])enddiff --git a/app/models/account/syncer.rb b/app/models/account/syncer.rbindex 9160e64f..df5a7b03 100644--- a/app/models/account/syncer.rb+++ b/app/models/account/syncer.rb@@ -11,7 +11,7 @@ class Account::Syncerupdate_account_info(balances, holdings) unless account.plaid_account_id.present?convert_records_to_family_currency(balances, holdings) unless account.currency == account.family.currency- if Setting.data_enrichment_enabled || Rails.configuration.app_mode.managed?+ if account.family.data_enrichment_enabled?account.enrich_data_laterelseRails.logger.info("Data enrichment is disabled, skipping enrichment for account #{account.id}")diff --git a/app/models/setting.rb b/app/models/setting.rbindex fe047cbb..d576fbea 100644--- a/app/models/setting.rb+++ b/app/models/setting.rb@@ -17,10 +17,6 @@ class Setting < RailsSettings::Basedefault: ENV.fetch("UPGRADES_TARGET", "release"),validates: { inclusion: { in: %w[release commit] } }- field :data_enrichment_enabled,- type: :boolean,- default: false-field :synth_api_key, type: :string, default: ENV["SYNTH_API_KEY"]field :require_invite_for_signup, type: :boolean, default: falsediff --git a/app/views/settings/hostings/_data_enrichment_settings.html.erb b/app/views/settings/hostings/_data_enrichment_settings.html.erbdeleted file mode 100644index 6d409923..00000000--- a/app/views/settings/hostings/_data_enrichment_settings.html.erb+++ /dev/null@@ -1,18 +0,0 @@-<div class="space-y-4">- <div class="flex items-center justify-between">- <div class="space-y-1">- <p class="text-sm"><%= t(".title") %></p>- <p class="text-gray-500 text-sm"><%= t(".description") %></p>- </div>-- <%= styled_form_with model: Setting.new,- url: settings_hosting_path,- method: :patch,- data: { controller: "auto-submit-form", "auto-submit-form-trigger-event-value": "blur" } do |form| %>- <div class="relative inline-block select-none">- <%= form.check_box :data_enrichment_enabled, class: "sr-only peer", "data-auto-submit-form-target": "auto", "data-autosubmit-trigger-event": "input" %>- <%= form.label :data_enrichment_enabled, " ".html_safe, class: "maybe-switch" %>- </div>- <% end %>- </div>-</div>diff --git a/app/views/settings/hostings/show.html.erb b/app/views/settings/hostings/show.html.erbindex a2af0bed..ba4b7d5d 100644--- a/app/views/settings/hostings/show.html.erb+++ b/app/views/settings/hostings/show.html.erb@@ -10,7 +10,6 @@<%= render "settings/hostings/upgrade_settings" %><%= render "settings/hostings/provider_settings" %><%= render "settings/hostings/synth_settings" %>- <%= render "settings/hostings/data_enrichment_settings" %></div><% end %>diff --git a/app/views/settings/preferences/_data_enrichment_settings.html.erb b/app/views/settings/preferences/_data_enrichment_settings.html.erbnew file mode 100644index 00000000..73f729fd--- /dev/null+++ b/app/views/settings/preferences/_data_enrichment_settings.html.erb@@ -0,0 +1,24 @@+<%# locals: (user:) %>++<div class="space-y-4">+ <div class="flex items-center justify-between">+ <div class="space-y-1">+ <p class="text-sm"><%= t(".title") %></p>+ <p class="text-gray-500 text-sm"><%= t(".description") %></p>+ <% if self_hosted? %>+ <p class="text-xs italic text-gray-500"><%= t(".self_host_disclaimer") %></p>+ <% end %>+ </div>++ <%= styled_form_with model: user,+ data: { controller: "auto-submit-form", "auto-submit-form-trigger-event-value": "blur" } do |form| %>+ <div class="relative inline-block select-none">+ <%= form.hidden_field :redirect_to, value: "preferences" %>+ <%= form.fields_for :family do |family_form| %>+ <%= family_form.check_box :data_enrichment_enabled, class: "sr-only peer", "data-auto-submit-form-target": "auto", "data-autosubmit-trigger-event": "input" %>+ <%= family_form.label :data_enrichment_enabled, " ".html_safe, class: "maybe-switch" %>+ <% end %>+ </div>+ <% end %>+ </div>+</div>diff --git a/app/views/settings/preferences/show.html.erb b/app/views/settings/preferences/show.html.erbindex 225e5d96..8b066503 100644--- a/app/views/settings/preferences/show.html.erb+++ b/app/views/settings/preferences/show.html.erb@@ -40,6 +40,11 @@<% end %></div><% end %>++ <%= settings_section title: t(".data"), subtitle: t(".data_subtitle") do %>+ <%= render "settings/preferences/data_enrichment_settings", user: @user %>+ <% end %>+<%= settings_section title: t(".theme_title"), subtitle: t(".theme_subtitle") do %><div><%= styled_form_with model: @user, class: "flex justify-between items-center" do |form| %>diff --git a/config/locales/views/settings/en.yml b/config/locales/views/settings/en.ymlindex aa8141b8..f784db97 100644--- a/config/locales/views/settings/en.yml+++ b/config/locales/views/settings/en.yml@@ -26,9 +26,16 @@ en:next: Nextprevious: Backpreferences:+ data_enrichment_settings:+ description: Let Maybe auto-categorize, name, and add merchant data to your+ transactions on each sync. All enrichment is done in English.+ self_host_disclaimer: This will incur Synth API credits.+ title: Transaction enrichment (English only)show:country: Countrycurrency: Currency+ data: Data enrichment+ data_subtitle: Enable data enrichment for your accountsdate_format: Date formatgeneral_subtitle: Configure your preferencesgeneral_title: Generaldiff --git a/config/locales/views/settings/hostings/en.yml b/config/locales/views/settings/hostings/en.ymlindex b3f04fc9..90a89fd7 100644--- a/config/locales/views/settings/hostings/en.yml+++ b/config/locales/views/settings/hostings/en.yml@@ -2,10 +2,6 @@en:settings:hostings:- data_enrichment_settings:- description: Enable data enrichment for your account transactions. This will- incur additional Synth credits.- title: Data Enrichmentinvite_code_settings:description: Every new user that joins your instance of Maybe can only doso via an invite codediff --git a/db/migrate/20241217141716_add_enrichment_setting.rb b/db/migrate/20241217141716_add_enrichment_setting.rbnew file mode 100644index 00000000..8d154887--- /dev/null+++ b/db/migrate/20241217141716_add_enrichment_setting.rb@@ -0,0 +1,5 @@+class AddEnrichmentSetting < ActiveRecord::Migration[7.2]+ def change+ add_column :families, :data_enrichment_enabled, :boolean, default: false+ end+enddiff --git a/db/schema.rb b/db/schema.rbindex 5fd3f26d..5ae96e52 100644--- a/db/schema.rb+++ b/db/schema.rb@@ -10,7 +10,7 @@## It's strongly recommended that you check this file into your version control system.-ActiveRecord::Schema[7.2].define(version: 2024_12_12_141453) do+ActiveRecord::Schema[7.2].define(version: 2024_12_17_141716) do# These are extensions that must be enabled in order to support this databaseenable_extension "pgcrypto"enable_extension "plpgsql"@@ -222,6 +222,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_12_12_141453) dot.string "country", default: "US"t.datetime "last_synced_at"t.string "timezone"+ t.boolean "data_enrichment_enabled", default: falseendcreate_table "good_job_batches", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|