diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-10-09 08:39:37 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-10-09 08:39:37 +0000 |
commit | 6501e1451a4377bd288aa3add7986e24df129e5d (patch) | |
tree | 530cc0b0bcf058d4a5476ad13b88efd35bb3ab9e | |
parent | 52b19aca3c4d7d1e8a08ca901cdfa3dd30478c82 (diff) | |
download | redmine-6501e1451a4377bd288aa3add7986e24df129e5d.tar.gz redmine-6501e1451a4377bd288aa3add7986e24df129e5d.zip |
Merged r15890 (#24014).
git-svn-id: http://svn.redmine.org/redmine/branches/3.3-stable@15893 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/models/time_entry_query.rb | 14 | ||||
-rw-r--r-- | test/unit/time_entry_query_test.rb | 24 |
2 files changed, 36 insertions, 2 deletions
diff --git a/app/models/time_entry_query.rb b/app/models/time_entry_query.rb index a921f6d93..148c657c0 100644 --- a/app/models/time_entry_query.rb +++ b/app/models/time_entry_query.rb @@ -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 diff --git a/test/unit/time_entry_query_test.rb b/test/unit/time_entry_query_test.rb index 9ca864f72..599aae52c 100644 --- a/test/unit/time_entry_query_test.rb +++ b/test/unit/time_entry_query_test.rb @@ -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 |