diff --git a/app/models/service_template.rb b/app/models/service_template.rb index c6a2a80558a..a8744732fe9 100644 --- a/app/models/service_template.rb +++ b/app/models/service_template.rb @@ -93,6 +93,7 @@ def self.class_from_request_data(data) def update_catalog_item(options, auth_user = nil) config_info = validate_update_config_info(options) + return update_attributes!(options) unless config_info transaction do update_from_options(options) @@ -428,7 +429,12 @@ def build_resource_action(ae_endpoint, action) end def validate_update_config_info(options) - raise _('service_type and prov_type cannot be changed') if options[:service_type] || options[:prov_type] + if options[:service_type] && options[:service_type] != service_type + raise _('service_type cannot be changed') + end + if options[:prov_type] && options[:prov_type] != prov_type + raise _('prov_type cannot be changed') + end options[:config_info] end diff --git a/app/models/service_template_ansible_tower.rb b/app/models/service_template_ansible_tower.rb index 91187f8e9d0..978820e8ed3 100644 --- a/app/models/service_template_ansible_tower.rb +++ b/app/models/service_template_ansible_tower.rb @@ -66,6 +66,7 @@ def update_service_resources(config_info, _auth_user = nil) def validate_update_config_info(options) super + return unless options.key?(:config_info) self.class.validate_config_info(options) end diff --git a/app/models/service_template_orchestration.rb b/app/models/service_template_orchestration.rb index bce37dd85ed..c14841df229 100644 --- a/app/models/service_template_orchestration.rb +++ b/app/models/service_template_orchestration.rb @@ -72,6 +72,7 @@ def update_service_resources(config_info, _auth_user = nil) def validate_update_config_info(options) super + return unless options.key?(:config_info) self.class.validate_config_info(options) end diff --git a/spec/models/service_template_ansible_tower_spec.rb b/spec/models/service_template_ansible_tower_spec.rb index 3e967a7b9f9..1a756d6b273 100644 --- a/spec/models/service_template_ansible_tower_spec.rb +++ b/spec/models/service_template_ansible_tower_spec.rb @@ -101,6 +101,13 @@ expect(updated.configuration_script).to eq(new_configuration_script) end + + it 'allows for update without the presence of config_info' do + expect do + @catalog_item.update_catalog_item(:name => 'new_name') + end.to change(@catalog_item, :name) + expect(@catalog_item.reload.name).to eq('new_name') + end end describe '#config_info' do diff --git a/spec/models/service_template_orchestration_spec.rb b/spec/models/service_template_orchestration_spec.rb index ecc053550ce..ab322726369 100644 --- a/spec/models/service_template_orchestration_spec.rb +++ b/spec/models/service_template_orchestration_spec.rb @@ -210,13 +210,6 @@ end.to raise_error(StandardError, 'Must provide both template_id and manager_id or manager and template') end - it 'cannot change service_type or prov_type' do - updated_catalog_item_options[:prov_type] = 'new type' - expect do - @catalog_item.update_catalog_item(updated_catalog_item_options) - end.to raise_error(StandardError, 'service_type and prov_type cannot be changed') - end - it 'can accept manager and template objects on update' do updated_catalog_item_options[:config_info].delete(:manager_id) updated_catalog_item_options[:config_info].delete(:manager_id) @@ -226,6 +219,13 @@ expect(updated.orchestration_template).to eq(new_template) expect(updated.orchestration_manager).to eq(new_manager) end + + it 'allows for update without the presence of config_info' do + expect do + @catalog_item.update_catalog_item(:name => 'new_name') + end.to change(@catalog_item, :name) + expect(@catalog_item.reload.name).to eq('new_name') + end end describe '#config_info' do diff --git a/spec/models/service_template_spec.rb b/spec/models/service_template_spec.rb index f8edc58d6f6..8cd4f7c7208 100644 --- a/spec/models/service_template_spec.rb +++ b/spec/models/service_template_spec.rb @@ -615,10 +615,32 @@ expect(updated.config_info).to eq(updated_catalog_item_options[:config_info]) end - it 'does not allow service_type and prov_type to be changed' do + it 'does not allow service_type to be changed' do expect do @catalog_item.update_catalog_item({:service_type => 'new'}, user) - end.to raise_error(StandardError, /service_type and prov_type cannot be changed/) + end.to raise_error(StandardError, /service_type cannot be changed/) + end + + it 'does not allow prov_type to be changed' do + expect do + @catalog_item.update_catalog_item({:prov_type => 'new'}, user) + end.to raise_error(StandardError, /prov_type cannot be changed/) + end + + it 'accepts prov_type and service_type if they are not changed' do + expect do + @catalog_item.update_catalog_item({:name => 'new_name', + :service_type => @catalog_item.service_type, + :prov_type => @catalog_item.prov_type}, user) + end.to change(@catalog_item, :name) + expect(@catalog_item.reload.name).to eq('new_name') + end + + it 'allows for update without the presence of config_info' do + expect do + @catalog_item.update_catalog_item(:name => 'new_name') + end.to change(@catalog_item, :name) + expect(@catalog_item.reload.name).to eq('new_name') end end