From d7c7f9c2b4070e871a68717640ee0b2a7431184c Mon Sep 17 00:00:00 2001 From: Erik Clarizio Date: Thu, 30 Nov 2017 09:49:25 -0800 Subject: [PATCH] Pass additional information to the API when ordering a service catalog https://bugzilla.redhat.com/show_bug.cgi?id=1518390 Resource action id, target id, and target type need to be passed in order to establish the context that some dynamic methods may use when going through automate. --- .../controllers/dialog_user/dialog_user_controller.js | 9 +++++++-- app/controllers/application_controller/buttons.rb | 7 +++++-- app/controllers/catalog_controller.rb | 7 ++++++- app/views/shared/dialogs/_dialog_provision.html.haml | 9 ++++++++- app/views/shared/dialogs/_dialog_user.html.haml | 5 ++++- .../dialog_user/dialog_user_controller.spec.js | 11 +++++++++-- 6 files changed, 39 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/controllers/dialog_user/dialog_user_controller.js b/app/assets/javascripts/controllers/dialog_user/dialog_user_controller.js index 43092796366..6a0a2edc164 100644 --- a/app/assets/javascripts/controllers/dialog_user/dialog_user_controller.js +++ b/app/assets/javascripts/controllers/dialog_user/dialog_user_controller.js @@ -1,9 +1,14 @@ -ManageIQ.angular.app.controller('dialogUserController', ['API', 'dialogFieldRefreshService', 'miqService', 'dialogId', 'apiSubmitEndpoint', 'apiAction', 'finishSubmitEndpoint', 'cancelEndpoint', function(API, dialogFieldRefreshService, miqService, dialogId, apiSubmitEndpoint, apiAction, finishSubmitEndpoint, cancelEndpoint) { +ManageIQ.angular.app.controller('dialogUserController', ['API', 'dialogFieldRefreshService', 'miqService', 'dialogId', 'apiSubmitEndpoint', 'apiAction', 'finishSubmitEndpoint', 'cancelEndpoint', 'resourceActionId', 'targetId', 'targetType', function(API, dialogFieldRefreshService, miqService, dialogId, apiSubmitEndpoint, apiAction, finishSubmitEndpoint, cancelEndpoint, resourceActionId, targetId, targetType) { var vm = this; vm.$onInit = function() { return new Promise(function(resolve) { - resolve(API.get('/api/service_dialogs/' + dialogId, {expand: 'resources', attributes: 'content'}).then(init)); + var url = '/api/service_dialogs/' + dialogId + + '?resource_action_id=' + resourceActionId + + '&target_id=' + targetId + + '&target_type=' + targetType; + + resolve(API.get(url, {expand: 'resources', attributes: 'content'}).then(init)); }); }; diff --git a/app/controllers/application_controller/buttons.rb b/app/controllers/application_controller/buttons.rb index 1f27eb34597..14dcadaa921 100644 --- a/app/controllers/application_controller/buttons.rb +++ b/app/controllers/application_controller/buttons.rb @@ -333,7 +333,7 @@ def custom_buttons(ids = nil) :target_kls => obj.class.name, } - options[:dialog_locals] = determine_dialog_locals_for_custom_button(obj, button.name) + options[:dialog_locals] = determine_dialog_locals_for_custom_button(obj, button.name, button.resource_action.id) dialog_initialize(button.resource_action, options) @@ -356,7 +356,7 @@ def custom_buttons(ids = nil) end end - def determine_dialog_locals_for_custom_button(obj, button_name) + def determine_dialog_locals_for_custom_button(obj, button_name, resource_action_id) case obj.class.name.demodulize when /Vm/ api_collection_name = "vms" @@ -375,6 +375,9 @@ def determine_dialog_locals_for_custom_button(obj, button_name) end { + :resource_action_id => resource_action_id, + :target_id => obj.id, + :target_type => obj.class.name.underscore, :force_old_dialog_use => force_old_dialog_use, :api_submit_endpoint => "/api/#{api_collection_name}/#{obj.id}", :api_action => button_name, diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index a137e67d113..9b8518d7730 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -544,12 +544,17 @@ def svc_catalog_provision options[:target_id] = st.id options[:target_kls] = st.class.name options[:dialog_locals] = { + :resource_action_id => ra.id, + :target_id => st.id, + :target_type => st.class.name.underscore, + :dialog_id => ra.dialog_id, :api_submit_endpoint => "/api/service_catalogs/#{st.service_template_catalog_id}/service_templates/#{st.id}", :api_action => "order", :finish_submit_endpoint => svc_catalog_provision_finish_submit_endpoint, :cancel_endpoint => "/catalog/explorer" } - dialog_initialize(ra, options) + + replace_right_cell(:action => "dialog_provision", :dialog_locals => options[:dialog_locals]) else # if catalog item has no dialog and provision button was pressed from list view add_flash(_("No Ordering Dialog is available"), :warning) diff --git a/app/views/shared/dialogs/_dialog_provision.html.haml b/app/views/shared/dialogs/_dialog_provision.html.haml index 3b9c159a859..73af5269793 100644 --- a/app/views/shared/dialogs/_dialog_provision.html.haml +++ b/app/views/shared/dialogs/_dialog_provision.html.haml @@ -5,6 +5,10 @@ - api_action ||= @dialog_locals[:api_action] - finish_submit_endpoint ||= @dialog_locals[:finish_submit_endpoint] - cancel_endpoint ||= @dialog_locals[:cancel_endpoint] + - target_id ||= @dialog_locals[:target_id] + - target_type ||= @dialog_locals[:target_type] + - dialog_id ||= @dialog_locals[:dialog_id] + - resource_action_id ||= @dialog_locals[:resource_action_id] - force_old_dialog_use = @dialog_locals[:force_old_dialog_use].to_s == "true" - force_old_dialog_use ||= true if api_submit_endpoint.nil? @@ -39,7 +43,10 @@ - else = render :partial => "shared/dialogs/dialog_user", - :locals => {:wf => wf, + :locals => {:dialog_id => dialog_id, + :resource_action_id => resource_action_id, + :target_id => target_id, + :target_type => target_type, :finish_submit_endpoint => finish_submit_endpoint, :api_submit_endpoint => api_submit_endpoint, :api_action => api_action, diff --git a/app/views/shared/dialogs/_dialog_user.html.haml b/app/views/shared/dialogs/_dialog_user.html.haml index 244787bb81c..4b8728bdee8 100644 --- a/app/views/shared/dialogs/_dialog_user.html.haml +++ b/app/views/shared/dialogs/_dialog_user.html.haml @@ -17,7 +17,10 @@ 'on-click' => "vm.cancelClicked($event)"} :javascript - ManageIQ.angular.app.value('dialogId', '#{wf.dialog.id}'); + ManageIQ.angular.app.value('resourceActionId', '#{resource_action_id}'); + ManageIQ.angular.app.value('targetId', '#{target_id}'); + ManageIQ.angular.app.value('targetType', '#{target_type}'); + ManageIQ.angular.app.value('dialogId', '#{dialog_id}'); ManageIQ.angular.app.value('finishSubmitEndpoint', '#{finish_submit_endpoint}'); ManageIQ.angular.app.value('apiSubmitEndpoint', '#{api_submit_endpoint}'); ManageIQ.angular.app.value('apiAction', '#{api_action}'); diff --git a/spec/javascripts/controllers/dialog_user/dialog_user_controller.spec.js b/spec/javascripts/controllers/dialog_user/dialog_user_controller.spec.js index 8e2a4818d55..e6705d76518 100644 --- a/spec/javascripts/controllers/dialog_user/dialog_user_controller.spec.js +++ b/spec/javascripts/controllers/dialog_user/dialog_user_controller.spec.js @@ -16,7 +16,6 @@ describe('dialogUserController', function() { spyOn(dialogFieldRefreshService, 'refreshField'); spyOn(miqService, 'miqAjaxButton'); - spyOn(miqService, 'redirectBack'); spyOn(miqService, 'sparkleOn'); spyOn(miqService, 'sparkleOff'); @@ -29,6 +28,9 @@ describe('dialogUserController', function() { apiAction: 'order', cancelEndpoint: 'cancel endpoint', finishSubmitEndpoint: 'finish submit endpoint', + resourceActionId: '789', + targetId: '987', + targetType: 'targettype', }); })); @@ -38,7 +40,10 @@ describe('dialogUserController', function() { }); it('requests the current dialog based on the service template', function() { - expect(API.get).toHaveBeenCalledWith('/api/service_dialogs/1234', {expand: 'resources', attributes: 'content'}); + expect(API.get).toHaveBeenCalledWith( + '/api/service_dialogs/1234?resource_action_id=789&target_id=987&target_type=targettype', + {expand: 'resources', attributes: 'content'} + ); }); it('resolves the request and stores the information in the dialog property', function() { @@ -85,6 +90,7 @@ describe('dialogUserController', function() { context('when the API call succeeds', function() { beforeEach(function() { + spyOn(miqService, 'redirectBack'); spyOn(API, 'post').and.returnValue(Promise.resolve('awesome')); }); @@ -122,6 +128,7 @@ describe('dialogUserController', function() { context('when the API call fails', function() { beforeEach(function() { + spyOn(miqService, 'redirectBack'); spyOn(API, 'post').and.returnValue(Promise.reject('not awesome')); spyOn(window, 'add_flash'); });