Permalink
Browse files

Comment feedback to mollom: report spam

  • Loading branch information...
1 parent 9ff7044 commit e3af43df9a895dfdce419f46efd8ee11baa74757 @franklouwers franklouwers committed Oct 3, 2008
Showing with 59 additions and 19 deletions.
  1. +27 −19 app/controllers/admin/comments_controller.rb
  2. +21 −0 app/models/comment.rb
  3. +11 −0 db/migrate/005_add_mollomid_column.rb
View
46 app/controllers/admin/comments_controller.rb
@@ -1,5 +1,5 @@
class Admin::CommentsController < ApplicationController
-
+
def index
conditions = case params[:status]
when "approved"
@@ -15,25 +15,25 @@ def index
else
@page.comments.paginate(:page => params[:page], :conditions => conditions)
end
-
+
respond_to do |format|
format.html
format.csv { render :text => @comments.to_csv }
end
end
-
+
def destroy
@comment = Comment.find(params[:id])
@comment.destroy
announce_comment_removed
ResponseCache.instance.expire_response(@comment.page.url)
redirect_to :back
end
-
+
def edit
@comment = Comment.find(params[:id])
end
-
+
def update
@comment = Comment.find(params[:id])
begin
@@ -48,36 +48,44 @@ def update
flash[:notice] = "There was an error saving the comment"
end
end
-
+
def enable
@page = Page.find(params[:page_id])
@page.enable_comments = 1
@page.save!
flash[:notice] = "Comments has been enabled for #{@page.title}"
redirect_to page_index_path
end
-
+
def approve
@comment = Comment.find(params[:id])
- @comment.approve!
+ begin
+ @comment.approve!
+ rescue Comment::AntispamWarning => e
+ antispamnotice = "The antispam engine gave a warning: #{e}<br />"
+ end
ResponseCache.instance.expire_response(@comment.page.url)
- flash[:notice] = "Comment was successfully approved on page #{@comment.page.title}"
+ flash[:notice] = "Comment was successfully approved on page #{@comment.page.title}" + (antispamnotice ? " (#{antispamnotice})" : "")
redirect_to :back
end
-
+
def unapprove
@comment = Comment.find(params[:id])
- @comment.unapprove!
+ begin
+ @comment.unapprove!
+ rescue Comment::AntispamWarning => e
+ antispamnotice = "The antispam engine gave a warning: #{e}"
+ end
ResponseCache.instance.expire_response(@comment.page.url)
- flash[:notice] = "Comment was successfully unapproved on page #{@comment.page.title}"
+ flash[:notice] = "Comment was successfully unapproved on page #{@comment.page.title}" + (antispamnotice ? " (#{antispamnotice})" : "" )
redirect_to :back
end
-
-
+
+
protected
-
- def announce_comment_removed
- flash[:notice] = "The comment was successfully removed from the site."
- end
-
+
+ def announce_comment_removed
+ flash[:notice] = "The comment was successfully removed from the site."
+ end
+
end
View
21 app/models/comment.rb
@@ -28,6 +28,7 @@ def save_mollom_servers
f.write mollom.server_list.to_yaml
end
end
+ rescue Mollom::Error
end
def mollom
@@ -63,10 +64,14 @@ def auto_approve?
:author_url => self.author_url, # author url
:post_body => self.content # comment text
)
+ ham = reponse.ham?
+ self.update_attibute(:mollom_id, response.session_id)
response.ham?
else
false
end
+ rescue Mollom::Error
+ return false
end
def unapproved?
@@ -83,6 +88,20 @@ def approve!
def unapprove!
self.update_attribute(:approved_at, nil)
+ # if we have to unapprove, and use mollom, it means
+ # the initial check was false. Submit this to mollom as Spam.
+ # Ideally, we'd need a different feedback for
+ # - spam
+ # - profanity
+ # - unwanted
+ # - low-quality
+ begin
+ if mollom.key_ok? and !self.mollom_id.empty?
+ mollom.send_feedback :session_id => self.mollom_id, :feedback => 'spam'
+ end
+ rescue Mollom::Error => e
+ raise Comment::AntispamWarning.new(e.to_s)
+ end
end
private
@@ -116,4 +135,6 @@ def filter(content)
simple_format(h(content))
end
end
+
+ class AntispamWarning < StandardError; end
end
View
11 db/migrate/005_add_mollomid_column.rb
@@ -0,0 +1,11 @@
+# rake production radiant:extensions:comments:migrate
+class AddMollomidColumn < ActiveRecord::Migration
+ def self.up
+ add_column :comments, :mollom_id, :string
+ end
+
+ def self.down
+ remove_column :comments, :mollom_id
+ end
+end
+

0 comments on commit e3af43d

Please sign in to comment.