blob: 5e1e6d8797b5689cb5ffd29688d3746a2557e8dc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# 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
|