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 22, 2019
1 parent a3bbe07 commit 87ba5f7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 53 deletions.
53 changes: 10 additions & 43 deletions app/services/dialog_local_service.rb
Original file line number Diff line number Diff line change
@@ -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 @@ -55,8 +19,6 @@ def determine_dialog_locals_for_svc_catalog_provision(resource_action, target, f
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)

submit_endpoint, cancel_endpoint = determine_api_endpoints(obj, display_options)

dialog_locals.merge!(
Expand All @@ -78,7 +40,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_class.name
case base_name
when /EmsCluster/
api_collection_name = "clusters"
Expand All @@ -90,7 +52,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 @@ -107,9 +69,14 @@ def determine_api_endpoints(obj, display_options = {})
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
Original file line number Diff line number Diff line change
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",
"private", "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 87ba5f7

Please sign in to comment.