Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catalog Item type list is dependent on installed providers #16559

Merged
merged 3 commits into from
Dec 11, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/models/manageiq/providers/base_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def ext_management_system
self
end

def supported_catalog_types
[]
end

def refresher
self.class::Refresher
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ class ManageIQ::Providers::EmbeddedAutomationManager < ManageIQ::Providers::Auto
require_nested :ConfigurationScriptSource
require_nested :ConfiguredSystem
require_nested :OrchestrationStack

def supported_catalog_types
%w(generic_ansible_playbook)
end
end
9 changes: 9 additions & 0 deletions app/models/service_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ class ServiceTemplate < ApplicationRecord
scope :with_existent_service_template_catalog_id, -> { where.not(:service_template_catalog_id => nil) }
scope :displayed, -> { where(:display => true) }

def self.catalog_item_types
ci_types = Rbac.filtered(ExtManagementSystem.all).flat_map(&:supported_catalog_types).uniq
ci_types << 'generic_orchestration' if Rbac.filtered(OrchestrationTemplate).exists?
ci_types << 'generic'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are building this up as an index for lookup purposes (with uniqueness), you would be better off using a Set object (and not manually calling unique, but letting Set do that for you).

CATALOG_ITEM_TYPES.each.with_object({}) do |(key, description), hash|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does the UI use it - gray out non-displayable item from the dropdown? Or should we simply remove non-qualified types?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bzwei @h-kataria mentioned that there is some bootstrap magic that does that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bzwei yes UI will show those items as grayed/disabled in the drop down, see screenshot in ManageIQ/manageiq-ui-classic#2908

hash[key] = { :description => description, :display => ci_types.include?(key) }
end
end

def self.create_catalog_item(options, auth_user)
transaction do
create_from_options(options).tap do |service_template|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
describe ManageIQ::Providers::EmbeddedAnsible::AutomationManager do
it_behaves_like 'ansible automation_manager'

context 'catalog types' do
let(:ems) { FactoryGirl.create(:embedded_automation_manager) }

it "#supported_catalog_types" do
expect(ems.supported_catalog_types).to eq(%w(generic_ansible_playbook))
end
end
end
21 changes: 21 additions & 0 deletions spec/models/service_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,27 @@
expect { service_template.provision_request(user, arg1, arg2) }.to raise_error(RuntimeError)
end
end

context "catalog_item_types" do
it "only returns generic with no providers" do
expect(ServiceTemplate.catalog_item_types).to match(
hash_including('amazon' => {:description => 'Amazon', :display => false},
'generic' => {:description => 'Generic', :display => true })
)
end

it "returns orchestration template and generic" do
FactoryGirl.create(:orchestration_template)
expect(ServiceTemplate.catalog_item_types).to match(
hash_including('amazon' => { :description => 'Amazon',
:display => false },
'generic' => { :description => 'Generic',
:display => true },
'generic_orchestration' => { :description => 'Orchestration',
:display => true})
)
end
end
end

def add_and_save_service(p, c)
Expand Down