From 8d039903f630db0b89f2df44a94f4e5c938bd7bf Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Tue, 17 Oct 2023 11:43:07 -0400 Subject: Added marking comments as spam --- app/controllers/admin/comments_controller.rb | 23 +++++++++++++++++++++++ app/controllers/comments_controller.rb | 7 +++++-- 2 files changed, 28 insertions(+), 2 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/admin/comments_controller.rb b/app/controllers/admin/comments_controller.rb index 9958232..d3d948c 100644 --- a/app/controllers/admin/comments_controller.rb +++ b/app/controllers/admin/comments_controller.rb @@ -31,6 +31,29 @@ class Admin::CommentsController < Admin::AdminController redirect_to pending_admin_comments_url end + 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! + + flash.notice = "Comment successfully marked as spam." + redirect_back pending_admin_comments_url + end + def destroy if Comment.destroy(params[:id]) flash.notice = "Comment successfully deleted." diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 2f3117f..9fa05e4 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -6,6 +6,9 @@ class CommentsController < ApplicationController raise ActiveRecord::RecordNotFound unless @blog.published @comment = @blog.comments.new(comment_params) + @comment.request_ip = request.ip + @comment.user_agent = request.user_agent + @comment.referrer = request.referrer unless @comment.valid? flash.alert = "Error posting comment." @@ -23,11 +26,11 @@ class CommentsController < ApplicationController author_url: @comment.website, post_url: url_for(@comment.blog), post_modified_at: @comment.blog.updated_at, - referrer: request.referrer, + referrer: @comment.referrer, env: request.env.slice(*akismet_vars) } - is_spam, is_blatant = Akismet.check(request.ip, request.user_agent, akismet_params) + is_spam, is_blatant = Akismet.check(@comment.ip, @comment.user_agent, akismet_params) if is_blatant # I am lying. -- cgit 1.4.1