Skip to content

Commit

Permalink
Merge pull request #3661 from h-kataria/catalog_item_missing_request_fix
Browse files Browse the repository at this point in the history
Show message when trying to edit item with missing Provisioning request
  • Loading branch information
Dan Clarizio authored Mar 20, 2018
2 parents adb24a0 + 6a24e66 commit 09b7417
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
19 changes: 16 additions & 3 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,15 @@ def atomic_st_edit
add_flash(_("All changes have been reset"), :warning)
end
if !@record.id.nil? && need_prov_dialogs?(@record.prov_type)
prov_set_form_vars(MiqRequest.find(@record.service_resources[0].resource_id)) # Set vars from existing request
request = MiqRequest.find_by(:id => @record.service_resources[0].resource_id) if @record.service_resources[0]&.resource_id
if request
prov_set_form_vars(request) # Set vars from existing request
else
add_flash(_("Can not edit selected item, Request is missing"), :error)
@edit = @record = nil
replace_right_cell
return
end
else
# prov_set_form_vars
@edit ||= {} # Set default vars
Expand Down Expand Up @@ -1763,8 +1771,13 @@ def get_node_info_handle_leaf_node_ot(id)
def get_node_info_handle_leaf_node(id)
show_record(id)
if @record.atomic? && need_prov_dialogs?(@record.prov_type)
@miq_request = MiqRequest.find(@record.service_resources[0].resource_id)
prov_set_show_vars
@miq_request = MiqRequest.find_by(:id => @record.service_resources[0].resource_id) if @record.service_resources[0]&.resource_id
if @miq_request
prov_set_show_vars
else
@options = nil
@no_wf_msg = _("Request is missing for selected item")
end
end
unless @record.prov_type == "generic_ansible_playbook"
@sb[:dialog_label] = _("No Dialog")
Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/_sandt_tree_show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
- else
- if [email protected]_type || (@record.prov_type && need_prov_dialogs?(@record.prov_type))
= miq_tab_content('request') do
- if @options[:wf]
- if @options && @options[:wf]
%h3
= _('Request Info')
= render :partial => "miq_request/prov_wf",
Expand Down
24 changes: 24 additions & 0 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,30 @@
end
end

context "#x_button catalogitem_edit" do
before do
vm = FactoryGirl.create(:vm_vmware,
:ext_management_system => FactoryGirl.create(:ems_vmware),
:storage => FactoryGirl.create(:storage))
@miq_request = FactoryGirl.create(:miq_provision_request, :requester => admin_user, :src_vm_id => vm.id)
service_template_with_root_tenant.update_attributes(:prov_type => 'vmware')
service_template_with_root_tenant.add_resource(@miq_request)
service_template_with_root_tenant.save
end

it "shows flash message for missing Request" do
@miq_request.destroy
post :x_button, :params => {:id => service_template_with_root_tenant.id, :pressed => "catalogitem_edit", :format => :js}
expect(assigns(:flash_array).first[:message]).to include("Can not edit selected item, Request is missing")
expect(assigns(:edit)).to be_nil
end

it "continues with setting edit screen when Request is present" do
post :x_button, :params => {:id => service_template_with_root_tenant.id, :pressed => "catalogitem_edit", :format => :js}
expect(assigns(:edit)).not_to be_nil
end
end

context "#st_edit" do
it "@record is cleared out after Service Template is added" do
controller.instance_variable_set(:@sb, {})
Expand Down

0 comments on commit 09b7417

Please sign in to comment.