From 2e1365d37bddf787c7089126c1a5ff1c623ab0e2 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Wed, 20 Mar 2024 10:49:38 -0400 Subject: Added mass pending comment deletion/markspamming --- app/controllers/admin/comments_controller.rb | 53 +++++++++++++++++++--------- 1 file changed, 37 insertions(+), 16 deletions(-) (limited to 'app/controllers/admin') diff --git a/app/controllers/admin/comments_controller.rb b/app/controllers/admin/comments_controller.rb index 6b4bff3..4d9502d 100644 --- a/app/controllers/admin/comments_controller.rb +++ b/app/controllers/admin/comments_controller.rb @@ -33,22 +33,7 @@ class Admin::CommentsController < Admin::AdminController def mark_spam @comment = Comment.find(params[:id]) - - akismet_params = { - type: "comment", - text: @comment.body, - created_at: @comment.created_at, - author: @comment.username, - author_email: @comment.email, - author_url: @comment.website, - post_url: url_for(@comment.blog), - post_modified_at: @comment.blog.updated_at, - referrer: @comment.referrer - } - - Akismet.spam @comment.request_ip, @comment.user_agent, akismet_params - - @comment.destroy! + perform_mark_spam(@comment) flash.notice = "Comment successfully marked as spam." redirect_back fallback_location: pending_admin_comments_url @@ -64,9 +49,45 @@ class Admin::CommentsController < Admin::AdminController redirect_to admin_comments_url end + def mass + if params[:mass_action] == "Delete" + Comment.destroy_by(id: params[:comment_ids]) + + flash.notice = "Comments successfully deleted." + elsif params[:mass_action] == "Mark Spam" + @comments = Comment.find(params[:comment_ids]) + + @comments.each do |comment| + perform_mark_spam(comment) + end + + flash.notice = "Comments successfully marked as spam." + end + + redirect_back fallback_location: pending_admin_comments_url + end + private def set_section @section = "comments" end + + def perform_mark_spam(comment) + akismet_params = { + type: "comment", + text: comment.body, + created_at: comment.created_at, + author: comment.username, + author_email: comment.email, + author_url: comment.website, + post_url: url_for(comment.blog), + post_modified_at: comment.blog.updated_at, + referrer: comment.referrer + } + + Akismet.spam comment.request_ip, comment.user_agent, akismet_params + + comment.destroy! + end end -- cgit 1.4.1