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.

62 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. 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 + @report.target_account.targeted_account_warnings.latest.custom).sort_by(&:created_at)
  13. @form = Form::StatusBatch.new
  14. end
  15. def assign_to_self
  16. authorize @report, :update?
  17. @report.update!(assigned_account_id: current_account.id)
  18. log_action :assigned_to_self, @report
  19. redirect_to admin_report_path(@report)
  20. end
  21. def unassign
  22. authorize @report, :update?
  23. @report.update!(assigned_account_id: nil)
  24. log_action :unassigned, @report
  25. redirect_to admin_report_path(@report)
  26. end
  27. def reopen
  28. authorize @report, :update?
  29. @report.unresolve!
  30. log_action :reopen, @report
  31. redirect_to admin_report_path(@report)
  32. end
  33. def resolve
  34. authorize @report, :update?
  35. @report.resolve!(current_account)
  36. log_action :resolve, @report
  37. redirect_to admin_reports_path, notice: I18n.t('admin.reports.resolved_msg')
  38. end
  39. private
  40. def filtered_reports
  41. ReportFilter.new(filter_params).results.order(id: :desc).includes(:account, :target_account)
  42. end
  43. def filter_params
  44. params.slice(*ReportFilter::KEYS).permit(*ReportFilter::KEYS)
  45. end
  46. def set_report
  47. @report = Report.find(params[:id])
  48. end
  49. end
  50. end