# frozen_string_literal: true class Admin::ModNotesController < ApplicationController include UserQuery before_action :check_authorization before_action :load_notable, only: [:new, :create] before_action :load_mod_note, except: [:new, :create] def index @title = 'Admin - Mod Notes' @notes = if params[:q] @query = params[:q] ModNote.where('body ILIKE ?', '%' + @query + '%') else ModNote end.order(created_at: :desc).page(params[:page]).per(50) end def new @title = 'New Mod Note' @mod_note = @notable.mod_notes.new end def create @notable.mod_notes.create!(moderator: current_user, body: params[:mod_note][:body]) redirect_to admin_mod_notes_path end def destroy @mod_note.destroy! redirect_to admin_mod_notes_path end def edit @title = 'Editing Mod Note' end def update @mod_note.update(body: params[:mod_note][:body]) redirect_to admin_mod_notes_path end private def check_authorization authorize! :manage, ModNote end def load_mod_note @mod_note = ModNote.find(params[:id]) end def load_notable notable_class = params[:notable_class].capitalize.safe_constantize return false unless notable_class < Notable @notable = notable_class.find(params[:notable_id]) end end