diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index ff709b58b53..9ad32bd99fc 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -901,6 +901,10 @@ def atomic_req_submit end end + # Save selected Tenants from the tree + tenant_objects = Tenant.where(:id => @edit[:new][:tenant_ids]) + st.additional_tenants = tenant_objects + if st.save set_resource_action(st) unless st.kind_of?(ServiceTemplateContainerTemplate) flash_key = params[:button] == "save" ? _("Service Catalog Item \"%{name}\" was saved") : _("Service Catalog Item \"%{name}\" was added") @@ -1254,6 +1258,7 @@ def set_form_vars @edit[:new][:catalog_id] = @record.service_template_catalog.try(:id) @edit[:new][:st_prov_type] ||= @record.prov_type @edit[:new][:generic_subtype] = @record.generic_subtype || "custom" if @edit[:new][:st_prov_type] == 'generic' + @edit[:new][:tenant_ids] = @record.additional_tenants @tenants_tree = build_tenants_tree # Build the tree with available tenants @available_catalogs = available_catalogs.sort # Get available catalogs with tenants and ancestors available_orchestration_templates if @record.kind_of?(ServiceTemplateOrchestration) @@ -1392,6 +1397,7 @@ def get_form_vars # saving it in @edit as well, to use it later because prov_set_form_vars resets @edit[:new] @edit[:st_prov_type] = @edit[:new][:st_prov_type] = params[:st_prov_type] if params[:st_prov_type] @edit[:new][:long_description] = @edit[:new][:long_description].to_s + "..." if params[:transOne] + checked_tenants if params[:check] # Save checked Tenants to @edit @tenants_tree = build_tenants_tree # Build the tree with available tenants @available_catalogs = available_catalogs.sort # Get available catalogs with tenants and ancestors @@ -1399,6 +1405,15 @@ def get_form_vars fetch_form_vars_ansible_or_ct if %w[generic_ansible_tower generic_container_template].include?(@edit[:new][:st_prov_type]) end + def checked_tenants + new_id = params[:id].split('-').pop if params[:id].starts_with?('tn') + if params[:check] == '1' # Adding/checking Tenant(s) in the tree for the Catalog Item + @edit[:new][:tenant_ids] = @edit[:new][:tenant_ids] + [new_id] + else # Unchecking selected Tenant(s) + @edit[:new][:tenant_ids].delete(new_id) + end + end + def available_container_managers @edit[:new][:available_managers] = ManageIQ::Providers::ContainerManager.all.collect { |t| [t.name, t.id] }.sort