X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/293265a00b468b9d69a261fc6029922c4d1848c8..0330e109437fdcb8fbfdd112492699607b507d4c:/app/models/user.rb diff --git a/app/models/user.rb b/app/models/user.rb index 08325d5b9..636f83424 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -8,6 +8,7 @@ class User < ActiveRecord::Base has_many :new_messages, :class_name => "Message", :foreign_key => :to_user_id, :conditions => { :to_user_visible => true, :message_read => false }, :order => 'sent_on DESC' has_many :sent_messages, :class_name => "Message", :foreign_key => :from_user_id, :conditions => { :from_user_visible => true }, :order => 'sent_on DESC' has_many :friends, :include => :befriendee, :conditions => "users.status IN ('active', 'confirmed')" + has_many :friend_users, :through => :friends, :source => :befriendee has_many :tokens, :class_name => "UserToken" has_many :preferences, :class_name => "UserPreference" has_many :changesets, :order => 'created_at DESC' @@ -20,6 +21,7 @@ class User < ActiveRecord::Base scope :visible, where(:status => ["pending", "active", "confirmed"]) scope :active, where(:status => ["active", "confirmed"]) + scope :public, where(:data_public => true) validates_presence_of :email, :display_name validates_confirmation_of :email#, :message => ' addresses must match' @@ -39,10 +41,15 @@ class User < ActiveRecord::Base validates_numericality_of :home_zoom, :only_integer => true, :allow_nil => true validates_inclusion_of :preferred_editor, :in => Editors::ALL_EDITORS, :allow_nil => true - after_initialize :set_creation_time + attr_accessible :display_name, :email, :email_confirmation, :openid_url, + :pass_crypt, :pass_crypt_confirmation, :consider_pd + + after_initialize :set_defaults before_save :encrypt_password - file_column :image, :magick => { :geometry => "100x100>" } + has_attached_file :image, + :default_url => "/assets/:class/:attachment/:style.png", + :styles => { :large => "100x100>", :small => "50x50>" } def self.authenticate(options) if options[:username] and options[:password] @@ -94,6 +101,10 @@ class User < ActiveRecord::Base return el1 end + def description + RichText.new(read_attribute(:description_format), read_attribute(:description)) + end + def languages attribute_present?(:languages) ? read_attribute(:languages).split(/ *, */) : [] end @@ -193,10 +204,10 @@ class User < ActiveRecord::Base def spam_score changeset_score = self.changesets.limit(10).length * 50 trace_score = self.traces.limit(10).length * 50 - diary_entry_score = self.diary_entries.inject(0) { |s,e| s += OSM.spam_score(e.body) } - diary_comment_score = self.diary_comments.inject(0) { |s,e| s += OSM.spam_score(e.body) } + diary_entry_score = self.diary_entries.inject(0) { |s,e| s += e.body.spam_score } + diary_comment_score = self.diary_comments.inject(0) { |s,c| s += c.body.spam_score } - score = OSM.spam_score(self.description) * 2 + score = self.description.spam_score / 4.0 score += diary_entry_score / self.diary_entries.length if self.diary_entries.length > 0 score += diary_comment_score / self.diary_comments.length if self.diary_comments.length > 0 score -= changeset_score @@ -213,8 +224,9 @@ class User < ActiveRecord::Base private - def set_creation_time + def set_defaults self.creation_time = Time.now.getutc unless self.attribute_present?(:creation_time) + self.description_format = "markdown" unless self.attribute_present?(:description_format) end def encrypt_password