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.

70 lines
1.6 KiB

  1. # frozen_string_literal: true
  2. module Admin
  3. class ReportsController < BaseController
  4. before_action :set_report, except: [:index]
  5. def index
  6. @reports = filtered_reports.page(params[:page])
  7. end
  8. def show; end
  9. def update
  10. process_report
  11. redirect_to admin_report_path(@report)
  12. end
  13. private
  14. def process_report
  15. case params[:outcome].to_s
  16. when 'resolve'
  17. @report.update(action_taken_by_current_attributes)
  18. when 'suspend'
  19. Admin::SuspensionWorker.perform_async(@report.target_account.id)
  20. resolve_all_target_account_reports
  21. when 'silence'
  22. @report.target_account.update(silenced: true)
  23. resolve_all_target_account_reports
  24. else
  25. raise ActiveRecord::RecordNotFound
  26. end
  27. end
  28. def action_taken_by_current_attributes
  29. { action_taken: true, action_taken_by_account_id: current_account.id }
  30. end
  31. def resolve_all_target_account_reports
  32. unresolved_reports_for_target_account.update_all(
  33. action_taken_by_current_attributes
  34. )
  35. end
  36. def unresolved_reports_for_target_account
  37. Report.where(
  38. target_account: @report.target_account
  39. ).unresolved
  40. end
  41. def filtered_reports
  42. ReportFilter.new(filter_params).results.order(id: :desc).includes(
  43. :account,
  44. :target_account
  45. )
  46. end
  47. def filter_params
  48. params.permit(
  49. :account_id,
  50. :resolved,
  51. :target_account_id
  52. )
  53. end
  54. def set_report
  55. @report = Report.find(params[:id])
  56. end
  57. end
  58. end