Skip to content

Commit

Permalink
Pass additional information to the API when ordering a service catalog
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
eclarizio committed Dec 1, 2017
1 parent 797eb75 commit d7c7f9c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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));
});
};

Expand Down
7 changes: 5 additions & 2 deletions app/controllers/application_controller/buttons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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"
Expand All @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion app/views/shared/dialogs/_dialog_provision.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion app/views/shared/dialogs/_dialog_user.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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}');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ describe('dialogUserController', function() {

spyOn(dialogFieldRefreshService, 'refreshField');
spyOn(miqService, 'miqAjaxButton');
spyOn(miqService, 'redirectBack');
spyOn(miqService, 'sparkleOn');
spyOn(miqService, 'sparkleOff');

Expand All @@ -29,6 +28,9 @@ describe('dialogUserController', function() {
apiAction: 'order',
cancelEndpoint: 'cancel endpoint',
finishSubmitEndpoint: 'finish submit endpoint',
resourceActionId: '789',
targetId: '987',
targetType: 'targettype',
});
}));

Expand All @@ -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() {
Expand Down Expand Up @@ -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'));
});

Expand Down Expand Up @@ -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');
});
Expand Down

0 comments on commit d7c7f9c

Please sign in to comment.