Skip to content

Commit

Permalink
Merge pull request ManageIQ#15657 from hstastna/Ansible_tower_job_tem…
Browse files Browse the repository at this point in the history
…plates_filters_EUWE

[EUWE] Display Ansible tower job templates filters
  • Loading branch information
simaishi authored Jul 31, 2017
2 parents 7a03762 + c837b73 commit f956391
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ def display_adv_search?
ems_container vm miq_template offline retired templates
host service storage ems_cloud ems_cluster flavor
ems_network security_group floating_ip cloud_subnet network_router network_port cloud_network
load_balancer provider_foreman
load_balancer provider_foreman configuration_scripts
ems_storage cloud_volume cloud_object_store_container
resource_pool ems_infra ontap_storage_system ontap_storage_volume
ontap_file_share snia_local_file_system ontap_logical_disk
Expand Down
15 changes: 15 additions & 0 deletions app/models/miq_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ def self.visible_to_all
where("search_type=? or (search_type=? and (search_key is null or search_key<>?))", "global", "default", "_hidden_")
end

def self.visible_to_current_user
where(:search_type => 'user', :search_key => User.current_user.userid)
end

def self.filters_by_type(type)
case type
when "global" # Global filters
visible_to_all
when "my" # My filters
visible_to_current_user
else
raise "Error: #{type} is not a proper filter type!"
end
end

def self.get_expressions_by_model(db)
get_expressions(:db => db.to_s)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,34 @@ def root_options

# Get root nodes count/array for explorer tree
def x_get_tree_roots(count_only, _options)
count_only_or_objects(count_only,
Rbac.filtered(ManageIQ::Providers::AnsibleTower::ConfigurationManager.order("lower(name)"),
:match_via_descendants => ConfigurationScript), "name")
objects = []
templates = Rbac.filtered(ManageIQ::Providers::AnsibleTower::ConfigurationManager.order("lower(name)"),
:match_via_descendants => ConfigurationScript)

templates.each do |temp|
objects.push(temp)
end

objects.push(:id => "global",
:text => _("Global Filters"),
:image => "folder",
:tip => _("Global Shared Filters"),
:cfmeNoClick => true)
objects.push(:id => "my",
:text => _("My Filters"),
:image => "folder",
:tip => _("My Personal Filters"),
:cfmeNoClick => true)
count_only_or_objects(count_only, objects)
end

def x_get_tree_cmat_kids(object, count_only)
count_only_or_objects(count_only,
Rbac.filtered(ManageIQ::Providers::AnsibleTower::ConfigurationManager::ConfigurationScript.where(:manager_id => object.id)), "name")
end

def x_get_tree_custom_kids(object, count_only, options)
objects = MiqSearch.where(:db => options[:leaf]).filters_by_type(object[:id])
count_only_or_objects(count_only, objects, 'description')
end
end
4 changes: 2 additions & 2 deletions app/views/layouts/listnav/_explorer.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#accordion.panel-group
- if @accords.length == 1 # there is no need for JavaScript if only one accordion is present
- if @accords.present? && @accords.length == 1 # there is no need for JavaScript if only one accordion is present
.panel.panel-default
.panel-heading
%h4.panel-title
Expand All @@ -8,7 +8,7 @@
.panel-collapse.collapse.in
.panel-body{:id => @accords.first[:container]}
= render :partial => 'shared/explorer_tree', :locals => {:name => @accords.first[:name]}
- elsif @accords.length > 1
- elsif @accords.present? && @accords.length > 1
- accord_names = @accords.map { |accord| accord[:name].to_sym }
- @accords.each_with_index do |a, i|
= miq_accordion_panel(a[:title], accord_names.include?(@sb[:active_accord]) ? a[:name].to_sym == @sb[:active_accord] : i == 0, a[:container]) do
Expand Down
23 changes: 15 additions & 8 deletions spec/controllers/provider_foreman_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,14 @@
end

it "builds ansible tower child tree" do
config_ans = ManageIQ::Providers::AnsibleTower::ConfigurationManager.find_by(:provider_id => @provider_ans.id)
config_ans2 = ManageIQ::Providers::AnsibleTower::ConfigurationManager.find_by(:provider_id => @provider_ans2.id)
user = login_as user_with_feature(%w(configuration_manager_providers providers_accord configured_systems_filter_accord configuration_scripts_accord))
allow(User).to receive(:current_user).and_return(user)
controller.send(:build_configuration_manager_tree, :providers, :configuration_manager_providers_tree)
tree_builder = TreeBuilderConfigurationManager.new("root", "", {})
objects = tree_builder.send(:x_get_tree_custom_kids, {:id => "at"}, false, {})
expected_objects = [@config_ans, @config_ans2]
expected_objects = [config_ans, config_ans2]
expect(objects).to match_array(expected_objects)
end

Expand All @@ -350,21 +354,24 @@
end

it "builds ansible tower job templates tree" do
user = login_as user_with_feature(%w(configuration_manager_providers providers_accord configured_systems_filter_accord configuration_scripts_accord))
allow(User).to receive(:current_user).and_return(user)
controller.send(:build_configuration_manager_tree, :configuration_scripts, :configuration_scripts_tree)
tree_builder = TreeBuilderConfigurationManagerConfigurationScripts.new("root", "", {})
objects = tree_builder.send(:x_get_tree_roots, false, {})
expected_objects = [@config_ans, @config_ans2]
expect(objects).to match_array(expected_objects)
expect(objects).to include(@config_ans)
expect(objects).to include(@config_ans2)
end

it "constructs the ansible tower job templates tree node" do
login_as user_with_feature(%w(providers_accord configured_systems_filter_accord configuration_scripts_accord))
user = login_as user_with_feature(%w(providers_accord configured_systems_filter_accord configuration_scripts_accord))
allow(User).to receive(:current_user).and_return(user)
controller.send(:build_configuration_manager_tree, :configuration_scripts, :configuration_scripts_tree)
tree_builder = TreeBuilderConfigurationManagerConfigurationScripts.new("root", "", {})
objects = tree_builder.send(:x_get_tree_roots, false, {})
objects = tree_builder.send(:x_get_tree_cmat_kids, objects[0], false)
expected_objects = [@ans_job_template1, @ans_job_template3]
expect(objects).to match_array(expected_objects)
root_objects = tree_builder.send(:x_get_tree_roots, false, {})
objects = tree_builder.send(:x_get_tree_cmat_kids, root_objects[1], false)
expect(objects).to include(@ans_job_template1)
expect(objects).to include(@ans_job_template3)
end

context "renders tree_select" do
Expand Down

0 comments on commit f956391

Please sign in to comment.