Skip to content

Commit

Permalink
Make transaction enrichment opt-in for all users
Browse files Browse the repository at this point in the history
  • Loading branch information
zachgoll committed Dec 17, 2024
1 parent ba878c3 commit b38b473
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 35 deletions.
6 changes: 1 addition & 5 deletions app/controllers/settings/hostings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ def update
Setting.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 => error
flash.now[:alert] = t(".failure")
Expand All @@ -38,7 +34,7 @@ def update

private
def 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)
end

def raise_if_not_self_hosted
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def should_purge_profile_image?
def user_params
params.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 ]
)
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/account/syncer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def run
update_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_later
else
Rails.logger.info("Data enrichment is disabled, skipping enrichment for account #{account.id}")
Expand Down
4 changes: 0 additions & 4 deletions app/models/setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ class Setting < RailsSettings::Base
default: 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: false
Expand Down
18 changes: 0 additions & 18 deletions app/views/settings/hostings/_data_enrichment_settings.html.erb

This file was deleted.

1 change: 0 additions & 1 deletion app/views/settings/hostings/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>

Expand Down
24 changes: 24 additions & 0 deletions app/views/settings/preferences/_data_enrichment_settings.html.erb
Original file line number Diff line number Diff line change
@@ -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, "&nbsp;".html_safe, class: "maybe-switch" %>
<% end %>
</div>
<% end %>
</div>
</div>
5 changes: 5 additions & 0 deletions app/views/settings/preferences/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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| %>
Expand Down
7 changes: 7 additions & 0 deletions config/locales/views/settings/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,16 @@ en:
next: Next
previous: Back
preferences:
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: Country
currency: Currency
data: Data enrichment
data_subtitle: Enable data enrichment for your accounts
date_format: Date format
general_subtitle: Configure your preferences
general_title: General
Expand Down
4 changes: 0 additions & 4 deletions config/locales/views/settings/hostings/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 Enrichment
invite_code_settings:
description: Every new user that joins your instance of Maybe can only do
so via an invite code
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20241217141716_add_enrichment_setting.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddEnrichmentSetting < ActiveRecord::Migration[7.2]
def change
add_column :families, :data_enrichment_enabled, :boolean, default: false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b38b473

Please sign in to comment.