actions_controller.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # frozen_string_literal: true
  2. class Admin::Reports::ActionsController < Admin::BaseController
  3. before_action :set_report
  4. def preview
  5. authorize @report, :show?
  6. @moderation_action = action_from_button
  7. end
  8. def create
  9. authorize @report, :show?
  10. case action_from_button
  11. when 'delete', 'mark_as_sensitive'
  12. status_batch_action = Admin::StatusBatchAction.new(
  13. type: action_from_button,
  14. status_ids: @report.status_ids,
  15. current_account: current_account,
  16. report_id: @report.id,
  17. send_email_notification: !@report.spam?,
  18. text: params[:text]
  19. )
  20. status_batch_action.save!
  21. when 'silence', 'suspend'
  22. account_action = Admin::AccountAction.new(
  23. type: action_from_button,
  24. report_id: @report.id,
  25. target_account: @report.target_account,
  26. current_account: current_account,
  27. send_email_notification: !@report.spam?,
  28. text: params[:text]
  29. )
  30. account_action.save!
  31. else
  32. return redirect_to admin_report_path(@report), alert: I18n.t('admin.reports.unknown_action_msg', action: action_from_button)
  33. end
  34. redirect_to admin_reports_path, notice: I18n.t('admin.reports.processed_msg', id: @report.id)
  35. end
  36. private
  37. def set_report
  38. @report = Report.find(params[:report_id])
  39. end
  40. def action_from_button
  41. if params[:delete]
  42. 'delete'
  43. elsif params[:mark_as_sensitive]
  44. 'mark_as_sensitive'
  45. elsif params[:silence]
  46. 'silence'
  47. elsif params[:suspend]
  48. 'suspend'
  49. elsif params[:moderation_action]
  50. params[:moderation_action]
  51. end
  52. end
  53. end