Skip to content

Commit

Permalink
Merge pull request ManageIQ#8998 from kbrock/network_vms
Browse files Browse the repository at this point in the history
filter vms displayed in tree lan
  • Loading branch information
jeffibm authored Jan 9, 2024
2 parents babdf56 + 491e2d4 commit 325850d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 6 additions & 9 deletions app/presenters/tree_builder_network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,18 @@ def root_options
end

def x_get_tree_roots
@root.switches.empty? ? [] : count_only_or_objects(false, @root.switches)
Rbac.filtered(@root.switches)
end

def x_get_tree_switch_kids(parent, count_only)
objects = []
objects.concat(parent.guest_devices) unless parent.guest_devices.empty?
objects.concat(parent.lans) unless parent.lans.empty?
count_only_or_objects(count_only, objects)
count_only_or_objects_filtered(count_only, parent.guest_devices) + count_only_or_objects_filtered(count_only, parent.lans)
end

def x_get_tree_lan_kids(parent, count_only)
kids = count_only ? 0 : []
if parent.respond_to?("vms_and_templates") && parent.vms_and_templates.present?
kids = count_only_or_objects(count_only, parent.vms_and_templates, "name")
if parent.respond_to?(:vms_and_templates)
count_only_or_objects_filtered(count_only, parent.vms_and_templates, "name")
else
count_only ? 0 : []
end
kids
end
end
2 changes: 2 additions & 0 deletions spec/presenters/tree_builder_network_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
describe TreeBuilderNetwork do
context 'TreeBuilderNetwork' do
before do
EvmSpecHelper.local_miq_server
role = MiqUserRole.find_by(:name => "EvmRole-operator")
@group = FactoryBot.create(:miq_group, :miq_user_role => role, :description => "Network Group")
login_as FactoryBot.create(:user, :userid => 'network_wilma', :miq_groups => [@group])
Expand Down Expand Up @@ -37,6 +38,7 @@
end

it 'returns Vm as Lan child' do
EvmSpecHelper.local_miq_server
parent = @network_tree.send(:x_get_tree_roots).first.lans.first
kid = @network_tree.send(:x_get_tree_lan_kids, parent, false)
expect(kid.first).to be_a_kind_of(Vm)
Expand Down

0 comments on commit 325850d

Please sign in to comment.