Skip to content

Commit 546910f

Browse files
committed
Added create orchestration template service dialog endpoint.
1 parent f3ed911 commit 546910f

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

app/controllers/api/service_dialogs_controller.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class ServiceDialogsController < BaseController
33
before_action :set_additional_attributes, :only => [:index, :show]
44

55
CONTENT_PARAMS = %w[target_type target_id resource_action_id].freeze
6+
ORCHESTRATION_TEMPLATE_DIALOG_REQUIRED_ATTRS = %w[ot_id label].freeze
67

78
def refresh_dialog_fields_resource(type, id = nil, data = nil)
89
raise BadRequestError, "Must specify an id for Reconfiguring a #{type} resource" unless id
@@ -48,6 +49,12 @@ def copy_resource(type, id, data)
4849
raise BadRequestError, "Failed to copy service dialog - #{err}"
4950
end
5051

52+
def orchestration_template_service_dialog_resource(_type, _id, data)
53+
validate_orchestration_template_dialog_create_data(data)
54+
ot = OrchestrationTemplate.find(data['ot_id'])
55+
Dialog::OrchestrationTemplateServiceDialog.create_dialog(data['label'], ot)
56+
end
57+
5158
private
5259

5360
def validate_dialog_content_params(params, required = false)
@@ -98,5 +105,11 @@ def define_service_dialog(dialog_fields, data, options = {})
98105
def service_dialog_ident(service_dialog)
99106
"Service Dialog id:#{service_dialog.id} label:'#{service_dialog.label}'"
100107
end
108+
109+
def validate_orchestration_template_dialog_create_data(data)
110+
bad_attrs = []
111+
ORCHESTRATION_TEMPLATE_DIALOG_REQUIRED_ATTRS.each { |attr| bad_attrs << attr if data[attr].blank? }
112+
raise BadRequestError, "Missing attribute(s) #{bad_attrs.join(', ')} for creating a service dialog from orchestration template" if bad_attrs.present?
113+
end
101114
end
102115
end

config/api.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2884,6 +2884,8 @@
28842884
:identifier: dialog_edit_editor
28852885
- :name: copy
28862886
:identifier: dialog_copy_editor
2887+
- :name: orchestration_template_service_dialog
2888+
:identifier: dialog_new_editor
28872889
:resource_actions:
28882890
:get:
28892891
- :name: read
@@ -2899,6 +2901,8 @@
28992901
:identifier: dialog_edit_editor
29002902
- :name: copy
29012903
:identifier: dialog_copy_editor
2904+
- :name: orchestration_template_service_dialog
2905+
:identifier: dialog_new_editor
29022906
:delete:
29032907
- :name: delete
29042908
:identifier: dialog_delete

spec/requests/service_dialogs_spec.rb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,4 +739,64 @@ def init_dialog
739739
expect(response).to have_http_status(:bad_request)
740740
end
741741
end
742+
743+
context 'Create servide dialog from orchestration template' do
744+
let(:ot) do
745+
FactoryBot.create(:orchestration_template_amazon_in_json).tap do |template|
746+
allow(template).to receive(:parameter_groups).and_return(param_groups)
747+
allow(template).to receive(:tabs).and_return(tabs) if tabs.count > 0
748+
end
749+
end
750+
751+
let(:param_groups) { [] }
752+
let(:tabs) do
753+
[
754+
{
755+
:title => 'Tab 1',
756+
:stack_group => [
757+
OrchestrationTemplate::OrchestrationParameter.new(:label => 'Param 1', :name => SecureRandom.hex, :data_type => 'string'),
758+
OrchestrationTemplate::OrchestrationParameter.new(:label => 'Param 2', :name => SecureRandom.hex, :data_type => 'string')
759+
]
760+
}
761+
]
762+
end
763+
764+
it 'should create service dialog' do
765+
api_basic_authorize collection_action_identifier(:service_dialogs, :create)
766+
767+
orchestration_template_dialog_request = {
768+
:action => 'orchestration_template_service_dialog',
769+
:resource => {:label => 'Foo', :ot_id => ot.id}
770+
}
771+
772+
post(api_service_dialogs_url, :params => orchestration_template_dialog_request)
773+
expect(response).to have_http_status(:ok)
774+
expect(response.parsed_body['results'][0]['label']).to eq('Foo')
775+
expect(response.parsed_body['results'][0]['buttons']).to eq('submit,cancel')
776+
end
777+
778+
it 'should fail whet ot_id is undefined' do
779+
api_basic_authorize collection_action_identifier(:service_dialogs, :create)
780+
781+
orchestration_template_dialog_request = {
782+
:action => 'orchestration_template_service_dialog',
783+
:resource => {:label => 'Foo'}
784+
}
785+
786+
post(api_service_dialogs_url, :params => orchestration_template_dialog_request)
787+
expect(response).to have_http_status(:bad_request)
788+
end
789+
790+
it 'should fail whet label is undefined' do
791+
api_basic_authorize collection_action_identifier(:service_dialogs, :create)
792+
793+
orchestration_template_dialog_request = {
794+
:action => 'orchestration_template_service_dialog',
795+
:resource => {:ot_id => ot.id}
796+
}
797+
798+
post(api_service_dialogs_url, :params => orchestration_template_dialog_request)
799+
expect(response).to have_http_status(:bad_request)
800+
end
801+
end
742802
end

0 commit comments

Comments
 (0)