annotate app/models/principal.rb @ 45:65d9e2cabaa3 luisf

Added tipoftheday to the config/settings in order to correct previous issues. Tip of the day is now working correctly. Added the heading strings to the locales files.
author luisf
date Tue, 23 Nov 2010 11:50:01 +0000
parents 40f7cfd4df19
children cbb26bc654de
rev   line source
Chris@0 1 # Redmine - project management software
Chris@0 2 # Copyright (C) 2006-2009 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@0 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@0 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@0 18 class Principal < ActiveRecord::Base
Chris@0 19 set_table_name "#{table_name_prefix}users#{table_name_suffix}"
Chris@0 20
Chris@0 21 has_many :members, :foreign_key => 'user_id', :dependent => :destroy
Chris@0 22 has_many :memberships, :class_name => 'Member', :foreign_key => 'user_id', :include => [ :project, :roles ], :conditions => "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}", :order => "#{Project.table_name}.name"
Chris@0 23 has_many :projects, :through => :memberships
Chris@0 24
Chris@0 25 # Groups and active users
Chris@0 26 named_scope :active, :conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status = 1)"
Chris@0 27
Chris@0 28 named_scope :like, lambda {|q|
Chris@0 29 s = "%#{q.to_s.strip.downcase}%"
Chris@0 30 {:conditions => ["LOWER(login) LIKE :s OR LOWER(firstname) LIKE :s OR LOWER(lastname) LIKE :s OR LOWER(mail) LIKE :s", {:s => s}],
Chris@0 31 :order => 'type, login, lastname, firstname, mail'
Chris@0 32 }
Chris@0 33 }
Chris@0 34
Chris@0 35 before_create :set_default_empty_values
chris@22 36
chris@22 37 def name(formatter = nil)
chris@22 38 to_s
chris@22 39 end
chris@22 40
Chris@0 41 def <=>(principal)
Chris@0 42 if self.class.name == principal.class.name
Chris@0 43 self.to_s.downcase <=> principal.to_s.downcase
Chris@0 44 else
Chris@0 45 # groups after users
Chris@0 46 principal.class.name <=> self.class.name
Chris@0 47 end
Chris@0 48 end
Chris@0 49
Chris@0 50 protected
Chris@0 51
Chris@0 52 # Make sure we don't try to insert NULL values (see #4632)
Chris@0 53 def set_default_empty_values
Chris@0 54 self.login ||= ''
Chris@0 55 self.hashed_password ||= ''
Chris@0 56 self.firstname ||= ''
Chris@0 57 self.lastname ||= ''
Chris@0 58 self.mail ||= ''
Chris@0 59 true
Chris@0 60 end
Chris@0 61 end