]> source.dussan.org Git - redmine.git/commitdiff
Query through multiple projects by issue custom field not possible anymore (#25501).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 3 Apr 2017 14:04:04 +0000 (14:04 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 3 Apr 2017 14:04:04 +0000 (14:04 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@16467 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue_query.rb
app/models/project.rb
app/models/query.rb
app/models/time_entry_query.rb

index 9f3bf290d7841b4dee7e62db52ad7fe274508662..5ca76a5bc5db9310a7faeec2d9d6b90edb43a072 100644 (file)
@@ -164,10 +164,7 @@ class IssueQuery < Query
         :values => lambda { subproject_values }
     end
 
-
-    issue_custom_fields = project ? project.all_issue_custom_fields : IssueCustomField.where(:is_for_all => true)
     add_custom_fields_filters(issue_custom_fields)
-
     add_associations_custom_fields_filters :project, :author, :assigned_to, :fixed_version
 
     IssueRelation::TYPES.each do |relation_type, options|
@@ -186,10 +183,7 @@ class IssueQuery < Query
   def available_columns
     return @available_columns if @available_columns
     @available_columns = self.class.available_columns.dup
-    @available_columns += (project ?
-                            project.all_issue_custom_fields :
-                            IssueCustomField
-                           ).visible.collect {|cf| QueryCustomFieldColumn.new(cf) }
+    @available_columns += issue_custom_fields.visible.collect {|cf| QueryCustomFieldColumn.new(cf) }
 
     if User.current.allowed_to?(:view_time_entries, project, :global => true)
       index = @available_columns.find_index {|column| column.name == :total_estimated_hours}
index 3d8878ca2786480ca9c8cff513572c6ab197a2af..a425d8ca78e805a3838f877291d82ad6374681a5 100644 (file)
@@ -325,6 +325,7 @@ class Project < ActiveRecord::Base
     @shared_versions = nil
     @rolled_up_versions = nil
     @rolled_up_trackers = nil
+    @rolled_up_custom_fields = nil
     @all_issue_custom_fields = nil
     @all_time_entry_custom_fields = nil
     @to_param = nil
@@ -579,6 +580,22 @@ class Project < ActiveRecord::Base
     end
   end
 
+  # Returns a scope of all custom fields enabled for issues of the project
+  # and its subprojects
+  def rolled_up_custom_fields
+    if leaf?
+      all_issue_custom_fields
+    else
+      @rolled_up_custom_fields ||= IssueCustomField.
+        sorted.
+        where("is_for_all = ? OR EXISTS (SELECT 1" +
+          " FROM #{table_name_prefix}custom_fields_projects#{table_name_suffix} cfp" +
+          " JOIN #{Project.table_name} p ON p.id = cfp.project_id" +
+          " WHERE cfp.custom_field_id = #{CustomField.table_name}.id" +
+          " AND p.lft >= ? AND p.rgt <= ?)", true, lft, rgt)
+    end
+  end
+
   def project
     self
   end
index a0f1969e3735bed71032ca0591548d2fc763c730..863bdbc4abc16ae79e35eb1a3e2c777f70bd5d0e 100644 (file)
@@ -551,6 +551,15 @@ class Query < ActiveRecord::Base
     Version.sort_by_status(versions).collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s, l("version_status_#{s.status}")] }
   end
 
+  # Returns a scope of issue custom fields that are available as columns or filters
+  def issue_custom_fields
+    if project
+      project.rolled_up_custom_fields
+    else
+      IssueCustomField.all
+    end
+  end
+
   # Adds available filters
   def initialize_available_filters
     # implemented by sub-classes
index 656415d66b6c8625065c14587672fddb9ce0cbab..eab1113e28f673f85b34c9a2b81c576af869a717 100644 (file)
@@ -218,12 +218,4 @@ class TimeEntryQuery < Query
     joins.compact!
     joins.any? ? joins.join(' ') : nil
   end
-
-  def issue_custom_fields
-    if project
-      project.all_issue_custom_fields
-    else
-      IssueCustomField.where(:is_for_all => true)
-    end
-  end
 end