about summary refs log tree commit diff stats
path: root/app/controllers/admin/comments_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/admin/comments_controller.rb')
-rw-r--r--app/controllers/admin/comments_controller.rb93
1 files changed, 93 insertions, 0 deletions
diff --git a/app/controllers/admin/comments_controller.rb b/app/controllers/admin/comments_controller.rb new file mode 100644 index 0000000..4d9502d --- /dev/null +++ b/app/controllers/admin/comments_controller.rb
@@ -0,0 +1,93 @@
1class Admin::CommentsController < Admin::AdminController
2 before_action :set_section
3
4 def index
5 @comments = Comment.where(status: :published).order(updated_at: :desc).paginate(page: params[:page], per_page: 20)
6 end
7
8 def pending
9 @comments = Comment.where(status: :pending).order(updated_at: :desc).paginate(page: params[:page], per_page: 20)
10 end
11
12 def accept
13 @comment = Comment.find(params[:id])
14 @comment.status = :published
15 @comment.save!
16
17 if @comment.reply_to and @comment.reply_to.email != @comment.blog.user.email and @comment.reply_to.email != current_user.email
18 CommentMailer.with(comment: @comment).reply_comment_email.deliver_later
19 end
20
21 flash.notice = "Comment successfully published."
22 redirect_to pending_admin_comments_url
23 end
24
25 def reject
26 @comment = Comment.find(params[:id])
27 @comment.status = :rejected
28 @comment.save!
29
30 flash.notice = "Comment successfully rejected."
31 redirect_to pending_admin_comments_url
32 end
33
34 def mark_spam
35 @comment = Comment.find(params[:id])
36 perform_mark_spam(@comment)
37
38 flash.notice = "Comment successfully marked as spam."
39 redirect_back fallback_location: pending_admin_comments_url
40 end
41
42 def destroy
43 if Comment.destroy(params[:id])
44 flash.notice = "Comment successfully deleted."
45 else
46 flash.alert = "Could not delete comment."
47 end
48
49 redirect_to admin_comments_url
50 end
51
52 def mass
53 if params[:mass_action] == "Delete"
54 Comment.destroy_by(id: params[:comment_ids])
55
56 flash.notice = "Comments successfully deleted."
57 elsif params[:mass_action] == "Mark Spam"
58 @comments = Comment.find(params[:comment_ids])
59
60 @comments.each do |comment|
61 perform_mark_spam(comment)
62 end
63
64 flash.notice = "Comments successfully marked as spam."
65 end
66
67 redirect_back fallback_location: pending_admin_comments_url
68 end
69
70 private
71
72 def set_section
73 @section = "comments"
74 end
75
76 def perform_mark_spam(comment)
77 akismet_params = {
78 type: "comment",
79 text: comment.body,
80 created_at: comment.created_at,
81 author: comment.username,
82 author_email: comment.email,
83 author_url: comment.website,
84 post_url: url_for(comment.blog),
85 post_modified_at: comment.blog.updated_at,
86 referrer: comment.referrer
87 }
88
89 Akismet.spam comment.request_ip, comment.user_agent, akismet_params
90
91 comment.destroy!
92 end
93end