actions_controller.rb 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # frozen_string_literal: true
  2. class Admin::Reports::ActionsController < Admin::BaseController
  3. before_action :set_report
  4. def create
  5. authorize @report, :show?
  6. case action_from_button
  7. when 'delete', 'mark_as_sensitive'
  8. status_batch_action = Admin::StatusBatchAction.new(
  9. type: action_from_button,
  10. status_ids: @report.status_ids,
  11. current_account: current_account,
  12. report_id: @report.id,
  13. send_email_notification: !@report.spam?
  14. )
  15. status_batch_action.save!
  16. when 'silence', 'suspend'
  17. account_action = Admin::AccountAction.new(
  18. type: action_from_button,
  19. report_id: @report.id,
  20. target_account: @report.target_account,
  21. current_account: current_account,
  22. send_email_notification: !@report.spam?
  23. )
  24. account_action.save!
  25. end
  26. redirect_to admin_reports_path
  27. end
  28. private
  29. def set_report
  30. @report = Report.find(params[:report_id])
  31. end
  32. def action_from_button
  33. if params[:delete]
  34. 'delete'
  35. elsif params[:mark_as_sensitive]
  36. 'mark_as_sensitive'
  37. elsif params[:silence]
  38. 'silence'
  39. elsif params[:suspend]
  40. 'suspend'
  41. end
  42. end
  43. end