Diff
Modified: trunk/Rakefile (3033 => 3034)
--- trunk/Rakefile 2012-06-17 07:15:14 UTC (rev 3033)
+++ trunk/Rakefile 2012-06-18 09:50:17 UTC (rev 3034)
@@ -192,3 +192,34 @@
puts doc.to_s
end
+desc 'Perform spam analysis on user profiles'
+task "myexp:spam:run" do
+ require File.dirname(__FILE__) + '/config/environment'
+
+ conditions = [[]]
+
+ if ENV['FROM']
+ conditions[0] << 'users.id >= ?'
+ conditions << ENV['FROM']
+ end
+
+ if ENV['TO']
+ conditions[0] << 'users.id <= ?'
+ conditions << ENV['TO']
+ end
+
+ if conditions[0].empty?
+ conditions = nil
+ else
+ conditions[0] = conditions[0].join(" AND ")
+ end
+
+ User.find(:all, :conditions => conditions).each do |user|
+ user.calculate_spam_score
+
+ if user.save == false
+ puts "Unable to save user #{user.id} (spam score = #{user.spam_score})"
+ end
+ end
+end
+
Modified: trunk/app/controllers/users_controller.rb (3033 => 3034)
--- trunk/app/controllers/users_controller.rb 2012-06-17 07:15:14 UTC (rev 3033)
+++ trunk/app/controllers/users_controller.rb 2012-06-18 09:50:17 UTC (rev 3034)
@@ -380,7 +380,7 @@
# For simile timeline
def users_for_timeline
- @users = User.find(:all, :conditions => [ "users.activated_at IS NOT NULL AND users.created_at > ? AND users.created_at < ?", params[:start].to_time, params[:end].to_time ], :include => [ :profile ] )
+ @users = User.find(:all, :conditions => [ "users.activated_at IS NOT NULL AND users.spam_score < 50 AND users.created_at < ?", params[:start].to_time, params[:end].to_time ], :include => [ :profile ] )
respond_to do |format|
format.json { render :partial => 'users/timeline_json', :layout => false }
end
@@ -687,6 +687,8 @@
user.update_attributes(:account_status => "whitelist")
when "sleep"
user.update_attributes(:account_status => "sleep")
+ when "hide"
+ user.update_attributes(:account_status => "hide")
when "delete"
# build an "all elements" user.xml record
Modified: trunk/app/models/user.rb (3033 => 3034)
--- trunk/app/models/user.rb 2012-06-17 07:15:14 UTC (rev 3033)
+++ trunk/app/models/user.rb 2012-06-18 09:50:17 UTC (rev 3034)
@@ -160,7 +160,12 @@
# Activate user if not previously activated
unless self.activated?
self.activated_at = Time.now
- self.account_status = "sleep"
+
+ if probable_spammer?
+ self.account_status = "hide"
+ else
+ self.account_status = "sleep"
+ end
end
return self.save
@@ -599,6 +604,23 @@
Digest::SHA1.hexdigest(unconfirmed_email + Conf.secret_word)
end
+ def calculate_spam_score
+
+ score = 0
+
+ patterns = Conf.spam_patterns
+
+ patterns["email"].each do |pattern|
+ if unconfirmed_email
+ score = score + 80 if unconfirmed_email.match(pattern)
+ elsif email
+ score = score + 80 if email.match(pattern)
+ end
+ end
+
+ self.spam_score = score
+ end
+
protected
# clean up emails and username before validation
Modified: trunk/app/views/users/check.rhtml (3033 => 3034)
--- trunk/app/views/users/check.rhtml 2012-06-17 07:15:14 UTC (rev 3033)
+++ trunk/app/views/users/check.rhtml 2012-06-18 09:50:17 UTC (rev 3034)
@@ -153,6 +153,11 @@
changeSelectedKSE("sleep");
break;
+ case 104: /* 'h' key */
+
+ changeSelectedKSE("hide");
+ break;
+
case 120: /* 'x' key */
changeSelectedKSE("delete");
@@ -209,6 +214,10 @@
<label for="" input_name -%>-sleep">Sleep</label>
</div>
<div>
+ <input name="<%= input_name -%>" id="<%= input_name -%>-hide" value="hide" type="radio" user[:ob].id -%>').className = 'hide';"/>
+ <label for="" input_name -%>-hide">Hide</label>
+ </div>
+ <div>
<input name="<%= input_name -%>" id="<%= input_name -%>-delete" value="delete" type="radio" user[:ob].id -%>').className = 'delete';"/>
<label for="" input_name -%>-delete">Delete</label>
</div>
Modified: trunk/config/default_settings.yml (3033 => 3034)
--- trunk/config/default_settings.yml 2012-06-17 07:15:14 UTC (rev 3033)
+++ trunk/config/default_settings.yml 2012-06-18 09:50:17 UTC (rev 3034)
@@ -516,3 +516,12 @@
deleted_data_directory: ""
+# spam_patterns - These patterns are used to automatically hide users from
+# particular views, e.g. the timeline as they are likely to be
+# used at a later point by spammers.
+
+spam_patterns:
+
+ email:
+ - "[0-9]{2,address@hidden"
+
Modified: trunk/lib/conf.rb (3033 => 3034)
--- trunk/lib/conf.rb 2012-06-17 07:15:14 UTC (rev 3033)
+++ trunk/lib/conf.rb 2012-06-18 09:50:17 UTC (rev 3034)
@@ -185,6 +185,10 @@
self.fetch_entry('deleted_data_directory')
end
+ def self.spam_patterns
+ self.fetch_entry('spam_patterns')
+ end
+
def self.layouts
layouts = self.fetch_entry('layouts', {})
layouts.delete_if {|k,v| v["environment"] && (v["environment"] != ENV["RAILS_ENV"])}
Modified: trunk/public/stylesheets/styles.css (3033 => 3034)
--- trunk/public/stylesheets/styles.css 2012-06-17 07:15:14 UTC (rev 3033)
+++ trunk/public/stylesheets/styles.css 2012-06-18 09:50:17 UTC (rev 3034)
@@ -2330,6 +2330,11 @@
background: #c0c0c0;
}
+#user-check-list .hide TD {
+ border: 1px solid #c0a080;
+ background: #ffe0c0;
+}
+
#user-check-list .delete TD {
border: 1px solid #c08080;
background: #ffc0c0;