report_notes_controller.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # frozen_string_literal: true
  2. module Admin
  3. class ReportNotesController < BaseController
  4. before_action :set_report_note, only: [:destroy]
  5. def create
  6. authorize :report_note, :create?
  7. @report_note = current_account.report_notes.new(resource_params)
  8. @report = @report_note.report
  9. if @report_note.save
  10. if params[:create_and_resolve]
  11. @report.resolve!(current_account)
  12. log_action :resolve, @report
  13. elsif params[:create_and_unresolve]
  14. @report.unresolve!
  15. log_action :reopen, @report
  16. end
  17. redirect_to after_create_redirect_path, notice: I18n.t('admin.report_notes.created_msg')
  18. else
  19. @report_notes = @report.notes.includes(:account).order(id: :desc)
  20. @action_logs = @report.history.includes(:target)
  21. @form = Admin::StatusBatchAction.new
  22. @statuses = @report.statuses.with_includes
  23. render 'admin/reports/show'
  24. end
  25. end
  26. def destroy
  27. authorize @report_note, :destroy?
  28. @report_note.destroy!
  29. redirect_to admin_report_path(@report_note.report_id), notice: I18n.t('admin.report_notes.destroyed_msg')
  30. end
  31. private
  32. def after_create_redirect_path
  33. if params[:create_and_resolve]
  34. admin_reports_path
  35. else
  36. admin_report_path(@report)
  37. end
  38. end
  39. def resource_params
  40. params.require(:report_note).permit(
  41. :content,
  42. :report_id
  43. )
  44. end
  45. def set_report_note
  46. @report_note = ReportNote.find(params[:id])
  47. end
  48. end
  49. end