From 4b1d0278afe7cb9f0156463781efc37fd29047b4 Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 17 Sep 2026 17:03:24 +0000 Subject: [PATCH] Always require typing username when self-deleting account (#40576) --- app/controllers/settings/deletes_controller.rb | 8 +++----- app/views/settings/deletes/show.html.haml | 4 ++-- spec/system/settings/deletes_spec.rb | 9 +++++++++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/controllers/settings/deletes_controller.rb b/app/controllers/settings/deletes_controller.rb index 815d95ad83..053d419692 100644 --- a/app/controllers/settings/deletes_controller.rb +++ b/app/controllers/settings/deletes_controller.rb @@ -29,11 +29,9 @@ class Settings::DeletesController < Settings::BaseController end def challenge_passed? - if current_user.encrypted_password.blank? - current_account.username == resource_params[:username] - else - current_user.valid_password?(resource_params[:password]) - end + return false unless current_account.username == resource_params[:username] + + current_user.encrypted_password.blank? || current_user.valid_password?(resource_params[:password]) end def destroy_account! diff --git a/app/views/settings/deletes/show.html.haml b/app/views/settings/deletes/show.html.haml index 2e9785c898..d87edc83ae 100644 --- a/app/views/settings/deletes/show.html.haml +++ b/app/views/settings/deletes/show.html.haml @@ -20,10 +20,10 @@ %hr.spacer/ + = f.input :username, wrapper: :with_block_label, input_html: { autocomplete: 'off' }, hint: t('deletes.confirm_username') + - if current_user.encrypted_password.present? = f.input :password, wrapper: :with_block_label, input_html: { autocomplete: 'current-password' }, hint: t('deletes.confirm_password') - - else - = f.input :username, wrapper: :with_block_label, input_html: { autocomplete: 'off' }, hint: t('deletes.confirm_username') .actions = f.button :button, t('deletes.proceed'), type: :submit, class: 'negative' diff --git a/spec/system/settings/deletes_spec.rb b/spec/system/settings/deletes_spec.rb index 2a18a27694..a5644a9e4f 100644 --- a/spec/system/settings/deletes_spec.rb +++ b/spec/system/settings/deletes_spec.rb @@ -15,12 +15,21 @@ RSpec.describe 'Settings Deletes' do .and have_private_cache_control # Wrong confirmation value + fill_in 'form_delete_confirmation_username', with: user.account.username fill_in 'form_delete_confirmation_password', with: 'wrongvalue' click_on I18n.t('deletes.proceed') expect(page) .to have_text(I18n.t('deletes.challenge_not_passed')) + # Wrong confirmation value + fill_in 'form_delete_confirmation_username', with: 'wrongvalue' + fill_in 'form_delete_confirmation_password', with: user.password + click_on I18n.t('deletes.proceed') + expect(page) + .to have_text(I18n.t('deletes.challenge_not_passed')) + # Correct confirmation value + fill_in 'form_delete_confirmation_username', with: user.account.username fill_in 'form_delete_confirmation_password', with: user.password click_on I18n.t('deletes.proceed') expect(page)