Sort users by their display names so that user dropdown lists are sorted alphabetically (#2015).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2010 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2008-11-11 12:59:28 +00:00
parent e8d0c26e43
commit 6a8be88ad6
5 changed files with 38 additions and 11 deletions

5
.loadpath Normal file
View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<loadpath>
<pathentry path="" type="src"/>
<pathentry path="org.rubypeople.rdt.launching.RUBY_CONTAINER" type="con"/>
</loadpath>

18
.project Normal file
View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>trunk_fixes</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.rubypeople.rdt.core.rubybuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.rubypeople.rdt.core.rubynature</nature>
<nature>org.radrails.rails.core.railsnature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,5 @@
#Sun Nov 09 21:42:24 CET 2008
eclipse.preferences.version=1
encoding//app/helpers/ifpdf_helper.rb=UTF-8
encoding//test/fixtures/mail_handler=UTF-8
encoding/lang=UTF-8

View File

@ -72,6 +72,11 @@ class User < ActiveRecord::Base
self.hashed_password = User.hash_password(self.password) if self.password self.hashed_password = User.hash_password(self.password) if self.password
end end
def reload(*args)
@name = nil
super
end
def self.active def self.active
with_scope :find => { :conditions => [ "status = ?", STATUS_ACTIVE ] } do with_scope :find => { :conditions => [ "status = ?", STATUS_ACTIVE ] } do
yield yield
@ -120,8 +125,7 @@ class User < ActiveRecord::Base
# Return user's full name for display # Return user's full name for display
def name(formatter = nil) def name(formatter = nil)
f = USER_FORMATS[formatter || Setting.user_format] || USER_FORMATS[:firstname_lastname] @name ||= eval('"' + (USER_FORMATS[formatter || Setting.user_format] || USER_FORMATS[:firstname_lastname]) + '"')
eval '"' + f + '"'
end end
def active? def active?
@ -180,14 +184,9 @@ class User < ActiveRecord::Base
token && (token.created_on > Setting.autologin.to_i.day.ago) && token.user.active? ? token.user : nil token && (token.created_on > Setting.autologin.to_i.day.ago) && token.user.active? ? token.user : nil
end end
# Sort users by their display names
def <=>(user) def <=>(user)
if user.nil? self.to_s.downcase <=> user.to_s.downcase
-1
elsif lastname.to_s.downcase == user.lastname.to_s.downcase
firstname.to_s.downcase <=> user.firstname.to_s.downcase
else
lastname.to_s.downcase <=> user.lastname.to_s.downcase
end
end end
def to_s def to_s

View File

@ -85,9 +85,9 @@ class UserTest < Test::Unit::TestCase
def test_name_format def test_name_format
assert_equal 'Smith, John', @jsmith.name(:lastname_coma_firstname) assert_equal 'Smith, John', @jsmith.name(:lastname_coma_firstname)
Setting.user_format = :firstname_lastname Setting.user_format = :firstname_lastname
assert_equal 'John Smith', @jsmith.name assert_equal 'John Smith', @jsmith.reload.name
Setting.user_format = :username Setting.user_format = :username
assert_equal 'jsmith', @jsmith.name assert_equal 'jsmith', @jsmith.reload.name
end end
def test_lock def test_lock