Compare commits

...

2 Commits

Author SHA1 Message Date
Matt Jankowski
36908d2d64
Merge ac5d8f9bb0 into 624c024766 2025-09-03 10:05:11 +00:00
Matt Jankowski
ac5d8f9bb0 Avoid render redirect_to in admin/reports/actions 2025-08-28 09:00:41 -04:00

View File

@ -2,22 +2,29 @@
class Admin::Reports::ActionsController < Admin::BaseController class Admin::Reports::ActionsController < Admin::BaseController
before_action :set_report before_action :set_report
before_action :verify_report_permissions
before_action :unknown_action, unless: :valid_button_action?, only: :create
STATUS_ACTIONS = %w(
delete
mark_as_sensitive
).freeze
ACCOUNT_ACTIONS = %w(
silence
suspend
).freeze
def preview def preview
authorize @report, :show?
@moderation_action = action_from_button @moderation_action = action_from_button
end end
def create def create
authorize @report, :show?
case action_from_button case action_from_button
when 'delete', 'mark_as_sensitive' when *STATUS_ACTIONS
Admin::StatusBatchAction.new(status_batch_action_params).save! Admin::StatusBatchAction.new(status_batch_action_params).save!
when 'silence', 'suspend' when *ACCOUNT_ACTIONS
Admin::AccountAction.new(account_action_params).save! Admin::AccountAction.new(account_action_params).save!
else
return redirect_to admin_report_path(@report), alert: I18n.t('admin.reports.unknown_action_msg', action: action_from_button)
end end
redirect_to admin_reports_path, notice: I18n.t('admin.reports.processed_msg', id: @report.id) redirect_to admin_reports_path, notice: I18n.t('admin.reports.processed_msg', id: @report.id)
@ -25,6 +32,20 @@ class Admin::Reports::ActionsController < Admin::BaseController
private private
def verify_report_permissions
authorize @report, :show?
end
def unknown_action
redirect_to admin_report_path(@report), alert: t('admin.reports.unknown_action_msg', action: action_from_button)
end
def valid_button_action?
[STATUS_ACTIONS, ACCOUNT_ACTIONS]
.flatten
.include?(action_from_button)
end
def status_batch_action_params def status_batch_action_params
shared_params shared_params
.merge(status_ids: @report.status_ids) .merge(status_ids: @report.status_ids)