Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Insights follow-up to #5115: hide private insights from the chat prefill, Spanish copy (#5163)

David Gil19a45ab9a7ff
diff --git a/app/controllers/chats_controller.rb b/app/controllers/chats_controller.rb
index 9467d35a8b..9bb11a10bd 100644
--- a/app/controllers/chats_controller.rb
+++ b/app/controllers/chats_controller.rb
@@ -20,7 +20,8 @@ class ChatsController < ApplicationController
title: t(".default_title", timestamp: Time.current.strftime("%Y-%m-%d %H:%M"))
)
# "Dig in with AI" prefills the message so the user can edit it before sending.
- @insight = Current.family.insights.find_by(id: params[:insight_id]) if params[:insight_id]
+ # Same account check as InsightsController, so a hidden insight stays hidden.
+ @insight = Current.family.insights.about_shared_accounts.find_by(id: params[:insight_id]) if params[:insight_id]
end
def create
diff --git a/config/locales/views/insights/es.yml b/config/locales/views/insights/es.yml
index 0badda4ba4..b77b0336b5 100644
--- a/config/locales/views/insights/es.yml
+++ b/config/locales/views/insights/es.yml
@@ -2,8 +2,8 @@
es:
insights:
notification:
- title: Nuevo análisis financiero
- body: Abre Sure para revisar tu análisis más reciente.
+ title: Nuevo insight
+ body: Abre Sure para ver tu último insight.
index:
title: Insights
subtitle: Qué está pasando en tus finanzas, actualizado cada noche.
@@ -19,6 +19,18 @@ es:
acknowledge: Entendido
acknowledge_title: Ocultar esto hasta que cambien los números
new: Nuevo
+ dig_in: Profundizar con IA
+ dig_in:
+ prompt: |-
+ Ayúdame a profundizar en este insight.
+
+ Insight: %{title}
+ Qué ha encontrado Sure: %{body}
+ Periodo: %{period}
+ Cifras:
+ %{facts}
+
+ ¿A qué se debe y debería hacer algo al respecto?
feed:
view_all: Ver todos los insights
header: Últimos
@@ -33,6 +45,7 @@ es:
idle_cash: Efectivo inactivo
budget_at_risk: Presupuesto
budget_on_track: Presupuesto
+ maintained_goal_depleted: Reserva
meta:
next_n_days:
one: Próximo día
@@ -61,6 +74,7 @@ es:
savings_rate_change: Ver transacciones de ese mes
idle_cash: Ir a la cuenta
budget: Ver presupuesto
+ maintained_goal_depleted: Ver reserva
titles:
spending_anomaly:
above: El gasto en %{category} va en aumento
@@ -69,6 +83,7 @@ es:
low: Tu saldo de efectivo podría bajar demasiado
negative: Tu saldo de efectivo podría volverse negativo
net_worth_milestone: "Hito de patrimonio neto: %{milestone}"
+ maintained_goal_depleted: "%{goal} está por debajo del saldo que debe mantener"
subscription_audit: "¿%{name} sigue activa?"
savings_rate_change:
up: Tu tasa de ahorro mejoró en %{month}
@@ -86,6 +101,7 @@ es:
low: Según tus próximas transacciones recurrentes y tu gasto habitual, tu saldo de efectivo podría bajar a %{projected_low} alrededor del %{projected_low_date}.
negative: Según tus próximas transacciones recurrentes y tu gasto habitual, tu saldo de efectivo podría caer hasta %{projected_low} alrededor del %{projected_low_date}.
net_worth_milestone: Tu patrimonio neto superó %{milestone} y ahora está en %{net_worth}.
+ maintained_goal_depleted: "%{goal} tiene %{saved} de los %{target} que debe mantener. Le faltan %{missing}."
subscription_audit: "%{name} (%{amount}) no aparece desde que se esperaba el %{expected_on}. Puede haberse cancelado o el cargo puede haber cambiado de fecha."
savings_rate_change:
up: Ahorraste el %{current_rate}% de tus ingresos en %{month}, %{change_pp} puntos porcentuales más que el %{previous_rate}% del mes anterior.
diff --git a/config/locales/views/settings/ai_prompts/es.yml b/config/locales/views/settings/ai_prompts/es.yml
index 222c7c96f7..1044860169 100644
--- a/config/locales/views/settings/ai_prompts/es.yml
+++ b/config/locales/views/settings/ai_prompts/es.yml
@@ -16,3 +16,7 @@ es:
merchant_detector:
title: Detector de Comerciantes
subtitle: La IA identifica y enriquece los datos de transacciones con información de comerciantes
+ insight_dig_in:
+ title: Profundizar en un insight
+ subtitle: Primer mensaje del chat cuando profundizas en un insight con IA
+ label: Mensaje para profundizar
diff --git a/config/locales/views/settings/hostings/es.yml b/config/locales/views/settings/hostings/es.yml
index 8b25a67ee6..7df2522b16 100644
--- a/config/locales/views/settings/hostings/es.yml
+++ b/config/locales/views/settings/hostings/es.yml
@@ -62,10 +62,12 @@ es:
securities_provider_label: Proveedor de valores (Precios de acciones)
assistant_settings:
title: Asistente de IA
- description: Elige cómo responde el asistente del chat. "Integrado" utiliza directamente tu proveedor de LLM configurado. "Externo" delega en un agente remoto que puede interactuar con las herramientas financieras de Sure mediante MCP.
+ description: Elige cómo responde el asistente del chat. "Integrado" utiliza directamente tu proveedor de LLM configurado. "Externo" delega en un agente remoto que puede interactuar con las herramientas financieras de Sure mediante MCP. "Ninguno en la app" quita el chat de la app y mantiene MCP disponible para tus propios agentes.
type_label: Tipo de asistente
type_builtin: Integrado (LLM directo)
type_external: Externo (agente remoto)
+ type_mcp_only: Ninguno en la app (conecta tu propio agente por MCP)
+ mcp_only_help: El asistente de la app queda desactivado para todo el hogar. También dejan de funcionar los atajos de IA de los recibos y "Profundizar con IA" en los insights. MCP y la categorización en segundo plano siguen disponibles; conecta agentes externos en Ajustes > MCP.
external_status: Punto de conexión del asistente externo
external_configured: Configurado
external_not_configured: No configurado. Introduce la URL y el token a continuación, o define las variables de entorno EXTERNAL_ASSISTANT_URL y EXTERNAL_ASSISTANT_TOKEN.
diff --git a/test/controllers/chats_controller_test.rb b/test/controllers/chats_controller_test.rb
index 40333800d3..d1aa9d6c4c 100644
--- a/test/controllers/chats_controller_test.rb
+++ b/test/controllers/chats_controller_test.rb
@@ -57,6 +57,29 @@ class ChatsControllerTest < ActionDispatch::IntegrationTest
assert_select "textarea[name='chat[content]']", text: ""
end
+ # The feed hides an insight about an account not every member can see, so
+ # the chat composer must not hand its text to anyone who has the id.
+ test "new chat ignores an insight about an account the member cannot see" do
+ insight = create_private_account_insight
+ sign_in users(:family_member)
+
+ get new_chat_url(insight_id: insight.id)
+
+ assert_response :success
+ assert_select "textarea[name='chat[content]']", text: ""
+ assert_no_match "Private holds a balance", response.body
+ end
+
+ # Hidden from everyone, owner included, same as the feed.
+ test "new chat ignores an insight about a private account for its owner too" do
+ insight = create_private_account_insight
+
+ get new_chat_url(insight_id: insight.id)
+
+ assert_response :success
+ assert_select "textarea[name='chat[content]']", text: ""
+ end
+
test "creates chat" do
Usage.stubs(:capture)
Usage.expects(:capture).with("ai_assistant_served_daily").never
@@ -196,4 +219,15 @@ class ChatsControllerTest < ActionDispatch::IntegrationTest
post retry_chat_url(other_chat)
assert_response :not_found
end
+
+ private
+ # accounts(:connected) belongs to family_admin and is not shared.
+ def create_private_account_insight
+ @family.insights.create!(
+ insight_type: "idle_cash", priority: "low", status: "active", title: "Idle cash in Private",
+ body: "Private holds a balance with no activity in the last 60 days.",
+ metadata: { "account_id" => accounts(:connected).id },
+ dedup_key: "idle_cash:private:2026-07", generated_at: Time.current
+ )
+ end
end
diff --git a/test/i18n_test.rb b/test/i18n_test.rb
index 24d39b8f65..64c361078d 100644
--- a/test/i18n_test.rb
+++ b/test/i18n_test.rb
@@ -42,6 +42,19 @@ class I18nTest < ActiveSupport::TestCase
end
end
+ # The insights page, the card's "Dig in with AI" button and the push
+ # notification all read this tree, so a gap shows Spanish users English
+ # copy, and for the dig-in prompt, an English message in their chat box.
+ def test_spanish_insights_keys_and_placeholders_match_english
+ en = view_leaves("insights", "en")
+ es = view_leaves("insights", "es")
+
+ assert_equal en.keys.sort, es.keys.sort, "insights in views/insights/es.yml must carry every key en.yml does"
+ en.each do |key, value|
+ assert_equal value.scan(/%\{\w+\}/).sort, es.fetch(key).to_s.scan(/%\{\w+\}/).sort, "placeholders differ for #{key}"
+ end
+ end
+
def test_no_missing_keys
skip "Skipping missing keys test"
missing_keys = @i18n.missing_keys(locales: [ :en ])
@@ -203,8 +216,13 @@ class I18nTest < ActiveSupport::TestCase
private
# { "months_saved.one" => "...", ... } for UI.account.chart.loan in one locale.
def loan_chart_leaves(locale)
- tree = YAML.load_file(Pathname.pwd.join("config/locales/views/components/#{locale}.yml"), aliases: true)
- .dig(locale, "UI", "account", "chart", "loan") || {}
+ view_leaves("components", locale, "UI", "account", "chart", "loan")
+ end
+
+ # Leaves of config/locales/views/<dir>/<locale>.yml under the given keys.
+ def view_leaves(dir, locale, *keys)
+ tree = YAML.load_file(Pathname.pwd.join("config/locales/views/#{dir}/#{locale}.yml"), aliases: true)
+ .dig(locale, *keys) || {}
flatten_leaves(tree)
end