diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb
index 467ec0d41407..de6e3f0a5191 100644
--- a/app/controllers/catalog_controller.rb
+++ b/app/controllers/catalog_controller.rb
@@ -320,6 +320,8 @@ def identify_catalog(id = nil)
kls = TreeBuilder.get_model_for_prefix(@nodetype) == "MiqTemplate" ? VmOrTemplate : ServiceTemplate
@record = identify_record(id || params[:id], kls)
@tenants_tree = build_tenants_tree if kls == ServiceTemplate # Build the tree with available tenants for the Catalog Item/Bundle
+ @template_valid = @record.try(:template_valid?)
+ add_flash(_("This item is invalid"), :warning) unless @flash_array || @template_valid
end
# ST clicked on in the explorer right cell
diff --git a/app/views/catalog/_svccat_tree_show.html.haml b/app/views/catalog/_svccat_tree_show.html.haml
index c44209a4da4f..e25f0929a57d 100644
--- a/app/views/catalog/_svccat_tree_show.html.haml
+++ b/app/views/catalog/_svccat_tree_show.html.haml
@@ -45,10 +45,11 @@
.col-md-1{:align => "center"}
#buttons
= button_tag(_("Order"),
- :class => "btn btn-primary",
- :alt => t = _("Order this Service"),
- :title => t,
- :onclick => "miqOrderService(#{@record.id})")
+ :class => "btn btn-primary",
+ :alt => t = @template_valid ? _("Order this Service") : _("This Service cannot be ordered"),
+ :title => t,
+ :disabled => !@template_valid,
+ :onclick => "miqOrderService(#{@record.id})")
:javascript
miq_bootstrap('#long_description');
diff --git a/spec/controllers/catalog_controller_spec.rb b/spec/controllers/catalog_controller_spec.rb
index cf37eb8f598a..d9c512484d48 100644
--- a/spec/controllers/catalog_controller_spec.rb
+++ b/spec/controllers/catalog_controller_spec.rb
@@ -67,9 +67,7 @@
end
describe '#x_button' do
- before do
- ApplicationController.handle_exceptions = true
- end
+ before { ApplicationController.handle_exceptions = true }
context 'corresponding methods are called for allowed actions' do
CatalogController::CATALOG_X_BUTTON_ALLOWED_ACTIONS.each_pair do |action_name, actual_method|
@@ -476,6 +474,7 @@
describe "#ot_rendering" do
render_views
+
before do
EvmSpecHelper.create_guid_miq_server_zone
session[:settings] = {
@@ -964,6 +963,7 @@
describe '#replace_right_cell' do
let(:dialog) { FactoryBot.create(:dialog) }
+
before do
allow(controller).to receive(:params).and_return(:action => 'dialog_provision')
controller.instance_variable_set(:@in_a_form, true)
@@ -984,14 +984,8 @@
end
describe '#service_template_list' do
- let(:sandbox) { {:active_tree => tree} }
-
- before do
- controller.instance_variable_set(:@sb, sandbox)
- end
-
context 'Service Catalogs accordion' do
- let(:tree) { :svccat_tree }
+ before { controller.instance_variable_set(:@sb, :active_tree => :svccat_tree) }
it 'sets options for rendering proper type of view' do
expect(controller).to receive(:process_show_list).with(:gtl_dbname => :catalog, :named_scope => {})
@@ -1001,7 +995,7 @@
end
describe '#available_job_templates' do
- it "" do
+ it "sets new available templates" do
ems = FactoryBot.create(:automation_manager_ansible_tower)
cs = FactoryBot.create(:configuration_script,
:type => 'ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationScript')
@@ -1260,6 +1254,30 @@
controller.send(:identify_catalog, record.id)
expect(controller.instance_variable_get(:@tenants_tree).name).to eq(:tenants_tree)
end
+
+ it 'does not add warning flash message for valid Catalog Item or Bundle' do
+ controller.send(:identify_catalog, record.id)
+ expect(controller.instance_variable_get(:@flash_array)).to be_nil
+ end
+
+ it 'sets @template_valid to true' do
+ controller.send(:identify_catalog, record.id)
+ expect(controller.instance_variable_get(:@template_valid)).to be(true)
+ end
+
+ context 'invalid Catalog Item or Bundle' do
+ let(:record) { FactoryBot.create(:service_template, :service_resources => [FactoryBot.create(:service_resource)]) }
+
+ it 'adds warning flash message' do
+ controller.send(:identify_catalog, record.id)
+ expect(controller.instance_variable_get(:@flash_array)).to eq([{:message => 'This item is invalid', :level => :warning}])
+ end
+
+ it 'sets @template_valid to false' do
+ controller.send(:identify_catalog, record.id)
+ expect(controller.instance_variable_get(:@template_valid)).to be(false)
+ end
+ end
end
describe '#common_st_record_vars' do
diff --git a/spec/views/catalog/_svccat_tree_show.html.haml_spec.rb b/spec/views/catalog/_svccat_tree_show.html.haml_spec.rb
new file mode 100644
index 000000000000..ad07df397257
--- /dev/null
+++ b/spec/views/catalog/_svccat_tree_show.html.haml_spec.rb
@@ -0,0 +1,23 @@
+describe "catalog/_svccat_tree_show.html.haml" do
+ let(:service) { FactoryBot.create(:service_template) }
+
+ before do
+ assign(:record, service)
+ assign(:sb, {})
+ assign(:template_valid, true)
+ end
+
+ it 'enables Order button' do
+ render :partial => 'catalog/svccat_tree_show'
+ expect(response).to include("")
+ end
+
+ context 'invalid Catalog items or Bundles' do
+ before { assign(:template_valid, false) }
+
+ it 'disables Order button' do
+ render :partial => 'catalog/svccat_tree_show'
+ expect(response).to include("")
+ end
+ end
+end