The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

100 lines
2.5 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 'disable'
  40. @report.resolve!(current_account)
  41. @report.target_account.user.disable!
  42. log_action :resolve, @report
  43. log_action :disable, @report.target_account.user
  44. resolve_all_target_account_reports
  45. when 'silence'
  46. @report.resolve!(current_account)
  47. @report.target_account.update!(silenced: true)
  48. log_action :resolve, @report
  49. log_action :silence, @report.target_account
  50. resolve_all_target_account_reports
  51. else
  52. raise ActiveRecord::RecordNotFound
  53. end
  54. @report.reload
  55. end
  56. def resolve_all_target_account_reports
  57. unresolved_reports_for_target_account.update_all(action_taken: true, action_taken_by_account_id: current_account.id)
  58. end
  59. def unresolved_reports_for_target_account
  60. Report.where(
  61. target_account: @report.target_account
  62. ).unresolved
  63. end
  64. def filtered_reports
  65. ReportFilter.new(filter_params).results.order(id: :desc).includes(
  66. :account,
  67. :target_account
  68. )
  69. end
  70. def filter_params
  71. params.permit(
  72. :account_id,
  73. :resolved,
  74. :target_account_id
  75. )
  76. end
  77. def set_report
  78. @report = Report.find(params[:id])
  79. end
  80. end
  81. end