]> source.dussan.org Git - redmine.git/commitdiff
Merged r15890 (#24014).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 9 Oct 2016 08:39:37 +0000 (08:39 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 9 Oct 2016 08:39:37 +0000 (08:39 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/3.3-stable@15893 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/time_entry_query.rb
test/unit/time_entry_query_test.rb

index a921f6d9399ceb5b17fa2f60b437de2194284d1f..148c657c09229dbfcd8327ecd8098198d80c4b51 100644 (file)
@@ -86,7 +86,9 @@ class TimeEntryQuery < Query
     add_available_filter "hours", :type => :float
 
     add_custom_fields_filters(TimeEntryCustomField)
-    add_associations_custom_fields_filters :project, :issue, :user
+    add_associations_custom_fields_filters :project
+    add_custom_fields_filters(issue_custom_fields, :issue)
+    add_associations_custom_fields_filters :user
   end
 
   def available_columns
@@ -94,7 +96,7 @@ class TimeEntryQuery < Query
     @available_columns = self.class.available_columns.dup
     @available_columns += TimeEntryCustomField.visible.
                             map {|cf| QueryCustomFieldColumn.new(cf) }
-    @available_columns += IssueCustomField.visible.
+    @available_columns += issue_custom_fields.visible.
                             map {|cf| QueryAssociationCustomFieldColumn.new(:issue, cf) }
     @available_columns
   end
@@ -138,4 +140,12 @@ class TimeEntryQuery < Query
     end
     self
   end
+
+  def issue_custom_fields
+    if project
+      project.all_issue_custom_fields
+    else
+      IssueCustomField.where(:is_for_all => true)
+    end
+  end
 end
index 9ca864f7208147390999d4e4b73340463d1fdce3..599aae52cff925ae27a5913d382837c93015f4e9 100644 (file)
@@ -54,4 +54,28 @@ class TimeEntryQueryTest < ActiveSupport::TestCase
     query.add_filter('activity_id', '!', [system.id.to_s])
     assert_equal 4.0, query.results_scope.sum(:hours)
   end
+
+  def test_project_query_should_include_project_issue_custom_fields_only_as_filters
+    global = IssueCustomField.generate!(:is_for_all => true, :is_filter => true)
+    field_on_project = IssueCustomField.generate!(:is_for_all => false, :project_ids => [3], :is_filter => true)
+    field_not_on_project = IssueCustomField.generate!(:is_for_all => false, :project_ids => [1,2], :is_filter => true)
+
+    query = TimeEntryQuery.new(:project => Project.find(3))
+
+    assert_include "issue.cf_#{global.id}", query.available_filters.keys
+    assert_include "issue.cf_#{field_on_project.id}", query.available_filters.keys
+    assert_not_include "issue.cf_#{field_not_on_project.id}", query.available_filters.keys
+  end
+
+  def test_project_query_should_include_project_issue_custom_fields_only_as_columns
+    global = IssueCustomField.generate!(:is_for_all => true, :is_filter => true)
+    field_on_project = IssueCustomField.generate!(:is_for_all => false, :project_ids => [3], :is_filter => true)
+    field_not_on_project = IssueCustomField.generate!(:is_for_all => false, :project_ids => [1,2], :is_filter => true)
+
+    query = TimeEntryQuery.new(:project => Project.find(3))
+
+    assert_include "issue.cf_#{global.id}", query.available_columns.map(&:name).map(&:to_s)
+    assert_include "issue.cf_#{field_on_project.id}", query.available_columns.map(&:name).map(&:to_s)
+    assert_not_include "issue.cf_#{field_not_on_project.id}", query.available_columns.map(&:name).map(&:to_s)
+  end
 end