Skip to content

Commit

Permalink
Merge pull request #15353 from martinpovolny/use_views_from_plugins
Browse files Browse the repository at this point in the history
Search for "product/views" in all plugins
  • Loading branch information
chessbyte authored Jun 12, 2017
2 parents d62dd7d + fbae08d commit cb41626
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 cb41626

Please sign in to comment.