Fix error handling for blank actions in account moderation action form (#35246)

This commit is contained in:
Claire 2025-07-03 16:42:48 +02:00 committed by GitHub
parent c66c5fd73d
commit e97f43399b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 10 deletions

View File

@ -14,16 +14,20 @@ module Admin
def create def create
authorize @account, :show? authorize @account, :show?
account_action = Admin::AccountAction.new(resource_params) @account_action = Admin::AccountAction.new(resource_params)
account_action.target_account = @account @account_action.target_account = @account
account_action.current_account = current_account @account_action.current_account = current_account
account_action.save! if @account_action.save
if @account_action.with_report?
if account_action.with_report? redirect_to admin_reports_path, notice: I18n.t('admin.reports.processed_msg', id: resource_params[:report_id])
redirect_to admin_reports_path, notice: I18n.t('admin.reports.processed_msg', id: resource_params[:report_id]) else
redirect_to admin_account_path(@account.id)
end
else else
redirect_to admin_account_path(@account.id) @warning_presets = AccountWarningPreset.all
render :new
end end
end end

View File

@ -32,8 +32,8 @@ class Admin::AccountAction
validates :type, :target_account, :current_account, presence: true validates :type, :target_account, :current_account, presence: true
validates :type, inclusion: { in: TYPES } validates :type, inclusion: { in: TYPES }
def save! def save
raise ActiveRecord::RecordInvalid, self unless valid? return false unless valid?
ApplicationRecord.transaction do ApplicationRecord.transaction do
process_action! process_action!
@ -43,6 +43,12 @@ class Admin::AccountAction
process_notification! process_notification!
process_queue! process_queue!
true
end
def save!
raise ActiveRecord::RecordInvalid, self unless save
end end
def report def report

View File

@ -15,6 +15,13 @@ RSpec.describe 'Admin Account Actions' do
expect(page) expect(page)
.to have_title(I18n.t('admin.account_actions.title', acct: account.pretty_acct)) .to have_title(I18n.t('admin.account_actions.title', acct: account.pretty_acct))
# Invalid submission
expect { submit_form }
.to_not(change { account.strikes.count })
expect(page)
.to have_content(/can't be blank/)
# Valid submission
choose(option: 'silence') choose(option: 'silence')
expect { submit_form } expect { submit_form }
.to change { account.strikes.count }.by(1) .to change { account.strikes.count }.by(1)