collab/app/models/user.rb

34 lines
1.0 KiB
Ruby
Raw Normal View History

2010-03-05 06:48:00 +00:00
class User < ActiveRecord::Base
include Clearance::User
has_and_belongs_to_many :projects
has_many :owned_projects, :class_name => "Project", :foreign_key => "owner_id"
has_many :owned_tasks, :class_name => "Task", :foreign_key => "owner_id"
has_many :assigned_tasks, :class_name => "Task", :foreign_key => "assigned_id"
validates_uniqueness_of :short_name
2010-03-15 15:47:32 +00:00
validates_presence_of :email, :password, :short_name
2010-03-05 06:48:00 +00:00
validates_format_of :phone, :with => /^[0-9]{3}-[0-9]{3}-[0-9]{4}$/, :if => Proc.new {|user| !user.phone.blank?}
validates_format_of :mobile, :with => /^[0-9]{3}-[0-9]{3}-[0-9]{4}$/, :if => Proc.new {|user| !user.mobile.blank?}
2010-03-15 15:47:32 +00:00
before_validation :set_short_name
def set_short_name
if short_name.blank?
short_name = email.split('@')[0]
end
end
2010-03-05 06:48:00 +00:00
def gravatar(size = 48)
hash = Digest::MD5.hexdigest email
"http://www.gravatar.com/avatar/#{hash}.jpg?s=#{size}"
end
2010-03-15 15:47:32 +00:00
def send_post_notification(post)
project_id = post.project_id
end
def send_project_notification(project)
end
2010-03-05 06:48:00 +00:00
end