]> source.dussan.org Git - redmine.git/commitdiff
User display format is now configurable in administration settings.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 25 Jan 2008 10:31:06 +0000 (10:31 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 25 Jan 2008 10:31:06 +0000 (10:31 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1103 e93f8b46-1217-0410-a6f0-8f06a7374b81

30 files changed:
app/controllers/settings_controller.rb
app/models/member.rb
app/models/setting.rb
app/models/user.rb
app/views/projects/settings/_members.rhtml
app/views/settings/_general.rhtml
config/settings.yml
lang/bg.yml
lang/cs.yml
lang/de.yml
lang/en.yml
lang/es.yml
lang/fi.yml
lang/fr.yml
lang/he.yml
lang/it.yml
lang/ja.yml
lang/ko.yml
lang/lt.yml
lang/nl.yml
lang/pl.yml
lang/pt-br.yml
lang/pt.yml
lang/ro.yml
lang/ru.yml
lang/sr.yml
lang/sv.yml
lang/zh-tw.yml
lang/zh.yml
test/unit/user_test.rb

index c5fae2a1699d1ea426fd61548bb7c3d372f25c74..c7c8751dd121964533a027b854715a81715bafad 100644 (file)
@@ -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
index 0d0540690b5095743c844d242111d923d6126451..b4617c22961aecf11fac767506e6da17b2fe5b53 100644 (file)
@@ -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]
index 46b6d76ce364a55752627b7a5496bde3ada98f47..185991d9bbf9b812185ee1205f318a9ef6bf5ac2 100644 (file)
@@ -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
index 906420ed44691cf92b9dbb02636b0e820ed764cf..22d66539d25e20cb337c64447a96a35558557ee7 100644 (file)
@@ -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
index 55dfde1ac664e6163651544dd010e0e1692061ca..ab22ac602fec018c0b30b3d8a1d3d85a9f8c7d33 100644 (file)
@@ -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? %>
 <table class="list">
index 514e62b59d2a8bbbef5fee72a089eb0a4ffa0eb5..548ebbfacbf03c8eb3375f9293914296db39ecb4 100644 (file)
@@ -20,6 +20,9 @@
 <p><label><%= l(:setting_time_format) %></label>
 <%= 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) %></p>
 
+<p><label><%= l(:setting_user_format) %></label>
+<%= select_tag 'settings[user_format]', options_for_select( @options[:user_format], Setting.user_format.to_s ) %></p>
+
 <p><label><%= l(:setting_attachment_max_size) %></label>
 <%= text_field_tag 'settings[attachment_max_size]', Setting.attachment_max_size, :size => 6 %> KB</p>
 
index 1360b55018a59a5ad6f90950378796f5a22a40ea..a45ae17cedd1c0107107f5dc7d0a040443003c61 100644 (file)
@@ -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:
index 00b20308b988182086542428a63fbfdd74a4c8eb..7aac092cb2bfe7143bcb8c1f845138ad73946eac 100644 (file)
@@ -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
index ab159c2c471b0c10d9d081054fdbc7f26d9b9af9..d6307babe4f8983710ca803b5b5f271046ce4291 100644 (file)
@@ -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
index 0c1ba3575a33c0f3afe1d582ab340e9f1abdcd8f..0cdf989bfdea3c4b9eb320dc96e2c0742ad80695 100644 (file)
@@ -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
index 32fd9926f91b6ec714308d5fdf04c7d83c992fad..534a4834e28bbdf35285fca559775661d501eaf7 100644 (file)
@@ -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
index ac3b34c194d61fb5ef156da5fabb64cd158bf52b..9023f2b6a893c626cfb14192a965038cb96d6e30 100644 (file)
@@ -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
index d70cf396a1048de4db3f1a33f2e808054957547c..5dbe5e8a5245c068c27b3d848da16a4aec7c7438 100644 (file)
@@ -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
index be93da9a18d86b3d8dab80b6d59627285736f39f..1c1e7b5c252f76d0ea35ab6c74a8de36081cc680 100644 (file)
@@ -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
index ad33316244068f7e6bbe4aaaf05151ccb0c4da20..9b274c58d456211e1d7aad59fba3d3f5e156f016 100644 (file)
@@ -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
index 3b31312116b97ce3f9d29da16ba8fbd32bffb091..5f07a2f2429932bf7e50956300f68f9a168bcc7d 100644 (file)
@@ -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
index 08423c824317381414fd6edf56fa3c3fc1ae875d..3266256c299b380fa24b17e80a01b7c4a4c4145e 100644 (file)
@@ -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
index 0b556840dbc91e4c53242891309c84e2b33ef847..7f93fe94a12ee743dba905bc887bf936bda9a3a8 100644 (file)
@@ -565,3 +565,4 @@ label_change_properties: 속성 변경
 label_general: 일반
 label_repository_plural: 저장소들
 label_associated_revisions: Associated revisions
+setting_user_format: Users display format
index 5e8273b91d23d5c5630b8d5e3970d238134435fd..51686f9ede62a9404686c06d50ee9ea379c6da22 100644 (file)
@@ -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
index f81247623a43be865ac1b18a28bd44c3ddd1dd70..dc413b058cdc73216637fe3e84e13a0a8793c431 100644 (file)
@@ -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
index ec7eec222c79fc4db20dcbcc978a3d64f85098b8..10b5cd0290745950223cc66845082048364a24b4 100644 (file)
@@ -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
index 629ca2c38bf3273e32744fd6d55a06e39ed181b2..b246cfd30a9c9e25575735289798aad9bd7be742 100644 (file)
@@ -565,3 +565,4 @@ label_change_properties: Change properties
 label_general: General\r
 label_repository_plural: Repositories\r
 label_associated_revisions: Associated revisions\r
+setting_user_format: Users display format\r
index 8add9b6eb29ed298e6e30a22c16fc13f827acdec..aa98d15a8ccf3a2e3a139e7c80235baca765a30f 100644 (file)
@@ -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
index b5413fdd42de399e7b2ce835d38a46676c061fc5..d9011c21ef4e510ab8e3c4ce34cd2ef5eccbaf8f 100644 (file)
@@ -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
index 6636ed56f7d1f4922f29d510d4020a89725f79f8..61ce067595e198c53b1ac2401094c577fe8e4722 100644 (file)
@@ -567,3 +567,4 @@ enumeration_doc_categories: Категории документов
 enumeration_activities: Действия (учет времени)
 
 error_can_t_load_default_data: "Конфигурация по умолчанию не была загружена: %s"
+setting_user_format: Users display format
index 0c64ee128dece4214e601cc76dcc2c42da921f70..71503be01faf1021b1f492b568b39d8be7be658f 100644 (file)
@@ -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
index ff199aba4f2b113c60543bc1a4adfd8fc38e4422..604590aff92efcb43aca1ec166187f4af67d8ead 100644 (file)
@@ -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
index 21d1e9ead9b5d125936105f857262ca61d72360b..08b9057fa6d17c9d01a6a11e890ce389681facc2 100644 (file)
@@ -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
index de7ec093ebe7b7faa502735226aa84403b17ca9c..469bfb0c5e7f778d029226e7f20f7082bd828f60 100644 (file)
@@ -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
index 9f58d278f1b89c8faf24a51a363b87dab2d9bf7b..845a34afd6658d6bcf95c11c5d544351e578db9b 100644 (file)
@@ -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