You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.4 KiB

  1. # frozen_string_literal: true
  2. module Admin
  3. class ReportsController < BaseController
  4. before_action :set_report, except: [:index]
  5. def index
  6. authorize :report, :index?
  7. @reports = filtered_reports.page(params[:page])
  8. end
  9. def show
  10. authorize @report, :show?
  11. @report_note = @report.notes.new
  12. @report_notes = (@report.notes.latest + @report.history).sort_by(&:created_at)
  13. @form = Form::StatusBatch.new
  14. end
  15. def update
  16. authorize @report, :update?
  17. process_report
  18. if @report.action_taken?
  19. redirect_to admin_reports_path, notice: I18n.t('admin.reports.resolved_msg')
  20. else
  21. redirect_to admin_report_path(@report)
  22. end
  23. end
  24. private
  25. def process_report
  26. case params[:outcome].to_s
  27. when 'assign_to_self'
  28. @report.update!(assigned_account_id: current_account.id)
  29. log_action :assigned_to_self, @report
  30. when 'unassign'
  31. @report.update!(assigned_account_id: nil)
  32. log_action :unassigned, @report
  33. when 'reopen'
  34. @report.unresolve!
  35. log_action :reopen, @report
  36. when 'resolve'
  37. @report.resolve!(current_account)
  38. log_action :resolve, @report
  39. when 'suspend'
  40. Admin::SuspensionWorker.perform_async(@report.target_account.id)
  41. log_action :resolve, @report
  42. log_action :suspend, @report.target_account
  43. resolve_all_target_account_reports
  44. when 'silence'
  45. @report.target_account.update!(silenced: true)
  46. log_action :resolve, @report
  47. log_action :silence, @report.target_account
  48. resolve_all_target_account_reports
  49. else
  50. raise ActiveRecord::RecordNotFound
  51. end
  52. @report.reload
  53. end
  54. def resolve_all_target_account_reports
  55. unresolved_reports_for_target_account.update_all(action_taken: true, action_taken_by_account_id: current_account.id)
  56. end
  57. def unresolved_reports_for_target_account
  58. Report.where(
  59. target_account: @report.target_account
  60. ).unresolved
  61. end
  62. def filtered_reports
  63. ReportFilter.new(filter_params).results.order(id: :desc).includes(
  64. :account,
  65. :target_account
  66. )
  67. end
  68. def filter_params
  69. params.permit(
  70. :account_id,
  71. :resolved,
  72. :target_account_id
  73. )
  74. end
  75. def set_report
  76. @report = Report.find(params[:id])
  77. end
  78. end
  79. end