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/assets/javascripts/admin/dashboard.coffee | 2 + app/assets/stylesheets/admin/dashboard.scss | 5 +++ app/controllers/admin/comments_controller.rb | 53 +++++++++++++++++++-------- app/views/admin/comments/pending.haml | 52 ++++++++++++++------------ 4 files changed, 73 insertions(+), 39 deletions(-) (limited to 'app') diff --git a/app/assets/javascripts/admin/dashboard.coffee b/app/assets/javascripts/admin/dashboard.coffee index 4fa6cd8..bc48315 100644 --- a/app/assets/javascripts/admin/dashboard.coffee +++ b/app/assets/javascripts/admin/dashboard.coffee @@ -3,6 +3,8 @@ # You can use CoffeeScript in this file: http://coffeescript.org/ dash_ready = -> $(".datepicker").datepicker({"dateFormat": "yy-mm-dd"}) + $("#check_all").change -> + $(".comment_ids").prop("checked", $(this).prop("checked")) $(document).ready(dash_ready) $(document).on('turbolinks:load', dash_ready) diff --git a/app/assets/stylesheets/admin/dashboard.scss b/app/assets/stylesheets/admin/dashboard.scss index 60c257a..44e13b3 100644 --- a/app/assets/stylesheets/admin/dashboard.scss +++ b/app/assets/stylesheets/admin/dashboard.scss @@ -40,3 +40,8 @@ } } } + +#action-box { + text-align: center; + margin: 1em 0; +} 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 diff --git a/app/views/admin/comments/pending.haml b/app/views/admin/comments/pending.haml index 3303457..5352b12 100644 --- a/app/views/admin/comments/pending.haml +++ b/app/views/admin/comments/pending.haml @@ -1,26 +1,32 @@ - title "Pending Comments" = will_paginate @comments -%table#entries - %tr - %th Text - %th Author - %th Blog post - %th Date updated - %th - - @comments.each do |comment| - %tr{ class: cycle("even", "odd") } - %td= comment.body - %td - %ul - %li= comment.username - %li= comment.email - - unless comment.website.empty? - %li= comment.website - %td= link_to comment.blog.title, comment.blog - %td= comment.created_at.strftime("%B %d, %Y, %l:%M%P") - %td - %ul.admin-actions - %li= link_to "Accept", accept_admin_comment_url(comment), method: :post, data: { confirm: "Are you sure you want to accept this comment?" } - %li= link_to "Reject", reject_admin_comment_url(comment), method: :post, data: { confirm: "Are you sure you want to reject this comment?" } - %li= link_to "Mark Spam", mark_spam_admin_comment_url(comment), method: :post, data: { confirm: "Are you sure you want to mark this comment as spam?" } += form_tag mass_admin_comments_url, method: :post do + #action-box + = select_tag "mass_action", options_for_select(["Delete", "Mark Spam"]), include_blank: true + = submit_tag "Mass action", data: { confirm: "Are you sure you want to do this action?" } + %table#entries + %tr + %th= check_box_tag "check_all" + %th Text + %th Author + %th Blog post + %th Date updated + %th + - @comments.each do |comment| + %tr{ class: cycle("even", "odd") } + %td= check_box_tag "comment_ids[]", comment.id, class: "comment_ids" + %td= comment.body + %td + %ul + %li= comment.username + %li= comment.email + - unless comment.website.empty? + %li= comment.website + %td= link_to comment.blog.title, comment.blog + %td= comment.created_at.strftime("%B %d, %Y, %l:%M%P") + %td + %ul.admin-actions + %li= link_to "Accept", accept_admin_comment_url(comment), method: :post, data: { confirm: "Are you sure you want to accept this comment?" } + %li= link_to "Reject", reject_admin_comment_url(comment), method: :post, data: { confirm: "Are you sure you want to reject this comment?" } + %li= link_to "Mark Spam", mark_spam_admin_comment_url(comment), method: :post, data: { confirm: "Are you sure you want to mark this comment as spam?" } = will_paginate @comments -- cgit 1.4.1