The personal finance app for everyone (by everyone)
Ruby
fix(goals): allow deleting a goal without archiving it first (#2963)
Guillem Arias Fausteacf4cb20100d
diff --git a/app/controllers/goals_controller.rb b/app/controllers/goals_controller.rbindex 5de8aa24ac..684b5ce0a9 100644--- a/app/controllers/goals_controller.rb+++ b/app/controllers/goals_controller.rb@@ -122,12 +122,13 @@ class GoalsController < ApplicationControllerrender :edit, status: :unprocessable_entityend+ # Deletable from any state. Destroying a goal cascades only to its own+ # goal_accounts / goal_pledges — and GoalPledge#clear_matched_transaction_extra+ # unstamps the pledge id it wrote onto a matched transaction. No account,+ # balance, entry or transaction is removed, so the archive-first gate this+ # used to enforce bought no safety; it only hid the action behind a two-step+ # flow no other Sure resource requires.def destroy- unless @goal.archived?- redirect_to goal_path(@goal), alert: t(".archive_first")- return- end-@goal.destroy!redirect_to goals_path, notice: t(".success")enddiff --git a/app/helpers/custom_confirm.rb b/app/helpers/custom_confirm.rbindex f2d59a0095..b4bc52be62 100644--- a/app/helpers/custom_confirm.rb+++ b/app/helpers/custom_confirm.rb@@ -2,13 +2,24 @@# default browser confirm API via Turbo.class CustomConfirmclass << self+ # `body` is the one field the dialog renders as HTML — confirm_dialog_controller+ # assigns it to innerHTML so bodies such as accounts' `confirm_body_html` can+ # carry markup, while title and button label go through textContent. Every+ # caller passes a user-named record here, so the name is escaped on its way+ # into the body: without it a record named "<img src=x onerror=…>" executes+ # as soon as someone opens the confirmation.+ # `titleize` / `downcase` are English-shaped and stay applied to the record+ # name so the English copy is unchanged; a locale that needs different+ # casing can absorb it in its own string.def for_resource_deletion(resource_name, high_severity: false)new(destructive: true,high_severity: high_severity,- title: "Delete #{resource_name.titleize}?",- body: "Are you sure you want to delete #{resource_name.downcase}? This is not reversible.",- btn_text: "Delete #{resource_name.titleize}"+ title: I18n.t("shared.custom_confirm.resource_deletion_title", resource: resource_name.titleize),+ # Escaped, unlike the other two: this is the only field the dialog+ # renders as HTML.+ body: I18n.t("shared.custom_confirm.resource_deletion_body", resource: ERB::Util.html_escape(resource_name.downcase)),+ btn_text: I18n.t("shared.custom_confirm.resource_deletion_btn_text", resource: resource_name.titleize))endenddiff --git a/app/models/goal.rb b/app/models/goal.rbindex e0a2598ed2..bc01420358 100644--- a/app/models/goal.rb+++ b/app/models/goal.rb@@ -476,6 +476,27 @@ class Goal < ApplicationRecordendend+ # Confirm dialog for deleting this goal, shared by the show-page kebab and+ # the index card kebab so the two can't drift. Spelled out rather than using+ # CustomConfirm.for_resource_deletion, whose generic "This is not reversible"+ # reads scarier than a goal delete is: only the goal, its account links and+ # its pledge history go — the accounts, balances and transactions behind it+ # are untouched.+ def deletion_confirm+ CustomConfirm.new(+ destructive: true,+ high_severity: true,+ title: I18n.t("goals.show.confirm_delete_title"),+ # Escaped: the dialog assigns `body` to innerHTML (so bodies like the+ # accounts' confirm_body_html can carry <p>), so a goal named+ # "<img src=x onerror=…>" would otherwise run when a family member opens+ # the confirmation. Only `body` needs this — the dialog sets its title and+ # button label with textContent.+ body: I18n.t("goals.show.confirm_delete_body", name: ERB::Util.html_escape(name)),+ btn_text: I18n.t("goals.show.confirm_delete_cta")+ )+ end+# Single-line state summary rendered between the header and the ring on# the show page. Replaces the stacked catch-up alert + inline status pill;# carries the same actionable copy without owning a CTA. Returns nil whendiff --git a/app/views/goals/show.html.erb b/app/views/goals/show.html.erbindex 5a79115a2f..36c46d99f9 100644--- a/app/views/goals/show.html.erb+++ b/app/views/goals/show.html.erb@@ -79,17 +79,17 @@<% if @goal.may_reopen? %><% menu.with_item(variant: "button", text: t(".reopen"), icon: "rotate-ccw", href: reopen_goal_path(@goal), method: :patch) %><% end %>- <% if @goal.archived? %>- <% menu.with_item(- variant: "button",- text: t(".delete"),- icon: "trash-2",- href: goal_path(@goal),- method: :delete,- destructive: true,- confirm: CustomConfirm.for_resource_deletion(@goal.name, high_severity: true)- ) %>- <% end %>+ <%# Available in any state — see GoalsController#destroy for why there's+ no archive-first gate. %>+ <% menu.with_item(+ variant: "button",+ text: t(".delete"),+ icon: "trash-2",+ href: goal_path(@goal),+ method: :delete,+ destructive: true,+ confirm: @goal.deletion_confirm+ ) %><% end %></div></header>diff --git a/config/locales/views/goals/de.yml b/config/locales/views/goals/de.ymlindex a00cdca1d8..261af0cfb4 100644--- a/config/locales/views/goals/de.yml+++ b/config/locales/views/goals/de.yml@@ -16,7 +16,6 @@ de:create:success: Ziel erstellt.destroy:- archive_first: Archivier das Ziel, bevor du es löschst.success: Ziel gelöscht.edit:heading: Ziel bearbeiten@@ -185,7 +184,10 @@ de:confirm_complete_body_short: Du stehst bei %{progress} %, also %{saved} von %{target}. Wenn du abschließt, wird dieser Stand als dein Ergebnis festgehalten statt des ursprünglichen Ziels. Weiter, oder lieber schließen und das Ziel anpassen?confirm_complete_cta: Als erreicht markierenconfirm_complete_title: Dieses Ziel als erreicht markieren?- delete: Endgültig löschen+ confirm_delete_body: "%{name} und der zugehörige Verlauf der Zusagen werden endgültig entfernt. Deine verknüpften Konten, Salden und Transaktionen sind davon nicht betroffen. Wenn du es stattdessen als Beleg behalten willst, archivier es."+ confirm_delete_cta: Ziel löschen+ confirm_delete_title: Dieses Ziel löschen?+ delete: Löschenedit: Bearbeitenempty:body: Überweis Geld auf dein verknüpftes Konto. Sure erkennt es beim nächsten Sync. Oder aktualisier den Saldo deines manuellen Kontos.diff --git a/config/locales/views/goals/en.yml b/config/locales/views/goals/en.ymlindex cfe336a6c7..e3524b78fe 100644--- a/config/locales/views/goals/en.yml+++ b/config/locales/views/goals/en.yml@@ -77,7 +77,6 @@ en:success: Goal updated.destroy:success: Goal deleted.- archive_first: Archive the goal before deleting it.pause:success: Goal paused.invalid_transition: Goal can't be paused from its current state.@@ -104,7 +103,7 @@ en:archive: Archiveunarchive: Restorereopen: Reopen goal- delete: Delete permanently+ delete: Deleterecord_pledge_cta: Record pledgepledge_just_transferred: Log a transfer you madepledge_just_saved: Log money you set aside@@ -172,6 +171,9 @@ en:confirm_archive_title: Archive this goal?confirm_archive_body: Archived goals disappear from the main list. You can restore them later.confirm_archive_cta: Archive+ confirm_delete_title: Delete this goal?+ confirm_delete_body: "%{name} and its pledge history are removed for good. Your linked accounts, balances and transactions are not affected. To keep it as a record instead, archive it."+ confirm_delete_cta: Delete goalpaused_banner:title: This goal is pausedbody: Resume it to keep tracking your progress.diff --git a/config/locales/views/goals/fr.yml b/config/locales/views/goals/fr.ymlindex 840659ef91..e7d44ea6b8 100644--- a/config/locales/views/goals/fr.yml+++ b/config/locales/views/goals/fr.yml@@ -16,7 +16,6 @@ fr:create:success: Objectif créé.destroy:- archive_first: Archivez l'objectif avant de le supprimer.success: Objectif supprimé.edit:heading: Modifier l'objectif@@ -176,11 +175,14 @@ fr:confirm_archive_body: Les objectifs archivés disparaissent de la liste principale. Vous pourrez les restaurer plus tard.confirm_archive_cta: Archiverconfirm_archive_title: Archiver cet objectif ?+ confirm_delete_title: "Supprimer cet objectif ?"+ confirm_delete_body: "%{name} et son historique de versements sont supprimés définitivement. Vos comptes liés, soldes et transactions ne sont pas affectés. Pour en garder une trace, archivez-le plutôt."+ confirm_delete_cta: "Supprimer l'objectif"confirm_complete_body: Il quittera la liste En cours. Vous pourrez toujours l'archiver ou le restaurer plus tard.confirm_complete_body_short: Vous êtes à %{progress}%, %{saved} sur %{target}. Marquer comme terminé enregistrera cela comme votre réussite à la place de l'objectif initial. Continuer, ou fermer ceci et ajuster l'objectif à la place ?confirm_complete_cta: Marquer comme terminéconfirm_complete_title: Marquer cet objectif comme terminé ?- delete: Supprimer définitivement+ delete: Supprimeredit: Modifierempty:body: Effectuez un virement sur votre compte lié. Sure le détectera lors de la prochaine synchronisation. Ou mettez à jour manuellement le solde du compte.diff --git a/config/locales/views/goals/it.yml b/config/locales/views/goals/it.ymlindex 71b8531fd1..09beb57b86 100644--- a/config/locales/views/goals/it.yml+++ b/config/locales/views/goals/it.yml@@ -76,7 +76,6 @@ it:success: Obiettivo aggiornato.destroy:success: Obiettivo eliminato.- archive_first: Archivia l'obiettivo prima di eliminarlo.pause:success: Obiettivo messo in pausa.invalid_transition: L'obiettivo non può essere messo in pausa dal suo stato attuale.@@ -103,7 +102,7 @@ it:archive: Archiviaunarchive: Ripristinareopen: Riapri obiettivo- delete: Elimina definitivamente+ delete: Eliminarecord_pledge_cta: Registra impegnopledge_just_transferred: Registra un trasferimento effettuatopledge_just_saved: Registra denaro messo da parte@@ -171,6 +170,9 @@ it:confirm_archive_title: Archiviare questo obiettivo?confirm_archive_body: Gli obiettivi archiviati scompaiono dalla lista principale. Puoi ripristinarli in seguito.confirm_archive_cta: Archivia+ confirm_delete_title: "Eliminare questo obiettivo?"+ confirm_delete_body: "%{name} e la sua cronologia dei versamenti vengono eliminati definitivamente. I conti collegati, i saldi e le transazioni non vengono toccati. Per conservarlo come traccia, archivialo invece."+ confirm_delete_cta: "Elimina obiettivo"paused_banner:title: Questo obiettivo è in pausabody: Riprendi per continuare a monitorare i tuoi progressi.diff --git a/config/locales/views/goals/pl.yml b/config/locales/views/goals/pl.ymlindex 4e7e87acd2..4106dbd42a 100644--- a/config/locales/views/goals/pl.yml+++ b/config/locales/views/goals/pl.yml@@ -86,7 +86,6 @@ pl:success: Cel zaktualizowany.destroy:success: Cel usunięty.- archive_first: Zarchiwizuj cel przed jego usunięciem.pause:success: Cel wstrzymany.invalid_transition: Cel nie może być wstrzymany z bieżącego stanu.@@ -113,7 +112,7 @@ pl:archive: Archiwizujunarchive: Przywróćreopen: Otwórz ponownie- delete: Usuń na stałe+ delete: Usuńrecord_pledge_cta: Zapisz zobowiązaniepledge_just_transferred: Zarejestruj wykonany przelewpledge_just_saved: Zarejestruj odłożone pieniądze@@ -183,6 +182,9 @@ pl:confirm_archive_title: Zarchiwizować ten cel?confirm_archive_body: Zarchiwizowane cele znikną z głównej listy. Możesz je później przywrócić.confirm_archive_cta: Archiwizuj+ confirm_delete_title: "Usunąć ten cel?"+ confirm_delete_body: "%{name} i jego historia wpłat zostaną trwale usunięte. Powiązane konta, salda i transakcje pozostaną bez zmian. Aby zachować go jako zapis, zarchiwizuj go zamiast usuwać."+ confirm_delete_cta: "Usuń cel"paused_banner:title: Ten cel jest wstrzymanybody: Wznów go, aby kontynuować śledzenie postępów.diff --git a/config/locales/views/goals/ru.yml b/config/locales/views/goals/ru.ymlindex 5ab84f3518..42a1323d1f 100644--- a/config/locales/views/goals/ru.yml+++ b/config/locales/views/goals/ru.yml@@ -16,7 +16,6 @@ ru:create:success: Цель создана.destroy:- archive_first: Сначала архивируйте цель перед удалением.success: Цель удалена.edit:heading: Редактировать цель@@ -194,6 +193,9 @@ ru:confirm_archive_body: Архивные цели скрываются из списка. Их можно восстановить позже.confirm_archive_cta: Архивироватьconfirm_archive_title: Архивировать цель?+ confirm_delete_title: "Удалить эту цель?"+ confirm_delete_body: "%{name} и история взносов будут удалены безвозвратно. Связанные счета, балансы и транзакции не затрагиваются. Чтобы сохранить её как запись, заархивируйте её вместо удаления."+ confirm_delete_cta: "Удалить цель"confirm_complete_body: Цель исчезнет из активных.confirm_complete_body_short: Вы достигли %{progress}%, %{saved} из %{target}.confirm_complete_cta: Отметить выполненнойdiff --git a/config/locales/views/goals/tr.yml b/config/locales/views/goals/tr.ymlindex 961d60fd01..b44516e199 100644--- a/config/locales/views/goals/tr.yml+++ b/config/locales/views/goals/tr.yml@@ -16,7 +16,6 @@ tr:create:success: Hedef oluşturuldu.destroy:- archive_first: Hedefi silmeden önce arşivleyin.success: Hedef silindi.edit:heading: Hedefi düzenle@@ -183,6 +182,9 @@ tr:geri yükleyebilirsiniz.confirm_archive_cta: Arşivleconfirm_archive_title: Bu hedef arşivlensin mi?+ confirm_delete_title: "Bu hedef silinsin mi?"+ confirm_delete_body: "%{name} ve taahhüt geçmişi kalıcı olarak silinir. Bağlı hesaplarınız, bakiyeleriniz ve işlemleriniz etkilenmez. Kayıt olarak saklamak için bunun yerine arşivleyin."+ confirm_delete_cta: "Hedefi sil"confirm_complete_body: Devam Eden listesinden çıkar. Daha sonra yine de arşivleyebilirveya geri yükleyebilirsiniz.confirm_complete_body_short: "%{progress}%'desiniz, %{target} hedefinin %{saved}@@ -190,7 +192,7 @@ tr:yerine başarınız olarak kaydeder. Devam edin ya da bunu kapatıp hedefi ayarlayın."confirm_complete_cta: Tamamlandı olarak işaretleconfirm_complete_title: Bu hedef tamamlandı olarak işaretlensin mi?- delete: Kalıcı olarak sil+ delete: Siledit: Düzenleempty:body: Bağlı hesabınıza bir transfer yapın. Sure bir sonraki eşitlemede bunudiff --git a/config/locales/views/goals/zh-CN.yml b/config/locales/views/goals/zh-CN.ymlindex 6727a0f71e..fedb679258 100644--- a/config/locales/views/goals/zh-CN.yml+++ b/config/locales/views/goals/zh-CN.yml@@ -76,7 +76,6 @@ zh-CN:success: 目标已更新。destroy:success: 目标已删除。- archive_first: 删除前请先归档该目标。pause:success: 目标已暂停。invalid_transition: 目标当前状态不能暂停。@@ -103,7 +102,7 @@ zh-CN:archive: 归档unarchive: 恢复reopen: 重新开启目标- delete: 永久删除+ delete: 删除record_pledge_cta: 记录承诺pledge_just_transferred: 记录你完成的转账pledge_just_saved: 记录你留出的资金@@ -171,6 +170,9 @@ zh-CN:confirm_archive_title: 归档此目标?confirm_archive_body: 归档后的目标会从主列表隐藏。之后可以恢复。confirm_archive_cta: 归档+ confirm_delete_title: "删除此目标?"+ confirm_delete_body: "%{name} 及其存款记录将被永久删除。你的关联账户、余额和交易不受影响。如果想保留记录,请改为归档。"+ confirm_delete_cta: "删除目标"paused_banner:title: 此目标已暂停body: 恢复它以继续跟踪进度。diff --git a/config/locales/views/goals/zh-TW.yml b/config/locales/views/goals/zh-TW.ymlindex c79a6ee224..ba2d0c8a6f 100644--- a/config/locales/views/goals/zh-TW.yml+++ b/config/locales/views/goals/zh-TW.yml@@ -76,7 +76,6 @@ zh-TW:success: 目標已更新。destroy:success: 目標已刪除。- archive_first: 請先封存目標再刪除。pause:success: 目標已暫停。invalid_transition: 目標在目前的狀態下無法暫停。@@ -103,7 +102,7 @@ zh-TW:archive: 封存unarchive: 還原reopen: 重新開啟目標- delete: 永久刪除+ delete: 刪除record_pledge_cta: 記錄投入pledge_just_transferred: 記錄一筆您已完成的轉帳pledge_just_saved: 記錄一筆您已存起來的錢@@ -171,6 +170,9 @@ zh-TW:confirm_archive_title: 要封存這個目標嗎?confirm_archive_body: 封存的目標不會出現在主清單中,您之後可以再還原。confirm_archive_cta: 封存+ confirm_delete_title: 要刪除這個目標嗎?+ confirm_delete_body: "%{name} 和它的投入紀錄會被永久移除。您已連結的帳戶、餘額與交易都不會受到影響。若想保留成紀錄,請改為封存。"+ confirm_delete_cta: 刪除目標paused_banner:title: 這個目標已暫停body: 恢復它就能繼續追蹤您的進度。diff --git a/config/locales/views/shared/ca.yml b/config/locales/views/shared/ca.ymlindex 66e3f7bd6e..3cd96803be 100644--- a/config/locales/views/shared/ca.yml+++ b/config/locales/views/shared/ca.yml@@ -16,6 +16,9 @@ ca:default_body: Aquesta acció no es pot desfer.default_btn_text: Confirmadefault_title: Segur que vols continuar?+ resource_deletion_title: "Voleu eliminar %{resource}?"+ resource_deletion_body: "Segur que voleu eliminar %{resource}? Aquesta acció no es pot desfer."+ resource_deletion_btn_text: "Elimina %{resource}"exchange_rate_tabs:calculate_rate_tab: Calcular la taxa FXconvert_tab: Convertir amb la taxa FXdiff --git a/config/locales/views/shared/en.yml b/config/locales/views/shared/en.ymlindex 056cb521e2..9d7606cf24 100644--- a/config/locales/views/shared/en.yml+++ b/config/locales/views/shared/en.yml@@ -29,6 +29,9 @@ en:default_title: "Are you sure?"default_body: "This is not reversible."default_btn_text: "Confirm"+ resource_deletion_title: "Delete %{resource}?"+ resource_deletion_body: "Are you sure you want to delete %{resource}? This is not reversible."+ resource_deletion_btn_text: "Delete %{resource}"family_moniker:group_plural: Groupsgroup_singular: Groupdiff --git a/config/locales/views/shared/fr.yml b/config/locales/views/shared/fr.ymlindex ed1652a138..06d54e0758 100644--- a/config/locales/views/shared/fr.yml+++ b/config/locales/views/shared/fr.yml@@ -15,6 +15,9 @@ fr:default_body: Ceci n’est pas réversible.default_btn_text: Confirmerdefault_title: Êtes-vous sûr?+ resource_deletion_title: "Supprimer %{resource} ?"+ resource_deletion_body: "Êtes-vous sûr de vouloir supprimer %{resource} ? Ceci n’est pas réversible."+ resource_deletion_btn_text: "Supprimer %{resource}"exchange_rate_tabs:calculate_rate_tab: Calculer le taux FXconvert_tab: Convertir avec le taux FXdiff --git a/config/locales/views/shared/hu.yml b/config/locales/views/shared/hu.ymlindex 33191380c5..50d7fd0006 100644--- a/config/locales/views/shared/hu.yml+++ b/config/locales/views/shared/hu.yml@@ -25,6 +25,9 @@ hu:default_title: "Biztosan?"default_body: "Ez a művelet nem vonható vissza."default_btn_text: "Megerősítés"+ resource_deletion_title: "Törli a következőt: %{resource}?"+ resource_deletion_body: "Biztosan törli a következőt: %{resource}? Ez a művelet nem vonható vissza."+ resource_deletion_btn_text: "%{resource} törlése"family_moniker:singular: Háztartásplural: Háztartásokdiff --git a/config/locales/views/shared/it.yml b/config/locales/views/shared/it.ymlindex c67223cb2f..aef40f7e07 100644--- a/config/locales/views/shared/it.yml+++ b/config/locales/views/shared/it.yml@@ -29,6 +29,9 @@ it:default_title: "Sei sicuro?"default_body: "Questa operazione non è reversibile."default_btn_text: "Conferma"+ resource_deletion_title: "Eliminare %{resource}?"+ resource_deletion_body: "Sei sicuro di voler eliminare %{resource}? Questa operazione non è reversibile."+ resource_deletion_btn_text: "Elimina %{resource}"family_moniker:group_plural: Gruppigroup_singular: Gruppodiff --git a/config/locales/views/shared/ru.yml b/config/locales/views/shared/ru.ymlindex c4c3f9cb85..bb42f43376 100644--- a/config/locales/views/shared/ru.yml+++ b/config/locales/views/shared/ru.yml@@ -16,6 +16,9 @@ ru:default_body: Это действие необратимо.default_btn_text: Подтвердитьdefault_title: Вы уверены?+ resource_deletion_title: "Удалить %{resource}?"+ resource_deletion_body: "Вы уверены, что хотите удалить %{resource}? Это действие необратимо."+ resource_deletion_btn_text: "Удалить %{resource}"exchange_rate_tabs:calculate_rate_tab: Рассчитать курсconvert_tab: Конвертировать по курсуdiff --git a/config/locales/views/shared/tr.yml b/config/locales/views/shared/tr.ymlindex 09579e0dd3..03a069a306 100644--- a/config/locales/views/shared/tr.yml+++ b/config/locales/views/shared/tr.yml@@ -16,6 +16,9 @@ tr:default_body: Bu işlem geri alınamaz.default_btn_text: Onayladefault_title: Emin misiniz?+ resource_deletion_title: "%{resource} silinsin mi?"+ resource_deletion_body: "%{resource} ögesini silmek istediğinize emin misiniz? Bu işlem geri alınamaz."+ resource_deletion_btn_text: "%{resource} sil"exchange_rate_tabs:calculate_rate_tab: Döviz Kuru Hesaplaconvert_tab: Döviz Kuru ile Dönüştürdiff --git a/config/locales/views/shared/vi.yml b/config/locales/views/shared/vi.ymlindex db485cb380..cb27d9428e 100644--- a/config/locales/views/shared/vi.yml+++ b/config/locales/views/shared/vi.yml@@ -25,6 +25,9 @@ vi:default_title: "Bạn có chắc không?"default_body: "Thao tác này không thể hoàn tác."default_btn_text: "Xác nhận"+ resource_deletion_title: "Xóa %{resource}?"+ resource_deletion_body: "Bạn có chắc muốn xóa %{resource} không? Thao tác này không thể hoàn tác."+ resource_deletion_btn_text: "Xóa %{resource}"family_moniker:group_plural: Nhómgroup_singular: Nhómdiff --git a/config/locales/views/shared/zh-CN.yml b/config/locales/views/shared/zh-CN.ymlindex 5f2d3499f3..1e285dac41 100644--- a/config/locales/views/shared/zh-CN.yml+++ b/config/locales/views/shared/zh-CN.yml@@ -25,6 +25,9 @@ zh-CN:default_title: 确定吗?default_body: 此操作不可逆。default_btn_text: 确认+ resource_deletion_title: "删除%{resource}?"+ resource_deletion_body: "确定要删除%{resource}吗?此操作不可逆。"+ resource_deletion_btn_text: "删除%{resource}"family_moniker:group_plural: 组group_singular: 组diff --git a/docs/llm-guides/goals.md b/docs/llm-guides/goals.mdindex 7592d917d1..ccd6966c3b 100644--- a/docs/llm-guides/goals.md+++ b/docs/llm-guides/goals.md@@ -44,7 +44,7 @@ Model layer:Controllers / routes:-- `app/controllers/goals_controller.rb` — index / show / new / create / edit / update / destroy / pause / resume / complete / archive / unarchive.+- `app/controllers/goals_controller.rb` — index / show / new / create / edit / update / destroy (any state) / pause / resume / complete / archive / unarchive.- `app/controllers/goal_pledges_controller.rb` — new / create / renew / destroy.- `config/routes.rb` — `resources :goals do resources :pledges ... member { patch :renew } end`.@@ -117,6 +117,17 @@ The AASM `state` is independent. Read `Goal#display_status` (not `#status`)to get the right pill label: it returns the AASM state when it's not`:active`, otherwise falls through to `#status`.+`archived` is a "keep it as a record" state, **not** a prerequisite for+deleting. `GoalsController#destroy` accepts a goal in any state. The only+affordance is the kebab on the show page — index cards deliberately carry+no actions, so the card stays a single click target. A delete cascades+only to `goal_accounts` and `goal_pledges`;+`GoalPledge#clear_matched_transaction_extra` unstamps+`extra["goal"]["pledge_id"]` from any transaction a matched pledge+claimed. No account, balance, entry or transaction is removed. Reuse+`Goal#deletion_confirm` rather than building a second `CustomConfirm` at+a new call site.+`Goal#pace` is the rolling 90-day net inflow into the linked accounts,divided by three. The query joins `entries` with `transactions`(valuations excluded by join shape), drops excluded entries, and dropsdiff --git a/test/controllers/goals_controller_test.rb b/test/controllers/goals_controller_test.rbindex cfc5c6d5b5..cd2023d62f 100644--- a/test/controllers/goals_controller_test.rb+++ b/test/controllers/goals_controller_test.rb@@ -1,6 +1,8 @@require "test_helper"class GoalsControllerTest < ActionDispatch::IntegrationTest+ include EntriesTestHelper+setup do@user = users(:family_admin)@user.update!(preferences: (@user.preferences || {}).merge("preview_features_enabled" => true))@@ -210,6 +212,23 @@ class GoalsControllerTest < ActionDispatch::IntegrationTestassert fresh.reload.active?end+ # The reported bug: Delete rendered only when the goal was archived, so an+ # active goal had no delete affordance anywhere in the UI. The kebab is the+ # only route to it, so assert the form is actually in the markup per state —+ # a 200 alone would not have caught the original miss.+ test "show exposes delete for a goal in every state" do+ delete_form = "form[action='#{goal_path(@goal)}'] input[name='_method'][value='delete']"++ %w[active paused completed archived].each do |state|+ @goal.update_column(:state, state)++ get goal_url(@goal)++ assert_response :success+ assert_select delete_form, 1, "no delete affordance on a #{state} goal"+ end+ end+# A goal whose last funding account is deleted survives with zero links and# fails `must_have_at_least_one_linked_account` from then on. Editing is the# only way back, so update must validate the accounts the user SUBMITTED,@@ -240,14 +259,16 @@ class GoalsControllerTest < ActionDispatch::IntegrationTestassert_equal "active", orphan.reload.stateend- test "destroy on non-archived is rejected" do- assert_no_difference "Goal.count" do+ test "destroy deletes an active goal and cascades to its links and pledges" do+ assert_difference -> { Goal.count } => -1,+ -> { GoalAccount.count } => -2,+ -> { GoalPledge.count } => -2 dodelete goal_url(@goal)end- assert_redirected_to goal_path(@goal)+ assert_redirected_to goals_pathend- test "destroy on archived deletes" do+ test "destroy deletes an archived goal" do@goal.archive!assert_difference "Goal.count", -1 dodelete goal_url(@goal)@@ -255,6 +276,23 @@ class GoalsControllerTest < ActionDispatch::IntegrationTestassert_redirected_to goals_pathend+ # The one thing a goal delete reaches outside its own tables: a matched+ # pledge stamps `extra["goal"]["pledge_id"]` onto the transaction it claimed,+ # and GoalPledge#clear_matched_transaction_extra must unstamp it on the way+ # out. The transaction itself must survive untouched.+ test "destroy unstamps the transaction a matched pledge claimed" do+ txn = create_transaction(account: @connected, amount: -300).entryable+ pledge = goal_pledges(:matched_transfer)+ txn.update!(extra: { "goal" => { "pledge_id" => pledge.id } })+ pledge.update_column(:matched_transaction_id, txn.id)++ delete goal_url(@goal)++ assert_redirected_to goals_path+ assert Transaction.exists?(txn.id), "deleting a goal must not delete the transaction"+ assert_nil txn.reload.extra.dig("goal", "pledge_id")+ end+test "index KPI swaps to 'All caught up' when every tracked goal is reached" dofamily = users(:family_admin).familyfamily.goals.destroy_alldiff --git a/test/helpers/custom_confirm_test.rb b/test/helpers/custom_confirm_test.rbnew file mode 100644index 0000000000..7fc7c6be1b--- /dev/null+++ b/test/helpers/custom_confirm_test.rb@@ -0,0 +1,50 @@+require "test_helper"++class CustomConfirmTest < ActiveSupport::TestCase+ # `confirm_dialog_controller` assigns `body` to innerHTML so bodies like+ # accounts' `confirm_body_html` can carry markup. Every caller passes a+ # user-named record, so an account named "<img src=x onerror=…>" would run+ # when someone opened the confirmation.+ test "escapes the resource name in the HTML-rendered body" do+ data = CustomConfirm.for_resource_deletion("<img src=x onerror=alert(1)>").to_data_attribute++ assert_includes data[:body], "<img src=x onerror=alert(1)>"+ assert_no_match(/<img/, data[:body])+ end++ # Title and button label reach the dialog through textContent, so they are+ # inert — pinned here so a future move to innerHTML doesn't pass silently.+ test "keeps the English copy the hardcoded strings produced" do+ data = CustomConfirm.for_resource_deletion("rule").to_data_attribute++ assert_equal "Delete Rule?", data[:title]+ assert_equal "Are you sure you want to delete rule? This is not reversible.", data[:body]+ assert_equal "Delete Rule", data[:confirmText]+ end++ # These back ~40 call sites across the app, so a locale that ships the+ # sibling `default_*` copy should ship these too. Locales without a+ # `custom_confirm` block at all are left out on purpose — adding one would+ # invent structure they have not adopted, and fallbacks cover them.+ test "resource-deletion copy resolves wherever the sibling default copy lives" do+ localized = Dir["config/locales/views/shared/*.yml"].filter_map do |path|+ locale = File.basename(path, ".yml")+ next unless I18n.exists?("shared.custom_confirm.default_title", locale)+ locale+ end++ assert_operator localized.size, :>, 1, "expected more than just English to define this block"++ localized.each do |locale|+ body = I18n.t("shared.custom_confirm.resource_deletion_body", resource: "Wedding", locale: locale)+ assert_includes body, "Wedding", "#{locale} dropped the %{resource} interpolation"+ assert I18n.t("shared.custom_confirm.resource_deletion_title", resource: "x", locale: locale).present?+ assert I18n.t("shared.custom_confirm.resource_deletion_btn_text", resource: "x", locale: locale).present?+ end+ end++ test "high severity picks the destructive button variant" do+ assert_equal "destructive", CustomConfirm.for_resource_deletion("rule", high_severity: true).to_data_attribute[:variant]+ assert_equal "outline-destructive", CustomConfirm.for_resource_deletion("rule").to_data_attribute[:variant]+ end+enddiff --git a/test/models/goal_test.rb b/test/models/goal_test.rbindex e6af35e840..3c9da94cf7 100644--- a/test/models/goal_test.rb+++ b/test/models/goal_test.rb@@ -14,6 +14,38 @@ class GoalTest < ActiveSupport::TestCaseassert @goal.valid?end+ # The confirm dialog assigns `body` to innerHTML, so an unescaped goal name+ # would execute when a family member opens the delete confirmation.+ test "deletion_confirm escapes the goal name in the dialog body" do+ @goal.name = "<img src=x onerror=alert(1)>"++ body = @goal.deletion_confirm.to_data_attribute[:body]++ assert_includes body, "<img src=x onerror=alert(1)>"+ assert_no_match(/<img/, body)+ end++ # Derived, not a hardcoded list: a locale added later ships a goals YAML+ # without these keys otherwise. `fallback: false` carries as much weight —+ # the backend has I18n::Backend::Fallbacks mixed in, so a missing German key+ # resolves to the English string and a plain `.present?` assertion passes+ # while a German family reads English in the dialog.+ test "confirm_delete copy resolves in every locale that ships goal translations" do+ locales = Rails.root.glob("config/locales/views/goals/*.yml").map { |f| f.basename(".yml").to_s.to_sym }+ assert_operator locales.size, :>=, 7, "goal locale files disappeared — check the glob"++ locales.each do |locale|+ body = I18n.t("goals.show.confirm_delete_body", name: "Wedding", locale: locale, fallback: false, default: nil)+ assert body, "#{locale} is missing goals.show.confirm_delete_body"+ assert_includes body, "Wedding", "#{locale} dropped the %{name} interpolation"++ %w[confirm_delete_title confirm_delete_cta].each do |key|+ assert I18n.t("goals.show.#{key}", locale: locale, fallback: false, default: nil).present?,+ "#{locale} is missing goals.show.#{key}"+ end+ end+ end+# The days-left segment is returned separately so the view can keep it# unbroken; joined into one string it wrapped after "days" on a phone.test "header_summary_parts keeps the days-left phrase in its own segment" do