about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/admin/comments_controller.rb23
-rw-r--r--app/controllers/comments_controller.rb7
-rw-r--r--app/views/admin/comments/pending.haml1
-rw-r--r--config/routes.rb1
-rw-r--r--db/migrate/20231017153558_add_more_comment_columns.rb9
-rw-r--r--db/schema.rb5
6 files changed, 43 insertions, 3 deletions
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
31 redirect_to pending_admin_comments_url 31 redirect_to pending_admin_comments_url
32 end 32 end
33 33
34 def mark_spam
35 @comment = Comment.find(params[:id])
36
37 akismet_params = {
38 type: "comment",
39 text: @comment.body,
40 created_at: @comment.created_at,
41 author: @comment.username,
42 author_email: @comment.email,
43 author_url: @comment.website,
44 post_url: url_for(@comment.blog),
45 post_modified_at: @comment.blog.updated_at,
46 referrer: @comment.referrer
47 }
48
49 Akismet.spam @comment.request_ip, @comment.user_agent, akismet_params
50
51 @comment.destroy!
52
53 flash.notice = "Comment successfully marked as spam."
54 redirect_back pending_admin_comments_url
55 end
56
34 def destroy 57 def destroy
35 if Comment.destroy(params[:id]) 58 if Comment.destroy(params[:id])
36 flash.notice = "Comment successfully deleted." 59 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
6 raise ActiveRecord::RecordNotFound unless @blog.published 6 raise ActiveRecord::RecordNotFound unless @blog.published
7 7
8 @comment = @blog.comments.new(comment_params) 8 @comment = @blog.comments.new(comment_params)
9 @comment.request_ip = request.ip
10 @comment.user_agent = request.user_agent
11 @comment.referrer = request.referrer
9 12
10 unless @comment.valid? 13 unless @comment.valid?
11 flash.alert = "Error posting comment." 14 flash.alert = "Error posting comment."
@@ -23,11 +26,11 @@ class CommentsController < ApplicationController
23 author_url: @comment.website, 26 author_url: @comment.website,
24 post_url: url_for(@comment.blog), 27 post_url: url_for(@comment.blog),
25 post_modified_at: @comment.blog.updated_at, 28 post_modified_at: @comment.blog.updated_at,
26 referrer: request.referrer, 29 referrer: @comment.referrer,
27 env: request.env.slice(*akismet_vars) 30 env: request.env.slice(*akismet_vars)
28 } 31 }
29 32
30 is_spam, is_blatant = Akismet.check(request.ip, request.user_agent, akismet_params) 33 is_spam, is_blatant = Akismet.check(@comment.ip, @comment.user_agent, akismet_params)
31 34
32 if is_blatant 35 if is_blatant
33 # I am lying. 36 # I am lying.
diff --git a/app/views/admin/comments/pending.haml b/app/views/admin/comments/pending.haml index 18ae6c2..3303457 100644 --- a/app/views/admin/comments/pending.haml +++ b/app/views/admin/comments/pending.haml
@@ -22,4 +22,5 @@
22 %ul.admin-actions 22 %ul.admin-actions
23 %li= link_to "Accept", accept_admin_comment_url(comment), method: :post, data: { confirm: "Are you sure you want to accept this comment?" } 23 %li= link_to "Accept", accept_admin_comment_url(comment), method: :post, data: { confirm: "Are you sure you want to accept this comment?" }
24 %li= link_to "Reject", reject_admin_comment_url(comment), method: :post, data: { confirm: "Are you sure you want to reject this comment?" } 24 %li= link_to "Reject", reject_admin_comment_url(comment), method: :post, data: { confirm: "Are you sure you want to reject this comment?" }
25 %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?" }
25= will_paginate @comments 26= will_paginate @comments
diff --git a/config/routes.rb b/config/routes.rb index 4b68dc3..416e939 100644 --- a/config/routes.rb +++ b/config/routes.rb
@@ -24,6 +24,7 @@ Rails.application.routes.draw do
24 member do 24 member do
25 post 'accept' 25 post 'accept'
26 post 'reject' 26 post 'reject'
27 post 'mark_spam'
27 end 28 end
28 end 29 end
29 end 30 end
diff --git a/db/migrate/20231017153558_add_more_comment_columns.rb b/db/migrate/20231017153558_add_more_comment_columns.rb new file mode 100644 index 0000000..9ce3e07 --- /dev/null +++ b/db/migrate/20231017153558_add_more_comment_columns.rb
@@ -0,0 +1,9 @@
1class AddMoreCommentColumns < ActiveRecord::Migration[7.0]
2 def change
3 change_table :comments do |t|
4 t.string :request_ip
5 t.string :user_agent
6 t.string :referrer
7 end
8 end
9end
diff --git a/db/schema.rb b/db/schema.rb index edbb24e..3a9e111 100644 --- a/db/schema.rb +++ b/db/schema.rb
@@ -10,7 +10,7 @@
10# 10#
11# It's strongly recommended that you check this file into your version control system. 11# It's strongly recommended that you check this file into your version control system.
12 12
13ActiveRecord::Schema[7.0].define(version: 2023_10_14_194459) do 13ActiveRecord::Schema[7.0].define(version: 2023_10_17_153558) do
14 create_table "active_storage_attachments", force: :cascade do |t| 14 create_table "active_storage_attachments", force: :cascade do |t|
15 t.string "name", null: false 15 t.string "name", null: false
16 t.string "record_type", null: false 16 t.string "record_type", null: false
@@ -97,6 +97,9 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_14_194459) do
97 t.datetime "created_at", null: false 97 t.datetime "created_at", null: false
98 t.datetime "updated_at", null: false 98 t.datetime "updated_at", null: false
99 t.integer "reply_to_id" 99 t.integer "reply_to_id"
100 t.string "request_ip"
101 t.string "user_agent"
102 t.string "referrer"
100 t.index ["blog_id"], name: "index_comments_on_blog_id" 103 t.index ["blog_id"], name: "index_comments_on_blog_id"
101 t.index ["reply_to_id"], name: "index_comments_on_reply_to_id" 104 t.index ["reply_to_id"], name: "index_comments_on_reply_to_id"
102 end 105 end