annotate .svn/pristine/e1/e11e4b4f0c5381a061b098e00586564872bd5c98.svn-base @ 929:5f33065ddc4b redmine-1.3

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