Skip to content

Commit

Permalink
Use class base_name instead of demodulize
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed Jan 28, 2019
1 parent 6bcbfeb commit 19c7c1d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 57 deletions.
58 changes: 11 additions & 47 deletions app/services/dialog_local_service.rb
@@ -1,40 +1,4 @@
class DialogLocalService
NEW_DIALOG_USERS = %w(
AvailabilityZone
CloudNetwork
CloudObjectStoreContainer
CloudSubnet
CloudTenant
CloudVolume
ContainerGroup
ContainerImage
ContainerNode
ContainerProject
ContainerTemplate
ContainerVolume
EmsCluster
GenericObject
Host
InfraManager
LoadBalancer
MiqGroup
NetworkRouter
OrchestrationStack
SecurityGroup
Service
ServiceAnsiblePlaybook
ServiceAnsibleTower
ServiceContainerTemplate
ServiceGeneric
ServiceOrchestration
Storage
Switch
Template
Tenant
User
Vm
).freeze

def determine_dialog_locals_for_svc_catalog_provision(resource_action, target, finish_submit_endpoint)
api_submit_endpoint = "/api/service_catalogs/#{target.service_template_catalog_id}/service_templates/#{target.id}"

Expand All @@ -53,10 +17,7 @@ def determine_dialog_locals_for_svc_catalog_provision(resource_action, target, f
end

def determine_dialog_locals_for_custom_button(obj, button_name, resource_action, display_options = {})
dialog_locals = {:force_old_dialog_use => true}

return dialog_locals unless NEW_DIALOG_USERS.include?(obj.class.name.demodulize)

dialog_locals = {}
submit_endpoint, cancel_endpoint = determine_api_endpoints(obj, display_options)

dialog_locals.merge!(
Expand All @@ -78,7 +39,7 @@ def determine_dialog_locals_for_custom_button(obj, button_name, resource_action,
private

def determine_api_endpoints(obj, display_options = {})
base_name = obj.class.name.demodulize
base_name = obj.class.base_model.name
case base_name
when /EmsCluster/
api_collection_name = "clusters"
Expand All @@ -90,7 +51,7 @@ def determine_api_endpoints(obj, display_options = {})
else
"/service/explorer"
end
when /InfraManager/
when /ExtManagementSystem/
api_collection_name = "providers"
cancel_endpoint = "/ems_infra"
when /MiqGroup/
Expand All @@ -105,11 +66,14 @@ def determine_api_endpoints(obj, display_options = {})
when /Switch/
api_collection_name = "switches"
cancel_endpoint = "/infra_networking/explorer"

# ^ is necessary otherwise we match on ContainerTemplates
when /^Template/
api_collection_name = "templates"
cancel_endpoint = display_options[:cancel_endpoint] || "/vm_or_template/explorer"
when /VmOrTemplate/
if obj.class.name.demodulize == "Vm"
api_collection_name = "vms"
cancel_endpoint = display_options[:cancel_endpoint] || "/vm_infra/explorer"
else
api_collection_name = "templates"
cancel_endpoint = display_options[:cancel_endpoint] || "/vm_or_template/explorer"
end

# ^ is necessary otherwise we match CloudTenant
when /^Tenant/
Expand Down
24 changes: 14 additions & 10 deletions spec/services/dialog_local_service_spec.rb
Expand Up @@ -77,6 +77,13 @@
"cloud_network", "cloud_networks", "/cloud_network"
end

context "when the object is a private CloudNetwork" do
let(:obj) { double(:class => ManageIQ::Providers::Openstack::NetworkManager::CloudNetwork::Private, :id => 123) }

include_examples "DialogLocalService#determine_dialog_locals_for_custom_button return value",
"cloud_networks", "cloud_networks", "/cloud_network"
end

context "when the object is a CloudObjectStoreContainer" do
let(:obj) { double(:class => ManageIQ::Providers::Amazon::StorageManager::S3::CloudObjectStoreContainer, :id => 123) }

Expand Down Expand Up @@ -168,6 +175,13 @@
"host", "hosts", "/host"
end

context "when the object is a HostEsx" do
let(:obj) { double(:class => ManageIQ::Providers::Vmware::InfraManager::HostEsx, :id => 123) }

include_examples "DialogLocalService#determine_dialog_locals_for_custom_button return value",
"host_esx", "hosts", "/host"
end

context "when the object is an InfraManager" do
let(:obj) { double(:class => ManageIQ::Providers::Vmware::InfraManager, :id => 123) }

Expand Down Expand Up @@ -292,15 +306,5 @@
"vm", "vms", "/vm_infra/explorer"
end
end

context "when the object does not support new dialogs" do
let(:obj) { double(:id => 123) }

it "returns a hash with 'force_old_dialog_use' set to true" do
expect(service.determine_dialog_locals_for_custom_button(obj, button_name, resource_action)).to eq(
:force_old_dialog_use => true
)
end
end
end
end

0 comments on commit 19c7c1d

Please sign in to comment.