Project

General

Profile

Patch #23417 » 3.4.0_make_id_column_configurable_v4.patch

Marius BĂLTEANU, 2016-11-19 09:14

View differences:

app/models/issue_query.rb
21 21
  self.view_permission = :view_issues
22 22

  
23 23
  self.available_columns = [
24
    QueryColumn.new(:id, :sortable => "#{Issue.table_name}.id", :default_order => 'desc', :caption => '#', :frozen => true),
24
    QueryColumn.new(:id, :sortable => "#{Issue.table_name}.id", :default_order => 'desc', :caption => '#'),
25 25
    QueryColumn.new(:project, :sortable => "#{Project.table_name}.name", :groupable => true),
26 26
    QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position", :groupable => true),
27 27
    QueryColumn.new(:parent, :sortable => ["#{Issue.table_name}.root_id", "#{Issue.table_name}.lft ASC"], :default_order => 'desc', :caption => :field_parent_issue),
config/settings.yml
193 193
issue_list_default_columns:
194 194
  serialized: true
195 195
  default:
196
  - id
196 197
  - tracker
197 198
  - status
198 199
  - priority
db/migrate/20160712091212_add_id_to_default_issue_list_columns.rb
1
class AddIdToDefaultIssueListColumns < ActiveRecord::Migration
2
  def self.up
3
    columns = Setting.issue_list_default_columns
4
    return if columns.include?("id")
5

  
6
    columns.unshift "id"
7
    Setting.set_from_params("issue_list_default_columns", columns)
8
  end
9
  def down
10
    columns = Setting.issue_list_default_columns
11
    return unless columns.include?("id")
12

  
13
    columns -= ["id"]
14
    Setting.set_from_params("issue_list_default_columns", columns)
15
  end
16
end
test/functional/issues_controller_test.rb
217 217
      :f => [filter_name],
218 218
      :op => {filter_name => '='},
219 219
      :v => {filter_name => ['Foo']},
220
      :c => ['project']
220
      :c => ['id', 'project']
221 221
    assert_response :success
222 222

  
223 223
    assert_equal [3, 5], issues_in_list.map(&:project_id).uniq.sort
......
455 455
    assert_response :success
456 456

  
457 457
    assert_equal 'text/csv; header=present', @response.content_type
458
    assert response.body.starts_with?("#,")
458
    assert response.body.starts_with?("Project,")
459 459
    lines = response.body.chomp.split("\n")
460
    # default columns + id and project
461
    assert_equal Setting.issue_list_default_columns.size + 2, lines[0].split(',').size
460
    # default columns + project
461
    assert_equal Setting.issue_list_default_columns.size + 1, lines[0].split(',').size
462 462
  end
463 463

  
464 464
  def test_index_csv_with_project
......
495 495
    issue = Issue.create!(:project_id => 1, :tracker_id => 1, :subject => 'test_index_csv_with_spent_time_column', :author_id => 2)
496 496
    TimeEntry.create!(:project => issue.project, :issue => issue, :hours => 7.33, :user => User.find(2), :spent_on => Date.today)
497 497

  
498
    get :index, :format => 'csv', :set_filter => '1', :c => %w(subject spent_hours)
498
    get :index, :format => 'csv', :set_filter => '1', :c => %w(id subject spent_hours)
499 499
    assert_response :success
500 500
    assert_equal 'text/csv; header=present', @response.content_type
501 501
    lines = @response.body.chomp.split("\n")
......
549 549
    child = Issue.generate!(:parent_issue_id => parent.id)
550 550

  
551 551
    with_settings :default_language => 'en' do
552
      get :index, :format => 'csv', :c => %w(parent)
552
      get :index, :format => 'csv', :c => %w(id parent)
553 553
    end
554 554
    lines = response.body.split("\n")
555 555
    assert_include "#{child.id},#{parent.id}", lines
......
561 561
      str_big5  = "\xa4@\xa4\xeb".force_encoding('Big5')
562 562
      issue = Issue.generate!(:subject => str_utf8)
563 563

  
564
      get :index, :project_id => 1, 
565
                  :f => ['subject'], 
564
      get :index, :project_id => 1,
565
                  :f => ['subject'],
566 566
                  :op => '=', :values => [str_utf8],
567 567
                  :format => 'csv'
568 568
      assert_equal 'text/csv; header=present', @response.content_type
......
580 580
      str_utf8  = "\xe4\xbb\xa5\xe5\x86\x85".force_encoding('UTF-8')
581 581
      issue = Issue.generate!(:subject => str_utf8)
582 582

  
583
      get :index, :project_id => 1, 
584
                  :f => ['subject'], 
583
      get :index, :project_id => 1,
584
                  :f => ['subject'],
585 585
                  :op => '=', :values => [str_utf8],
586
                  :c => ['status', 'subject'],
586
                  :c => ['id', 'status', 'subject'],
587 587
                  :format => 'csv',
588 588
                  :set_filter => 1
589 589
      assert_equal 'text/csv; header=present', @response.content_type
......
603 603
      str1  = "test_index_csv_tw"
604 604
      issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
605 605

  
606
      get :index, :project_id => 1, 
607
                  :f => ['subject'], 
606
      get :index, :project_id => 1,
607
                  :f => ['subject'],
608 608
                  :op => '=', :values => [str1],
609
                  :c => ['estimated_hours', 'subject'],
609
                  :c => ['id', 'estimated_hours', 'subject'],
610 610
                  :format => 'csv',
611 611
                  :set_filter => 1
612 612
      assert_equal 'text/csv; header=present', @response.content_type
......
620 620
      str1  = "test_index_csv_fr"
621 621
      issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
622 622

  
623
      get :index, :project_id => 1, 
624
                  :f => ['subject'], 
623
      get :index, :project_id => 1,
624
                  :f => ['subject'],
625 625
                  :op => '=', :values => [str1],
626
                  :c => ['estimated_hours', 'subject'],
626
                  :c => ['id', 'estimated_hours', 'subject'],
627 627
                  :format => 'csv',
628 628
                  :set_filter => 1
629 629
      assert_equal 'text/csv; header=present', @response.content_type
......
696 696
      assert_response :success
697 697
    end
698 698
  end
699
  
699

  
700 700
  def test_index_sort_by_assigned_to
701 701
    get :index, :sort => 'assigned_to'
702 702
    assert_response :success
703
    
703

  
704 704
    assignees = issues_in_list.map(&:assigned_to).compact
705 705
    assert_equal assignees.sort, assignees
706 706
    assert_select 'table.issues.sort-by-assigned-to.sort-asc'
707 707
  end
708
  
708

  
709 709
  def test_index_sort_by_assigned_to_desc
710 710
    get :index, :sort => 'assigned_to:desc'
711 711
    assert_response :success
712
    
712

  
713 713
    assignees = issues_in_list.map(&:assigned_to).compact
714 714
    assert_equal assignees.sort.reverse, assignees
715 715
    assert_select 'table.issues.sort-by-assigned-to.sort-desc'
716 716
  end
717
  
717

  
718 718
  def test_index_group_by_assigned_to
719 719
    get :index, :group_by => 'assigned_to', :sort => 'priority'
720 720
    assert_response :success
721 721
  end
722
  
722

  
723 723
  def test_index_sort_by_author
724 724
    get :index, :sort => 'author', :c => ['author']
725 725
    assert_response :success
726
    
726

  
727 727
    authors = issues_in_list.map(&:author)
728 728
    assert_equal authors.sort, authors
729 729
  end
......
731 731
  def test_index_sort_by_author_desc
732 732
    get :index, :sort => 'author:desc'
733 733
    assert_response :success
734
    
734

  
735 735
    authors = issues_in_list.map(&:author)
736 736
    assert_equal authors.sort.reverse, authors
737 737
  end
738
  
738

  
739 739
  def test_index_group_by_author
740 740
    get :index, :group_by => 'author', :sort => 'priority'
741 741
    assert_response :success
742 742
  end
743
  
743

  
744 744
  def test_index_sort_by_spent_hours
745 745
    get :index, :sort => 'spent_hours:desc'
746 746
    assert_response :success
747 747
    hours = issues_in_list.map(&:spent_hours)
748 748
    assert_equal hours.sort.reverse, hours
749 749
  end
750
  
750

  
751 751
  def test_index_sort_by_total_spent_hours
752 752
    get :index, :sort => 'total_spent_hours:desc'
753 753
    assert_response :success
754 754
    hours = issues_in_list.map(&:total_spent_hours)
755 755
    assert_equal hours.sort.reverse, hours
756 756
  end
757
  
757

  
758 758
  def test_index_sort_by_total_estimated_hours
759 759
    get :index, :sort => 'total_estimated_hours:desc'
760 760
    assert_response :success
......
769 769
    CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
770 770
    CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
771 771

  
772
    get :index, :project_id => 1, :set_filter => 1, :sort => "cf_#{cf.id},id"
772
    get :index, :project_id => 1, :c => ["id"], :set_filter => 1, :sort => "cf_#{cf.id},id"
773 773
    assert_response :success
774 774

  
775 775
    assert_equal [2, 3, 1], issues_in_list.select {|issue| issue.custom_field_value(cf).present?}.map(&:id)
......
780 780
    get :index, :set_filter => 1, :c => columns
781 781
    assert_response :success
782 782

  
783
    # query should use specified columns + id and checkbox
784
    assert_select 'table.issues thead th', columns.size + 2
783
    # query should use specified columns + checkbox
784
    assert_select 'table.issues thead th', columns.size + 1
785 785

  
786 786
    # columns should be stored in session
787 787
    assert_kind_of Hash, session[:issue_query]
......
802 802
    end
803 803

  
804 804
    # query should use specified columns
805
    assert_equal ["#", "Project", "Tracker", "Subject", "Assignee"], columns_in_issues_list
805
    assert_equal ["Project", "Tracker", "Subject", "Assignee"], columns_in_issues_list
806 806
  end
807 807

  
808 808
  def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
......
820 820
    with_settings :issue_list_default_columns => columns do
821 821
      get :index, :project_id => 1, :set_filter => 1
822 822

  
823
      assert_equal ["#", "Assignee", "Subject", "Status", "Tracker"], columns_in_issues_list
823
      assert_equal ["Assignee", "Subject", "Status", "Tracker"], columns_in_issues_list
824 824
    end
825 825
  end
826 826

  
827 827
  def test_index_with_custom_field_column
828
    columns = %w(tracker subject cf_2)
828
    columns = %w(id tracker subject cf_2)
829 829
    get :index, :set_filter => 1, :c => columns
830 830
    assert_response :success
831 831

  
......
919 919
    IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(1), :issue_to => Issue.find(11))
920 920
    IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(12), :issue_to => Issue.find(2))
921 921

  
922
    get :index, :set_filter => 1, :c => %w(subject relations)
922
    get :index, :set_filter => 1, :c => %w(id subject relations)
923 923
    assert_response :success
924 924
    assert_select "tr#issue-1 td.relations" do
925 925
      assert_select "span", 3
......
935 935
      assert_select "span", 0
936 936
    end
937 937

  
938
    get :index, :set_filter => 1, :c => %w(relations), :format => 'csv'
938
    get :index, :set_filter => 1, :c => %w(id relations), :format => 'csv'
939 939
    assert_response :success
940 940
    assert_equal 'text/csv; header=present', response.content_type
941 941
    lines = response.body.chomp.split("\n")
......
943 943
    assert_include '2,Blocked by #12', lines
944 944
    assert_include '3,""', lines
945 945

  
946
    get :index, :set_filter => 1, :c => %w(subject relations), :format => 'pdf'
946
    get :index, :set_filter => 1, :c => %w(id subject relations), :format => 'pdf'
947 947
    assert_response :success
948 948
    assert_equal 'application/pdf', response.content_type
949 949
  end
......
951 951
  def test_index_with_description_column
952 952
    get :index, :set_filter => 1, :c => %w(subject description)
953 953

  
954
    assert_select 'table.issues thead th', 3 # columns: chekbox + id + subject
955
    assert_select 'td.description[colspan="3"]', :text => 'Unable to print recipes'
954
    assert_select 'table.issues thead th', 2 # columns: chekbox subject
955
    assert_select 'td.description[colspan="2"]', :text => 'Unable to print recipes'
956 956

  
957 957
    get :index, :set_filter => 1, :c => %w(subject description), :format => 'pdf'
958 958
    assert_response :success
......
1093 1093
  def test_index_should_not_include_new_issue_tab_for_project_without_trackers
1094 1094
    with_settings :new_item_menu_tab => '1' do
1095 1095
      Project.find(1).trackers.clear
1096
  
1096

  
1097 1097
      @request.session[:user_id] = 2
1098 1098
      get :index, :project_id => 1
1099 1099
      assert_select '#main-menu a.new-issue', 0
......
1105 1105
      role = Role.find(1)
1106 1106
      role.remove_permission! :add_issues
1107 1107
      role.add_permission! :copy_issues
1108
  
1108

  
1109 1109
      @request.session[:user_id] = 2
1110 1110
      get :index, :project_id => 1
1111 1111
      assert_select '#main-menu a.new-issue', 0
......
1614 1614
  end
1615 1615

  
1616 1616
  def test_show_export_to_pdf
1617
    issue = Issue.find(3) 
1617
    issue = Issue.find(3)
1618 1618
    assert issue.relations.select{|r| r.other_issue(issue).visible?}.present?
1619 1619
    get :show, :id => 3, :format => 'pdf'
1620 1620
    assert_response :success
......
2062 2062
    get :new, :project_id => 'invalid'
2063 2063
    assert_response 404
2064 2064
  end
2065
 
2065

  
2066 2066
  def test_new_with_parent_id_should_only_propose_valid_trackers
2067 2067
    @request.session[:user_id] = 2
2068 2068
    t = Tracker.find(3)
......
2611 2611
                              :custom_field_values => {'2' => 'Value for field 2'}}
2612 2612
      end
2613 2613
      assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
2614
  
2614

  
2615 2615
      assert_equal 1, ActionMailer::Base.deliveries.size
2616 2616
    end
2617 2617
  end
......
2885 2885
        assert_select 'option[value="1"][selected=selected]', :text => 'eCookbook'
2886 2886
        assert_select 'option[value="2"]:not([selected])', :text => 'OnlineStore'
2887 2887
      end
2888
      assert_select 'input[name=?][value=?]', 'issue[subject]', orig.subject 
2888
      assert_select 'input[name=?][value=?]', 'issue[subject]', orig.subject
2889 2889
      assert_select 'input[name=copy_from][value="1"]'
2890 2890
    end
2891 2891
  end
......
3180 3180
  def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
3181 3181
    @request.session[:user_id] = 2
3182 3182
    Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
3183
    
3183

  
3184 3184
    get :edit, :id => 1
3185 3185
    assert_select 'input[name=?]', 'time_entry[hours]'
3186 3186
  end
......
3188 3188
  def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
3189 3189
    @request.session[:user_id] = 2
3190 3190
    Role.find_by_name('Manager').remove_permission! :log_time
3191
    
3191

  
3192 3192
    get :edit, :id => 1
3193 3193
    assert_select 'input[name=?]', 'time_entry[hours]', 0
3194 3194
  end
......
3833 3833
    assert_response :redirect
3834 3834
    assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
3835 3835
  end
3836
 
3836

  
3837 3837
  def test_put_update_should_redirect_with_previous_and_next_issue_ids_params
3838 3838
    @request.session[:user_id] = 2
3839 3839

  
......
3887 3887

  
3888 3888
      assert_select 'select[name=?]', 'issue[project_id]'
3889 3889
      assert_select 'input[name=?]', 'issue[parent_issue_id]'
3890
  
3890

  
3891 3891
      # Project specific custom field, date type
3892 3892
      field = CustomField.find(9)
3893 3893
      assert !field.is_for_all?
3894 3894
      assert_equal 'date', field.field_format
3895 3895
      assert_select 'input[name=?]', 'issue[custom_field_values][9]'
3896
  
3896

  
3897 3897
      # System wide custom field
3898 3898
      assert CustomField.find(1).is_for_all?
3899 3899
      assert_select 'select[name=?]', 'issue[custom_field_values][1]'
3900
  
3900

  
3901 3901
      # Be sure we don't display inactive IssuePriorities
3902 3902
      assert ! IssuePriority.find(15).active?
3903 3903
      assert_select 'select[name=?]', 'issue[priority_id]' do
......
4084 4084
                                       :issue => {:priority_id => '',
4085 4085
                                                  :assigned_to_id => group.id,
4086 4086
                                                  :custom_field_values => {'2' => ''}}
4087
  
4087

  
4088 4088
      assert_response 302
4089 4089
      assert_equal [group, group], Issue.where(:id => [1, 2]).collect {|i| i.assigned_to}
4090 4090
    end
......
4390 4390
      assert_select 'option[value="2"]'
4391 4391
    end
4392 4392
  end
4393
  
4393

  
4394 4394
  def test_bulk_copy_to_another_project
4395 4395
    @request.session[:user_id] = 2
4396 4396
    assert_difference 'Issue.count', 2 do
......
4443 4443
                    :assigned_to_id => 3)
4444 4444
    ]
4445 4445
    assert_difference 'Issue.count', issues.size do
4446
      post :bulk_update, :ids => issues.map(&:id), :copy => '1', 
4446
      post :bulk_update, :ids => issues.map(&:id), :copy => '1',
4447 4447
           :issue => {
4448 4448
             :project_id => '', :tracker_id => '', :assigned_to_id => '',
4449 4449
             :status_id => '', :start_date => '', :due_date => ''
......
4471 4471
    @request.session[:user_id] = 2
4472 4472
    assert_difference 'Issue.count', 2 do
4473 4473
      assert_no_difference 'Project.find(1).issues.count' do
4474
        post :bulk_update, :ids => [1, 2], :copy => '1', 
4474
        post :bulk_update, :ids => [1, 2], :copy => '1',
4475 4475
             :issue => {
4476 4476
               :project_id => '2', :tracker_id => '', :assigned_to_id => '2',
4477 4477
               :status_id => '1', :start_date => '2009-12-01', :due_date => '2009-12-31'
test/functional/issues_custom_fields_visibility_test.rb
206 206
    Issue.generate!(:project => p1, :tracker_id => 1, :custom_field_values => {@field2.id => 'ValueC'})
207 207

  
208 208
    @request.session[:user_id] = user.id
209
    get :index, :c => ["subject", "cf_#{@field2.id}"]
209
    get :index, :c => ["id", "subject", "cf_#{@field2.id}"]
210 210
    assert_select 'td', :text => 'ValueA'
211 211
    assert_select 'td', :text => 'ValueB', :count => 0
212 212
    assert_select 'td', :text => 'ValueC'
test/functional/queries_controller_test.rb
122 122
         :operators => {"assigned_to_id" => "=", "status_id" => "o"},
123 123
         :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]},
124 124
         :query => {"name" => "test_new_global_private_query", "visibility" => "0"},
125
         :c => ["", "tracker", "subject", "priority", "category"]
125
         :c => ["", "id", "tracker", "subject", "priority", "category"]
126 126

  
127 127
    q = Query.find_by_name('test_new_global_private_query')
128 128
    assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q
test/unit/query_test.rb
1075 1075

  
1076 1076
  def test_set_column_names
1077 1077
    q = IssueQuery.new
1078
    q.column_names = ['tracker', :subject, '', 'unknonw_column']
1078
    q.column_names = ['id', 'tracker', :subject, '', 'unknonw_column']
1079 1079
    assert_equal [:id, :tracker, :subject], q.columns.collect {|c| c.name}
1080 1080
  end
1081 1081

  
......
1101 1101

  
1102 1102
  def test_inline_and_block_columns
1103 1103
    q = IssueQuery.new
1104
    q.column_names = ['subject', 'description', 'tracker']
1104
    q.column_names = ['id', 'subject', 'description', 'tracker']
1105 1105

  
1106 1106
    assert_equal [:id, :subject, :tracker], q.inline_columns.map(&:name)
1107 1107
    assert_equal [:description], q.block_columns.map(&:name)
(5-5/5)