Skip to content

Commit

Permalink
Search for "product/views" in all plugings.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinpovolny committed Jun 12, 2017
1 parent be8613f commit fbae08d
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions app/models/miq_report/import_export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@ module MiqReport::ImportExport
extend ActiveSupport::Concern

module ClassMethods
def view_paths
@view_paths ||= (
Vmdb::Plugins.instance.vmdb_plugins.map do |engine|
directory = File.join(engine.root, 'product/views')
directory if File.directory?(directory)
end.compact
)
end

def resolve_view_path(file_name)
view_paths.each do |path|
full_path = File.join(path, file_name)
return full_path if File.exist?(full_path)
end
nil
end

VIEWS_FOLDER = File.join(ManageIQ::UI::Classic::Engine.root, "product/views")
def import_from_hash(report, options = nil)
raise _("No Report to Import") if report.nil?
Expand Down Expand Up @@ -77,30 +94,20 @@ def view_yaml_filename(db, current_user, options)
if %w(ManageIQ::Providers::CloudManager::Template ManageIQ::Providers::InfraManager::Template
ManageIQ::Providers::CloudManager::Vm ManageIQ::Providers::InfraManager::Vm VmOrTemplate).include?(db)
if role && role.settings && role.settings.fetch_path(:restrictions, :vms)
viewfilerestricted = "#{VIEWS_FOLDER}/Vm__restricted.yaml"
viewfilerestricted = resolve_view_path('Vm__restricted.yaml')
end
end

db = db.gsub(/::/, '_')

role = role.name.split("-").last if role.try(:read_only?)

# Build the view file name
if suffix
viewfile = "#{VIEWS_FOLDER}/#{db}-#{suffix}.yaml"
viewfilebyrole = "#{VIEWS_FOLDER}/#{db}-#{suffix}-#{role}.yaml"
else
viewfile = "#{VIEWS_FOLDER}/#{db}.yaml"
viewfilebyrole = "#{VIEWS_FOLDER}/#{db}-#{role}.yaml"
end
suffix = suffix ? "-#{suffix}" : ''

if viewfilerestricted && File.exist?(viewfilerestricted)
viewfilerestricted
elsif File.exist?(viewfilebyrole)
viewfilebyrole
else
viewfile
end
viewfile = resolve_view_path("#{db}#{suffix}.yaml")
viewfilebyrole = resolve_view_path("#{db}#{suffix}-#{role}.yaml")

viewfilerestricted || viewfilebyrole || viewfile
end
end

Expand Down

0 comments on commit fbae08d

Please sign in to comment.