logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

reports_controller.rb (2435B)


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