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.

56 lines
1.4 KiB

  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 ReportNote, :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. redirect_to admin_reports_path, notice: I18n.t('admin.reports.resolved_msg')
  14. return
  15. end
  16. if params[:create_and_unresolve]
  17. @report.unresolve!
  18. log_action :reopen, @report
  19. end
  20. redirect_to admin_report_path(@report), notice: I18n.t('admin.report_notes.created_msg')
  21. else
  22. @report_notes = @report.notes.latest
  23. @report_history = @report.history
  24. @form = Form::StatusBatch.new
  25. render template: 'admin/reports/show'
  26. end
  27. end
  28. def destroy
  29. authorize @report_note, :destroy?
  30. @report_note.destroy!
  31. redirect_to admin_report_path(@report_note.report_id), notice: I18n.t('admin.report_notes.destroyed_msg')
  32. end
  33. private
  34. def resource_params
  35. params.require(:report_note).permit(
  36. :content,
  37. :report_id
  38. )
  39. end
  40. def set_report_note
  41. @report_note = ReportNote.find(params[:id])
  42. end
  43. end
  44. end