mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-05 17:31:12 +00:00
Fix error handling for blank actions in account moderation action form (#35246)
This commit is contained in:
parent
c66c5fd73d
commit
e97f43399b
|
@ -14,16 +14,20 @@ module Admin
|
|||
def create
|
||||
authorize @account, :show?
|
||||
|
||||
account_action = Admin::AccountAction.new(resource_params)
|
||||
account_action.target_account = @account
|
||||
account_action.current_account = current_account
|
||||
@account_action = Admin::AccountAction.new(resource_params)
|
||||
@account_action.target_account = @account
|
||||
@account_action.current_account = current_account
|
||||
|
||||
account_action.save!
|
||||
|
||||
if account_action.with_report?
|
||||
redirect_to admin_reports_path, notice: I18n.t('admin.reports.processed_msg', id: resource_params[:report_id])
|
||||
if @account_action.save
|
||||
if @account_action.with_report?
|
||||
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
|
||||
redirect_to admin_account_path(@account.id)
|
||||
@warning_presets = AccountWarningPreset.all
|
||||
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -32,8 +32,8 @@ class Admin::AccountAction
|
|||
validates :type, :target_account, :current_account, presence: true
|
||||
validates :type, inclusion: { in: TYPES }
|
||||
|
||||
def save!
|
||||
raise ActiveRecord::RecordInvalid, self unless valid?
|
||||
def save
|
||||
return false unless valid?
|
||||
|
||||
ApplicationRecord.transaction do
|
||||
process_action!
|
||||
|
@ -43,6 +43,12 @@ class Admin::AccountAction
|
|||
|
||||
process_notification!
|
||||
process_queue!
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def save!
|
||||
raise ActiveRecord::RecordInvalid, self unless save
|
||||
end
|
||||
|
||||
def report
|
||||
|
|
|
@ -15,6 +15,13 @@ RSpec.describe 'Admin Account Actions' do
|
|||
expect(page)
|
||||
.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')
|
||||
expect { submit_form }
|
||||
.to change { account.strikes.count }.by(1)
|
||||
|
|
Loading…
Reference in New Issue
Block a user