diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb
index c5fae2a16..c7c8751dd 100644
--- a/app/controllers/settings_controller.rb
+++ b/app/controllers/settings_controller.rb
@@ -35,7 +35,10 @@ class SettingsController < ApplicationController
end
flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'edit', :tab => params[:tab]
+ return
end
+ @options = {}
+ @options[:user_format] = User::USER_FORMATS.keys.collect {|f| [User.current.name(f), f.to_s] }
end
def plugin
diff --git a/app/models/member.rb b/app/models/member.rb
index 0d0540690..b4617c229 100644
--- a/app/models/member.rb
+++ b/app/models/member.rb
@@ -31,6 +31,10 @@ class Member < ActiveRecord::Base
self.user.name
end
+ def <=>(member)
+ role == member.role ? (user <=> member.user) : (role <=> member.role)
+ end
+
def before_destroy
# remove category based auto assignments for this member
IssueCategory.update_all "assigned_to_id = NULL", ["project_id = ? AND assigned_to_id = ?", project.id, user.id]
diff --git a/app/models/setting.rb b/app/models/setting.rb
index 46b6d76ce..185991d9b 100644
--- a/app/models/setting.rb
+++ b/app/models/setting.rb
@@ -53,12 +53,13 @@ class Setting < ActiveRecord::Base
v = read_attribute(:value)
# Unserialize serialized settings
v = YAML::load(v) if @@available_settings[name]['serialized'] && v.is_a?(String)
+ v = v.to_sym if @@available_settings[name]['format'] == 'symbol' && !v.blank?
v
end
def value=(v)
v = v.to_yaml if v && @@available_settings[name]['serialized']
- write_attribute(:value, v)
+ write_attribute(:value, v.to_s)
end
# Returns the value of the setting named name
diff --git a/app/models/user.rb b/app/models/user.rb
index 906420ed4..22d66539d 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -23,6 +23,14 @@ class User < ActiveRecord::Base
STATUS_ACTIVE = 1
STATUS_REGISTERED = 2
STATUS_LOCKED = 3
+
+ USER_FORMATS = {
+ :firstname_lastname => '#{firstname} #{lastname}',
+ :firstname => '#{firstname}',
+ :lastname_firstname => '#{lastname} #{firstname}',
+ :lastname_coma_firstname => '#{lastname}, #{firstname}',
+ :username => '#{login}'
+ }
has_many :memberships, :class_name => 'Member', :include => [ :project, :role ], :conditions => "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}", :order => "#{Project.table_name}.name", :dependent => :delete_all
has_many :projects, :through => :memberships
@@ -107,8 +115,9 @@ class User < ActiveRecord::Base
end
# Return user's full name for display
- def name
- "#{firstname} #{lastname}"
+ def name(formatter = nil)
+ f = USER_FORMATS[formatter || Setting.user_format] || USER_FORMATS[:firstname_lastname]
+ eval '"' + f + '"'
end
def active?
@@ -164,7 +173,13 @@ class User < ActiveRecord::Base
end
def <=>(user)
- user.nil? ? -1 : (lastname == user.lastname ? firstname <=> user.firstname : lastname <=> user.lastname)
+ if user.nil?
+ -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
def to_s
diff --git a/app/views/projects/settings/_members.rhtml b/app/views/projects/settings/_members.rhtml
index 55dfde1ac..ab22ac602 100644
--- a/app/views/projects/settings/_members.rhtml
+++ b/app/views/projects/settings/_members.rhtml
@@ -1,8 +1,8 @@
<%= error_messages_for 'member' %>
<% roles = Role.find_all_givable %>
-<% users = User.find_active(:all) - @project.users %>
+<% users = User.find_active(:all).sort - @project.users %>
<% # members sorted by role position
- members = @project.members.find(:all, :include => [:role, :user]).sort{|x,y| x.role.position <=> y.role.position} %>
+ members = @project.members.find(:all, :include => [:role, :user]).sort %>
<% if members.any? %>
diff --git a/app/views/settings/_general.rhtml b/app/views/settings/_general.rhtml
index 514e62b59..548ebbfac 100644
--- a/app/views/settings/_general.rhtml
+++ b/app/views/settings/_general.rhtml
@@ -20,6 +20,9 @@
<%= select_tag 'settings[time_format]', options_for_select( [[l(:label_language_based), '']] + Setting::TIME_FORMATS.collect {|f| [Time.now.strftime(f), f]}, Setting.time_format) %>
+
+<%= select_tag 'settings[user_format]', options_for_select( @options[:user_format], Setting.user_format.to_s ) %>
+
<%= text_field_tag 'settings[attachment_max_size]', Setting.attachment_max_size, :size => 6 %> KB
diff --git a/config/settings.yml b/config/settings.yml
index 1360b5501..a45ae17ce 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -79,6 +79,9 @@ date_format:
default: ''
time_format:
default: ''
+user_format:
+ default: :firstname_lastname
+ format: symbol
cross_project_issue_relations:
default: 0
notified_events:
diff --git a/lang/bg.yml b/lang/bg.yml
index 00b20308b..7aac092cb 100644
--- a/lang/bg.yml
+++ b/lang/bg.yml
@@ -565,3 +565,4 @@ label_change_properties: Change properties
label_general: General
label_repository_plural: Repositories
label_associated_revisions: Associated revisions
+setting_user_format: Users display format
diff --git a/lang/cs.yml b/lang/cs.yml
index ab159c2c4..d6307babe 100644
--- a/lang/cs.yml
+++ b/lang/cs.yml
@@ -565,3 +565,4 @@ label_change_properties: Change properties
label_general: General
label_repository_plural: Repositories
label_associated_revisions: Associated revisions
+setting_user_format: Users display format
diff --git a/lang/de.yml b/lang/de.yml
index 0c1ba3575..0cdf989bf 100644
--- a/lang/de.yml
+++ b/lang/de.yml
@@ -565,3 +565,4 @@ label_change_properties: Change properties
label_general: General
label_repository_plural: Repositories
label_associated_revisions: Associated revisions
+setting_user_format: Users display format
diff --git a/lang/en.yml b/lang/en.yml
index 32fd9926f..534a4834e 100644
--- a/lang/en.yml
+++ b/lang/en.yml
@@ -204,6 +204,7 @@ setting_repositories_encodings: Repositories encodings
setting_emails_footer: Emails footer
setting_protocol: Protocol
setting_per_page_options: Objects per page options
+setting_user_format: Users display format
label_user: User
label_user_plural: Users
diff --git a/lang/es.yml b/lang/es.yml
index ac3b34c19..9023f2b6a 100644
--- a/lang/es.yml
+++ b/lang/es.yml
@@ -568,3 +568,4 @@ label_change_properties: Change properties
label_general: General
label_repository_plural: Repositories
label_associated_revisions: Associated revisions
+setting_user_format: Users display format
diff --git a/lang/fi.yml b/lang/fi.yml
index d70cf396a..5dbe5e8a5 100644
--- a/lang/fi.yml
+++ b/lang/fi.yml
@@ -569,3 +569,4 @@ enumeration_issue_priorities: Tapahtuman prioriteetit
enumeration_doc_categories: Dokumentin luokat
enumeration_activities: Aktiviteetit (ajan seuranta)
label_associated_revisions: Liittyvät versiot
+setting_user_format: Users display format
diff --git a/lang/fr.yml b/lang/fr.yml
index be93da9a1..1c1e7b5c2 100644
--- a/lang/fr.yml
+++ b/lang/fr.yml
@@ -205,6 +205,7 @@ setting_repositories_encodings: Encodages des dépôts
setting_emails_footer: Pied-de-page des emails
setting_protocol: Protocole
setting_per_page_options: Options d'objets affichés par page
+setting_user_format: Format d'affichage des utilisateurs
label_user: Utilisateur
label_user_plural: Utilisateurs
diff --git a/lang/he.yml b/lang/he.yml
index ad3331624..9b274c58d 100644
--- a/lang/he.yml
+++ b/lang/he.yml
@@ -565,3 +565,4 @@ label_change_properties: Change properties
label_general: General
label_repository_plural: Repositories
label_associated_revisions: Associated revisions
+setting_user_format: Users display format
diff --git a/lang/it.yml b/lang/it.yml
index 3b3131211..5f07a2f24 100644
--- a/lang/it.yml
+++ b/lang/it.yml
@@ -565,3 +565,4 @@ label_change_properties: Change properties
label_general: General
label_repository_plural: Repositories
label_associated_revisions: Associated revisions
+setting_user_format: Users display format
diff --git a/lang/ja.yml b/lang/ja.yml
index 08423c824..3266256c2 100644
--- a/lang/ja.yml
+++ b/lang/ja.yml
@@ -566,3 +566,4 @@ label_change_properties: Change properties
label_general: General
label_repository_plural: Repositories
label_associated_revisions: Associated revisions
+setting_user_format: Users display format
diff --git a/lang/ko.yml b/lang/ko.yml
index 0b556840d..7f93fe94a 100644
--- a/lang/ko.yml
+++ b/lang/ko.yml
@@ -565,3 +565,4 @@ label_change_properties: 속성 변경
label_general: 일반
label_repository_plural: 저장소들
label_associated_revisions: Associated revisions
+setting_user_format: Users display format
diff --git a/lang/lt.yml b/lang/lt.yml
index 5e8273b91..51686f9ed 100644
--- a/lang/lt.yml
+++ b/lang/lt.yml
@@ -566,3 +566,4 @@ text_no_configuration_data: "Roles, trackers, issue statuses and workflow have n
label_repository_plural: Repositories
error_can_t_load_default_data: "Default configuration could not be loaded: %s"
label_associated_revisions: Associated revisions
+setting_user_format: Users display format
diff --git a/lang/nl.yml b/lang/nl.yml
index f81247623..dc413b058 100644
--- a/lang/nl.yml
+++ b/lang/nl.yml
@@ -566,3 +566,4 @@ label_change_properties: Change properties
label_general: General
label_repository_plural: Repositories
label_associated_revisions: Associated revisions
+setting_user_format: Users display format
diff --git a/lang/pl.yml b/lang/pl.yml
index ec7eec222..10b5cd029 100644
--- a/lang/pl.yml
+++ b/lang/pl.yml
@@ -565,3 +565,4 @@ label_change_properties: Zmień właściwości
label_general: Ogólne
label_repository_plural: Repozytoria
label_associated_revisions: Associated revisions
+setting_user_format: Users display format
diff --git a/lang/pt-br.yml b/lang/pt-br.yml
index 629ca2c38..b246cfd30 100644
--- a/lang/pt-br.yml
+++ b/lang/pt-br.yml
@@ -565,3 +565,4 @@ label_change_properties: Change properties
label_general: General
label_repository_plural: Repositories
label_associated_revisions: Associated revisions
+setting_user_format: Users display format
diff --git a/lang/pt.yml b/lang/pt.yml
index 8add9b6eb..aa98d15a8 100644
--- a/lang/pt.yml
+++ b/lang/pt.yml
@@ -565,3 +565,4 @@ label_change_properties: Change properties
label_general: General
label_repository_plural: Repositories
label_associated_revisions: Associated revisions
+setting_user_format: Users display format
diff --git a/lang/ro.yml b/lang/ro.yml
index b5413fdd4..d9011c21e 100644
--- a/lang/ro.yml
+++ b/lang/ro.yml
@@ -565,3 +565,4 @@ label_change_properties: Change properties
label_general: General
label_repository_plural: Repositories
label_associated_revisions: Associated revisions
+setting_user_format: Users display format
diff --git a/lang/ru.yml b/lang/ru.yml
index 6636ed56f..61ce06759 100644
--- a/lang/ru.yml
+++ b/lang/ru.yml
@@ -567,3 +567,4 @@ enumeration_doc_categories: Категории документов
enumeration_activities: Действия (учет времени)
error_can_t_load_default_data: "Конфигурация по умолчанию не была загружена: %s"
+setting_user_format: Users display format
diff --git a/lang/sr.yml b/lang/sr.yml
index 0c64ee128..71503be01 100644
--- a/lang/sr.yml
+++ b/lang/sr.yml
@@ -566,3 +566,4 @@ label_change_properties: Change properties
label_general: General
label_repository_plural: Repositories
label_associated_revisions: Associated revisions
+setting_user_format: Users display format
diff --git a/lang/sv.yml b/lang/sv.yml
index ff199aba4..604590aff 100644
--- a/lang/sv.yml
+++ b/lang/sv.yml
@@ -566,3 +566,4 @@ label_change_properties: Change properties
label_general: General
label_repository_plural: Repositories
label_associated_revisions: Associated revisions
+setting_user_format: Users display format
diff --git a/lang/zh-tw.yml b/lang/zh-tw.yml
index 21d1e9ead..08b9057fa 100644
--- a/lang/zh-tw.yml
+++ b/lang/zh-tw.yml
@@ -566,3 +566,4 @@ enumeration_issue_priorities: 項目重要性
enumeration_doc_categories: 文件分類
enumeration_activities: 活動 (time tracking)
label_associated_revisions: Associated revisions
+setting_user_format: Users display format
diff --git a/lang/zh.yml b/lang/zh.yml
index de7ec093e..469bfb0c5 100644
--- a/lang/zh.yml
+++ b/lang/zh.yml
@@ -568,3 +568,4 @@ label_change_properties: Change properties
label_general: General
label_repository_plural: Repositories
label_associated_revisions: Associated revisions
+setting_user_format: Users display format
diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb
index 9f58d278f..845a34afd 100644
--- a/test/unit/user_test.rb
+++ b/test/unit/user_test.rb
@@ -76,6 +76,14 @@ class UserTest < Test::Unit::TestCase
assert_equal User.hash_password("hello"), user.hashed_password
end
+ def test_name_format
+ assert_equal 'Smith, John', @jsmith.name(:lastname_coma_firstname)
+ Setting.user_format = :firstname_lastname
+ assert_equal 'John Smith', @jsmith.name
+ Setting.user_format = :username
+ assert_equal 'jsmith', @jsmith.name
+ end
+
def test_lock
user = User.try_to_login("jsmith", "jsmith")
assert_equal @jsmith, user