Skip to content

Commit

Permalink
Include reflections of descendant classes when building model details…
Browse files Browse the repository at this point in the history
… for reporting and expression editors

- Enabled only for Vm and Host models
- Enables inclusion of cloud tenants under an openstack VM in reports and expressions
- Enables inclusion of cloud networks under an openstack Host

https://bugzilla.redhat.com/show_bug.cgi?id=1236001
  • Loading branch information
gtanzillo committed Nov 20, 2015
1 parent 4357cb4 commit a7597b6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/models/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ def settings
before_create :make_smart
after_save :process_events

def self.include_descendant_classes_in_expressions?
true
end

def authentication_check_role
'smartstate'
end
Expand Down
9 changes: 7 additions & 2 deletions app/models/miq_expression.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,7 @@ def self.miq_adv_search_lists(model, what)
case what.to_sym
when :exp_available_fields then @miq_adv_search_lists[model.to_s][:exp_available_fields] ||= MiqExpression.model_details(model, :typ => "field", :include_model => true)
when :exp_available_counts then @miq_adv_search_lists[model.to_s][:exp_available_counts] ||= MiqExpression.model_details(model, :typ => "count", :include_model => true)
when :exp_available_finds then @miq_adv_search_lists[model.to_s][:exp_available_finds] ||= MiqExpression.model_details(model, :typ => "find", :include_model => true)
when :exp_available_finds then @miq_adv_search_lists[model.to_s][:exp_available_finds] ||= MiqExpression.model_details(model, :typ => "find", :include_model => true)
end
end

Expand Down Expand Up @@ -1496,7 +1496,12 @@ def self.build_relats(model, parent = {}, seen = [])
result = {:columns => model.column_names_with_virtual, :parent => parent}
result[:reflections] = {}

model.reflections_with_virtual.each do |assoc, ref|
refs = model.reflections_with_virtual
if model.try(:include_descendant_classes_in_expressions?)
model.descendants.each { |desc| refs.reverse_merge!(desc.reflections_with_virtual) }
end

refs.each do |assoc, ref|
next unless @@include_tables.include?(assoc.to_s.pluralize)
next if assoc.to_s.pluralize == "event_logs" && parent[:root] == "Host" && !@@proto
next if assoc.to_s.pluralize == "processes" && parent[:root] == "Host" # Process data not available yet for Host
Expand Down
4 changes: 4 additions & 0 deletions app/models/vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ def self.base_model
Vm
end

def self.include_descendant_classes_in_expressions?
true
end

def self.corresponding_model
if self == Vm
MiqTemplate
Expand Down
5 changes: 5 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,8 @@ en:
ManageIQ::Providers::BaseManager: Provider
#ManageIQ::Providers::BaseManager::VmOrTemplate: VM or Template
#ManageIQ::Providers::BaseManager::Vm: VM and Instance
ManageIQ::Providers::ConfigurationManager: Configuration Manager
ManageIQ::Providers::Foreman::ConfigurationManager::ConfiguredSystem: Foreman Configured System
ManageIQ::Providers::CloudManager: Cloud Provider
ManageIQ::Providers::CloudManager::Vm: Instance
ManageIQ::Providers::CloudManager::Template: Image
Expand Down Expand Up @@ -1031,6 +1033,9 @@ en:
miq_custom_attribute: EVM Custom Attribute
miq_custom_attributes: EVM Custom Attributes
miq_event_definition: Event
manageiq_providers_foreman_configuration_manager_configuration_profile: Configuration Profile (Foreman)
manageiq_providers_openstack_infra_manager_cloud_networks: Cloud Networks (Openstack)
manageiq_providers_openstack_cloud_manager_cloud_tenant: Cloud Tenants (Openstack)
miq_provision: Provision
miq_provision_template: Provisioned From Template
miq_provision_vms: Provisioned VMs
Expand Down
17 changes: 17 additions & 0 deletions spec/models/miq_expression/miq_expression_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,23 @@
end
end

context ".build_relats" do
it "includes reflections from descendant classes of Vm" do
relats = MiqExpression.get_relats(Vm)
relats[:reflections][:cloud_tenant].should_not be_blank
end

it "includes reflections from descendant classes of Host" do
relats = MiqExpression.get_relats(Host)
relats[:reflections][:cloud_networks].should_not be_blank
end

it "excludes reflections from descendant classes of VmOrTemplate " do
relats = MiqExpression.get_relats(VmOrTemplate)
relats[:reflections][:cloud_tenant].should be_blank
end
end

context "Date/Time Support" do
context "Testing expression conversion ruby, sql and human with static dates and times" do
it "should generate the correct ruby expression with an expression having static dates and times with no time zone" do
Expand Down

0 comments on commit a7597b6

Please sign in to comment.