2
0

Move shared params to common method in admin/reports/actions (#35353)

This commit is contained in:
Matt Jankowski
2025-07-14 05:23:18 -04:00
committed by GitHub
parent a3ffd2edf8
commit 7273f6c03c
2 changed files with 28 additions and 20 deletions

View File

@@ -13,27 +13,9 @@ class Admin::Reports::ActionsController < Admin::BaseController
case action_from_button case action_from_button
when 'delete', 'mark_as_sensitive' when 'delete', 'mark_as_sensitive'
status_batch_action = Admin::StatusBatchAction.new( Admin::StatusBatchAction.new(status_batch_action_params).save!
type: action_from_button,
status_ids: @report.status_ids,
current_account: current_account,
report_id: @report.id,
send_email_notification: !@report.spam?,
text: params[:text]
)
status_batch_action.save!
when 'silence', 'suspend' when 'silence', 'suspend'
account_action = Admin::AccountAction.new( Admin::AccountAction.new(account_action_params).save!
type: action_from_button,
report_id: @report.id,
target_account: @report.target_account,
current_account: current_account,
send_email_notification: !@report.spam?,
text: params[:text]
)
account_action.save!
else else
return redirect_to admin_report_path(@report), alert: I18n.t('admin.reports.unknown_action_msg', action: action_from_button) return redirect_to admin_report_path(@report), alert: I18n.t('admin.reports.unknown_action_msg', action: action_from_button)
end end
@@ -43,6 +25,26 @@ class Admin::Reports::ActionsController < Admin::BaseController
private private
def status_batch_action_params
shared_params
.merge(status_ids: @report.status_ids)
end
def account_action_params
shared_params
.merge(target_account: @report.target_account)
end
def shared_params
{
current_account: current_account,
report_id: @report.id,
send_email_notification: !@report.spam?,
text: params[:text],
type: action_from_button,
}
end
def set_report def set_report
@report = Report.find(params[:report_id]) @report = Report.find(params[:report_id])
end end

View File

@@ -144,6 +144,12 @@ RSpec.describe Admin::Reports::ActionsController do
expect(media_attached_status.reload.sensitive).to be true expect(media_attached_status.reload.sensitive).to be true
end end
end end
context 'when the action is "invalid_action"' do
let(:action) { 'invalid_action' }
it { is_expected.to redirect_to(admin_report_path(report)) }
end
end end
context 'with action as submit button' do context 'with action as submit button' do