reports_controller.rb 1.6 KB

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