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.

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