Project

General

Profile

Defect #6244 » 0001-Fix-6244-Make-Issues-use-Setting.user_format.patch

Patch for defect 6244 -- respect Setting.user_format in Issues display - Steven Chanin, 2010-09-21 21:21

View differences:

app/models/query.rb
126 126
    QueryColumn.new(:priority, :sortable => "#{IssuePriority.table_name}.position", :default_order => 'desc', :groupable => true),
127 127
    QueryColumn.new(:subject, :sortable => "#{Issue.table_name}.subject"),
128 128
    QueryColumn.new(:author),
129
    QueryColumn.new(:assigned_to, :sortable => ["#{User.table_name}.lastname", "#{User.table_name}.firstname", "#{User.table_name}.id"], :groupable => true),
129
    QueryColumn.new(:assigned_to, :sortable => User::USER_SORT_FORMATS[:lastname_firstname], :groupable => true),
130 130
    QueryColumn.new(:updated_on, :sortable => "#{Issue.table_name}.updated_on", :default_order => 'desc'),
131 131
    QueryColumn.new(:category, :sortable => "#{IssueCategory.table_name}.name", :groupable => true),
132 132
    QueryColumn.new(:fixed_version, :sortable => ["#{Version.table_name}.effective_date", "#{Version.table_name}.name"], :default_order => 'desc', :groupable => true),
......
283 283
  def available_columns
284 284
    return @available_columns if @available_columns
285 285
    @available_columns = Query.available_columns
286

  
287
    #override Class variable values with :user_format from the database
288
    assigned_to_query_column = @available_columns.find {|col| col.is_a?(QueryColumn) && col.name == :assigned_to }
289
    assigned_to_query_column.sortable = User::USER_SORT_FORMATS[Setting.user_format] unless assigned_to_query_column.nil?
290
    
286 291
    @available_columns += (project ? 
287 292
                            project.all_issue_custom_fields :
288 293
                            IssueCustomField.find(:all)
app/models/user.rb
32 32
    :lastname_coma_firstname => '#{lastname}, #{firstname}',
33 33
    :username => '#{login}'
34 34
  }
35
  
36
  USER_SORT_FORMATS = {
37
    :firstname_lastname => ["#{User.table_name}.firstname", "#{User.table_name}.lastname", "#{User.table_name}.id"],
38
    :firstname => ["#{User.table_name}.firstname", "#{User.table_name}.id"],
39
    :lastname_firstname => ["#{User.table_name}.lastname", "#{User.table_name}.firstname", "#{User.table_name}.id"],
40
    :lastname_coma_firstname => ["#{User.table_name}.lastname", "#{User.table_name}.firstname", "#{User.table_name}.id"],
41
    :username => ["#{User.table_name}.login", "#{User.table_name}.id"]
42
  }
35 43

  
36 44
  has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)},
37 45
                                   :after_remove => Proc.new {|user, group| group.user_removed(user)}
test/unit/query_test.rb
303 303
    assert_equal values.sort, values
304 304
  end
305 305
  
306
  def test_sort_by_assignee_default
307
    q = Query.new
308
    c = q.available_columns.find {|col| col.is_a?(QueryColumn) && col.name == :assigned_to }
309
    
310
    assert c
311
    #since this test does not explicitly set Setting.user_format, it ultimately defaults back
312
    #to the value in config/settings.yml which is :firstname_lastname
313
    assert c.sortable == ["#{User.table_name}.firstname", "#{User.table_name}.lastname", "#{User.table_name}.id"]
314
  end
315
  
316
  def test_sort_by_assignee_username
317
    current_display_format = Setting.user_format
318
    assert current_display_format != :username
319
    
320
    Setting.user_format = :username
321
    
322
    q = Query.new
323
    c = q.available_columns.find {|col| col.is_a?(QueryColumn) && col.name == :assigned_to }
324
    
325
    assert c
326
    assert c.sortable == ["#{User.table_name}.login", "#{User.table_name}.id"]
327

  
328
    Setting.user_format = current_display_format
329
  end
330

  
306 331
  def test_invalid_query_should_raise_query_statement_invalid_error
307 332
    q = Query.new
308 333
    assert_raise Query::StatementInvalid do
(4-4/4)