]> source.dussan.org Git - redmine.git/commitdiff
Allow project column to be removed from the global issue list columns (#8411).
authorEtienne Massip <etienne.massip@gmail.com>
Mon, 26 Sep 2011 17:44:20 +0000 (17:44 +0000)
committerEtienne Massip <etienne.massip@gmail.com>
Mon, 26 Sep 2011 17:44:20 +0000 (17:44 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7538 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/query.rb
test/functional/issues_controller_test.rb

index 7bf0b0d2fa0feea1817da1aa3a6cf5d2ccce0074..b717ecbc2166b16bba692267e5123adeae719621 100644 (file)
@@ -378,14 +378,17 @@ class Query < ActiveRecord::Base
   end
 
   def columns
-    if has_default_columns?
-      available_columns.select do |c|
-        # Adds the project column by default for cross-project lists
-        Setting.issue_list_default_columns.include?(c.name.to_s) || (c.name == :project && project.nil?)
-      end
-    else
-      # preserve the column_names order
-      column_names.collect {|name| available_columns.find {|col| col.name == name}}.compact
+    # preserve the column_names order
+    (has_default_columns? ? default_columns_names : column_names).collect do |name|
+       available_columns.find { |col| col.name == name }
+    end.compact
+  end
+
+  def default_columns_names
+    @default_columns_names ||= begin
+      default_columns = Setting.issue_list_default_columns.map(&:to_sym)
+
+      project.present? ? default_columns : [:project] | default_columns
     end
   end
 
@@ -394,7 +397,7 @@ class Query < ActiveRecord::Base
       names = names.select {|n| n.is_a?(Symbol) || !n.blank? }
       names = names.collect {|n| n.is_a?(Symbol) ? n : n.to_sym }
       # Set column_names to nil if default columns
-      if names.map(&:to_s) == Setting.issue_list_default_columns
+      if names == default_columns_names
         names = nil
       end
     end
index 3fde8cdaac750541a73fcecc3e75692161201900..1b79cc1c14d9fd373c46670fcab3ebf5f6c8e7b9 100644 (file)
@@ -285,6 +285,27 @@ class IssuesControllerTest < ActionController::TestCase
                                     :parent => { :tag => 'select', :attributes => { :id => "selected_columns" } }
   end
 
+  def test_index_without_project_should_implicitly_add_project_column_to_default_columns
+    Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
+    get :index, :set_filter => 1
+
+    # query should use specified columns
+    query = assigns(:query)
+    assert_kind_of Query, query
+    assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
+  end
+
+  def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
+    Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
+    columns = ['tracker', 'subject', 'assigned_to']
+    get :index, :set_filter => 1, :c => columns
+
+    # query should use specified columns
+    query = assigns(:query)
+    assert_kind_of Query, query
+    assert_equal columns.map(&:to_sym), query.columns.map(&:name)
+  end
+
   def test_index_with_custom_field_column
     columns = %w(tracker subject cf_2)
     get :index, :set_filter => 1, :c => columns