Skip to content

Commit

Permalink
Only show catalog types for supported EMSs
Browse files Browse the repository at this point in the history
If an EMS isn't supported by disabling it in the Vmdb::PermissionStore
we shouldn't show it as an available catalog type

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1746084
  • Loading branch information
agrare committed Apr 3, 2020
1 parent 63b3608 commit 16adfcb
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 37 deletions.
27 changes: 15 additions & 12 deletions app/models/ext_management_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,39 @@ def self.supported_types
supported_subclasses.collect(&:ems_type)
end

def self.leaf_subclasses
descendants.select { |d| d.subclasses.empty? }
def self.supported_subclasses
leaf_subclasses.select(&:permitted?)
end

def self.supported_subclasses
subclasses.flat_map do |s|
s.subclasses.empty? ? s : s.supported_subclasses
end
def self.permitted?
Vmdb::PermissionStores.instance.supported_ems_type?(ems_type)
end
delegate :permitted?, :to => :class

def self.supported_types_and_descriptions_hash
supported_subclasses.each_with_object({}) do |klass, hash|
if Vmdb::PermissionStores.instance.supported_ems_type?(klass.ems_type)
hash[klass.ems_type] = klass.description
end
end
supported_subclasses.each_with_object({}) { |klass, hash| hash[klass.ems_type] = klass.description }
end

def self.api_allowed_attributes
%w[]
end

def self.supported_types_for_create
leaf_subclasses.select(&:supported_for_create?)
supported_subclasses.select(&:supported_for_create?)
end

def self.supported_types_for_catalog
supported_subclasses.select(&:supported_for_catalog?)
end

def self.supported_for_create?
!reflections.include?("parent_manager")
end

def self.supported_for_catalog?
catalog_types.present?
end

def self.provider_create_params
supported_types_for_create.each_with_object({}) do |ems_type, create_params|
create_params[ems_type.name] = ems_type.params_for_create if ems_type.respond_to?(:params_for_create)
Expand Down
5 changes: 3 additions & 2 deletions app/models/manageiq/providers/base_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ def ext_management_system
self
end

def supported_catalog_types
[]
def self.catalog_types
{}
end
delegate :catalog_types, :to => :class

def refresher
self.class::Refresher
Expand Down
4 changes: 2 additions & 2 deletions app/models/manageiq/providers/embedded_automation_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def self.supported_for_create?
false
end

def supported_catalog_types
%w(generic_ansible_playbook)
def self.catalog_types
{"generic_ansible_playbook" => N_("Ansible Playbook")}
end
end
40 changes: 22 additions & 18 deletions app/models/service_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,6 @@ class ServiceTemplate < ApplicationRecord
"storage" => N_("Storage")
}.freeze

CATALOG_ITEM_TYPES = {
"amazon" => N_("Amazon"),
"azure" => N_("Azure"),
"generic" => N_("Generic"),
"generic_orchestration" => N_("Orchestration"),
"generic_ansible_playbook" => N_("Ansible Playbook"),
"generic_ansible_tower" => N_("Ansible Tower"),
"generic_container_template" => N_("OpenShift Template"),
"google" => N_("Google"),
"microsoft" => N_("SCVMM"),
"openstack" => N_("OpenStack"),
"redhat" => N_("Red Hat Virtualization"),
"vmware" => N_("VMware")
}.freeze

SERVICE_TYPE_ATOMIC = 'atomic'.freeze
SERVICE_TYPE_COMPOSITE = 'composite'.freeze

Expand Down Expand Up @@ -103,12 +88,31 @@ def self.with_additional_tenants
references(table_name, :tenants).includes(:service_template_tenants => :tenant)
end

def self.all_catalog_item_types
@all_catalog_item_types ||= begin
builtin_catalog_item_types = {
"generic" => N_("Generic"),
"generic_orchestration" => N_("Orchestration"),
}

ExtManagementSystem.supported_types_for_catalog
.flat_map(&:catalog_types)
.reduce(builtin_catalog_item_types, :merge)
end
end

def self.catalog_item_types
ci_types = Set.new(Rbac.filtered(ExtManagementSystem.all).flat_map(&:supported_catalog_types))
ci_types = Set.new(
Rbac.filtered(ExtManagementSystem.all)
.select(&:supported_for_catalog?)
.flat_map(&:catalog_types).reduce({}, :merge).keys
)

ci_types.add('generic_orchestration') if Rbac.filtered(OrchestrationTemplate).exists?
ci_types.add('generic')
CATALOG_ITEM_TYPES.each.with_object({}) do |(key, description), hash|
hash[key] = { :description => description, :display => ci_types.include?(key) }

all_catalog_item_types.each.with_object({}) do |(key, description), hash|
hash[key] = {:description => description, :display => ci_types.include?(key)}
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
RSpec.describe ManageIQ::Providers::EmbeddedAnsible::AutomationManager do
context 'catalog types' do
describe ".catalog_types" do
it "includes generic_ansible_playbook" do
expect(described_class.catalog_types).to include("generic_ansible_playbook")
end
end

describe '#catalog_types' do
let(:ems) { FactoryBot.create(:embedded_automation_manager_ansible) }

it "#supported_catalog_types" do
expect(ems.supported_catalog_types).to eq(%w(generic_ansible_playbook))
it "includes generic_ansible_playbook" do
expect(ems.catalog_types).to include("generic_ansible_playbook")
end
end
end

0 comments on commit 16adfcb

Please sign in to comment.