diff --git a/app/models/miq_report/generator.rb b/app/models/miq_report/generator.rb index b0055fc685ec..ee93eab2d7c6 100644 --- a/app/models/miq_report/generator.rb +++ b/app/models/miq_report/generator.rb @@ -88,6 +88,34 @@ def get_include include_as_hash(include.presence || invent_report_includes) end + def polymorphic_includes + @polymorphic_includes ||= begin + polymorphic_rels = [] + top_level_rels = [] + top_level_rels += Array(get_include.try(:keys)) + top_level_rels += Array(get_include_for_find.try(:keys)) + + top_level_rels.uniq.each do |assoc| + reflection = db_klass.reflect_on_association(assoc) + polymorphic_rels << assoc if reflection && reflection.polymorphic? + end + + polymorphic_rels + end + end + + def get_include_for_find_rbac + polymorphic_includes.each_with_object(get_include_for_find.dup) do |key, includes| + includes.delete(key) + end + end + + def get_include_rbac + polymorphic_includes.each_with_object(get_include.dup) do |key, includes| + includes.delete(key) + end + end + def invent_includes include_as_hash(invent_report_includes) end @@ -312,8 +340,8 @@ def generate_basic_results(options = {}) rbac_opts = options.merge( :targets => targets, :filter => conditions, - :include_for_find => get_include_for_find, - :references => get_include, + :include_for_find => get_include_for_find_rbac, + :references => get_include_rbac, :where_clause => where_clause, :skip_counts => true )