Commit e66d26eee064e35d60190a48625f5809aa53eab4

Authored by Antonio Terceiro
1 parent 9688304f

Store origin IP address for every comment

I am also already adding a "spam" flag to the table, which we will use
next.

(ActionItem2309)
app/controllers/public/content_viewer_controller.rb
... ... @@ -111,6 +111,7 @@ class ContentViewerController < ApplicationController
111 111 def add_comment
112 112 @comment.author = user if logged_in?
113 113 @comment.article = @page
  114 + @comment.ip_address = request.remote_ip
114 115 if (pass_without_comment_captcha? || verify_recaptcha(:model => @comment, :message => _('Please type the words correctly'))) && @comment.save
115 116 @page.touch
116 117 @comment = nil # clear the comment form
... ...
db/migrate/20120307200651_add_ip_address_to_comment.rb 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +class AddIpAddressToComment < ActiveRecord::Migration
  2 + def self.up
  3 + add_column :comments, :ip_address, :string
  4 + add_column :comments, :spam, :boolean
  5 + end
  6 +
  7 + def self.down
  8 + remove_column :comments, :ip_address
  9 + remove_column :comments, :boolean
  10 + end
  11 +end
... ...
db/schema.rb
... ... @@ -9,7 +9,7 @@
9 9 #
10 10 # It's strongly recommended to check this file into your version control system.
11 11  
12   -ActiveRecord::Schema.define(:version => 20111004184104) do
  12 +ActiveRecord::Schema.define(:version => 20120307200651) do
13 13  
14 14 create_table "abuse_reports", :force => true do |t|
15 15 t.integer "reporter_id"
... ... @@ -204,6 +204,8 @@ ActiveRecord::Schema.define(:version =&gt; 20111004184104) do
204 204 t.string "email"
205 205 t.datetime "created_at"
206 206 t.integer "reply_of_id"
  207 + t.string "ip_address"
  208 + t.boolean "spam"
207 209 end
208 210  
209 211 create_table "contact_lists", :force => true do |t|
... ...
test/functional/content_viewer_controller_test.rb
... ... @@ -1370,4 +1370,13 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
1370 1370 post :view_page, :profile => profile.identifier, :page => ['test'], :comment => {:body => "Some comment...", :author => profile}, :confirm => 'true'
1371 1371 assert_not_nil assigns(:comment)
1372 1372 end
  1373 +
  1374 + should 'store IP address for comments' do
  1375 + page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text')
  1376 + @request.stubs(:remote_ip).returns('33.44.55.66')
  1377 + post :view_page, :profile => profile.identifier, :page => [ 'myarticle' ], :comment => { :title => 'title', :body => 'body', :name => "Spammer", :email => 'damn@spammer.com' }, :confirm => 'true'
  1378 + comment = Comment.last
  1379 + assert_equal '33.44.55.66', comment.ip_address
  1380 + end
  1381 +
1373 1382 end
... ...