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.

80 lines
1.9 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. @form = Form::StatusBatch.new
  12. end
  13. def update
  14. authorize @report, :update?
  15. process_report
  16. redirect_to admin_report_path(@report)
  17. end
  18. private
  19. def process_report
  20. case params[:outcome].to_s
  21. when 'resolve'
  22. @report.update!(action_taken_by_current_attributes)
  23. log_action :resolve, @report
  24. when 'suspend'
  25. Admin::SuspensionWorker.perform_async(@report.target_account.id)
  26. log_action :resolve, @report
  27. log_action :suspend, @report.target_account
  28. resolve_all_target_account_reports
  29. when 'silence'
  30. @report.target_account.update!(silenced: true)
  31. log_action :resolve, @report
  32. log_action :silence, @report.target_account
  33. resolve_all_target_account_reports
  34. else
  35. raise ActiveRecord::RecordNotFound
  36. end
  37. end
  38. def action_taken_by_current_attributes
  39. { action_taken: true, action_taken_by_account_id: current_account.id }
  40. end
  41. def resolve_all_target_account_reports
  42. unresolved_reports_for_target_account.update_all(
  43. action_taken_by_current_attributes
  44. )
  45. end
  46. def unresolved_reports_for_target_account
  47. Report.where(
  48. target_account: @report.target_account
  49. ).unresolved
  50. end
  51. def filtered_reports
  52. ReportFilter.new(filter_params).results.order(id: :desc).includes(
  53. :account,
  54. :target_account
  55. )
  56. end
  57. def filter_params
  58. params.permit(
  59. :account_id,
  60. :resolved,
  61. :target_account_id
  62. )
  63. end
  64. def set_report
  65. @report = Report.find(params[:id])
  66. end
  67. end
  68. end