##// END OF EJS Templates
Sort users by their display names so that user dropdown lists are sorted alphabetically (#2015)....
Jean-Philippe Lang -
r2008:6a8be88ad613
parent child
Show More
@@ -0,0 +1,5
1 <?xml version="1.0" encoding="UTF-8"?>
2 <loadpath>
3 <pathentry path="" type="src"/>
4 <pathentry path="org.rubypeople.rdt.launching.RUBY_CONTAINER" type="con"/>
5 </loadpath>
@@ -0,0 +1,18
1 <?xml version="1.0" encoding="UTF-8"?>
2 <projectDescription>
3 <name>trunk_fixes</name>
4 <comment></comment>
5 <projects>
6 </projects>
7 <buildSpec>
8 <buildCommand>
9 <name>org.rubypeople.rdt.core.rubybuilder</name>
10 <arguments>
11 </arguments>
12 </buildCommand>
13 </buildSpec>
14 <natures>
15 <nature>org.rubypeople.rdt.core.rubynature</nature>
16 <nature>org.radrails.rails.core.railsnature</nature>
17 </natures>
18 </projectDescription>
@@ -0,0 +1,5
1 #Sun Nov 09 21:42:24 CET 2008
2 eclipse.preferences.version=1
3 encoding//app/helpers/ifpdf_helper.rb=UTF-8
4 encoding//test/fixtures/mail_handler=UTF-8
5 encoding/lang=UTF-8
@@ -71,6 +71,11 class User < ActiveRecord::Base
71 # update hashed_password if password was set
71 # update hashed_password if password was set
72 self.hashed_password = User.hash_password(self.password) if self.password
72 self.hashed_password = User.hash_password(self.password) if self.password
73 end
73 end
74
75 def reload(*args)
76 @name = nil
77 super
78 end
74
79
75 def self.active
80 def self.active
76 with_scope :find => { :conditions => [ "status = ?", STATUS_ACTIVE ] } do
81 with_scope :find => { :conditions => [ "status = ?", STATUS_ACTIVE ] } do
@@ -120,8 +125,7 class User < ActiveRecord::Base
120
125
121 # Return user's full name for display
126 # Return user's full name for display
122 def name(formatter = nil)
127 def name(formatter = nil)
123 f = USER_FORMATS[formatter || Setting.user_format] || USER_FORMATS[:firstname_lastname]
128 @name ||= eval('"' + (USER_FORMATS[formatter || Setting.user_format] || USER_FORMATS[:firstname_lastname]) + '"')
124 eval '"' + f + '"'
125 end
129 end
126
130
127 def active?
131 def active?
@@ -180,14 +184,9 class User < ActiveRecord::Base
180 token && (token.created_on > Setting.autologin.to_i.day.ago) && token.user.active? ? token.user : nil
184 token && (token.created_on > Setting.autologin.to_i.day.ago) && token.user.active? ? token.user : nil
181 end
185 end
182
186
187 # Sort users by their display names
183 def <=>(user)
188 def <=>(user)
184 if user.nil?
189 self.to_s.downcase <=> user.to_s.downcase
185 -1
186 elsif lastname.to_s.downcase == user.lastname.to_s.downcase
187 firstname.to_s.downcase <=> user.firstname.to_s.downcase
188 else
189 lastname.to_s.downcase <=> user.lastname.to_s.downcase
190 end
191 end
190 end
192
191
193 def to_s
192 def to_s
@@ -85,9 +85,9 class UserTest < Test::Unit::TestCase
85 def test_name_format
85 def test_name_format
86 assert_equal 'Smith, John', @jsmith.name(:lastname_coma_firstname)
86 assert_equal 'Smith, John', @jsmith.name(:lastname_coma_firstname)
87 Setting.user_format = :firstname_lastname
87 Setting.user_format = :firstname_lastname
88 assert_equal 'John Smith', @jsmith.name
88 assert_equal 'John Smith', @jsmith.reload.name
89 Setting.user_format = :username
89 Setting.user_format = :username
90 assert_equal 'jsmith', @jsmith.name
90 assert_equal 'jsmith', @jsmith.reload.name
91 end
91 end
92
92
93 def test_lock
93 def test_lock
General Comments 0
You need to be logged in to leave comments. Login now