Skip to content

Commit

Permalink
Allow clicking on individual Providers thru Tenant's summary
Browse files Browse the repository at this point in the history
  • Loading branch information
hstastna committed Sep 19, 2019
1 parent b997b48 commit 3d56794
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 43 deletions.
12 changes: 12 additions & 0 deletions app/controllers/automation_manager_controller.rb
Expand Up @@ -93,6 +93,18 @@ def x_show
generic_x_show
end

# Display provider thru Tenant's textual summary
def show
@explorer = true
@lastaction = 'explorer'

build_accordions_and_trees

self.x_node = "at-#{params[:id]}"
@record = ExtManagementSystem.find_by(:id => params[:id])
generic_x_show
end

def tree_record
@record = case x_active_tree
when :automation_manager_providers_tree then automation_manager_providers_tree_rec
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/ops_controller.rb
Expand Up @@ -45,8 +45,7 @@ def display_providers
:breadcrumb_title => _('Providers'),
:association => :nested_providers,
:parent => @record,
:no_checkboxes => true,
:clickable => false
:no_checkboxes => true
)
end

Expand Down
13 changes: 13 additions & 0 deletions app/controllers/provider_foreman_controller.rb
Expand Up @@ -101,6 +101,19 @@ def load_or_clear_adv_search
end
end

# Display provider thru Tenant's textual summary
def show
@explorer = true
@lastaction = "explorer"

build_accordions_and_trees

params[:action] = 'tree-select'
provider_node(params[:id], ExtManagementSystem.find_by(:id => params[:id]).type)

render :layout => "application"
end

def x_show
tree_record unless unassigned_configuration_profile?(params[:id])

Expand Down
21 changes: 19 additions & 2 deletions app/controllers/restful_redirect_controller.rb
Expand Up @@ -5,7 +5,19 @@ def index
case params[:model]
when 'ExtManagementSystem'
record = ExtManagementSystem.find_by(:id => params[:id])
record ? redirect_to(polymorphic_path(record)) : handle_missing_record
if record
if %w[ManageIQ::Providers::ConfigurationManager].include?(record.type) || record.type.starts_with?('ManageIQ::Providers::Foreman')
redirect_to(:controller => 'provider_foreman', :action => 'show', :id => params[:id])
elsif %w[ManageIQ::Providers::AnsibleTower::AutomationManager].include?(record.type)
redirect_to(:controller => 'automation_manager', :action => 'show', :id => params[:id])
elsif %w[ManageIQ::Providers::EmbeddedAnsible::AutomationManager].include?(record.type)
redirect_to(:controller => 'ansible_playbook', :action => 'show_list')
else
redirect_to(polymorphic_path(record))
end
else
handle_missing_record
end
when 'ServiceTemplateTransformationPlanRequest'
req = ServiceTemplateTransformationPlanRequest.select(:source_id).find(params[:id])
req ? redirect_to(:controller => 'migration', :action => 'index', :anchor => "plan/#{req.source_id}") : handle_missing_record
Expand All @@ -15,7 +27,12 @@ def index
record = VmOrTemplate.select(:id, :type).find(params[:id])
record ? handle_vm_redirect(record) : handle_missing_record
else
handle_missing_record
if params[:model].starts_with?('ExtManagementSystem')
params[:model], params[:id] = params[:model].split('/')
index
else
handle_missing_record
end
end
end

Expand Down
2 changes: 2 additions & 0 deletions app/helpers/application_helper.rb
Expand Up @@ -327,6 +327,8 @@ def view_to_url(view, parent = nil)
controller = "vm_cloud" if controller == "template_cloud"
controller = "vm_infra" if controller == "template_infra"
controller = 'miq_ae_class' if controller == 'miq_ae_domain'
return url_for_only_path(:controller => 'restful_redirect', :model => 'ExtManagementSystem') if controller == 'ext_management_system'

return url_for_only_path(:controller => controller, :action => action, :id => nil) + "/"
end
else
Expand Down
4 changes: 4 additions & 0 deletions app/views/provider_foreman/show.html.haml
@@ -0,0 +1,4 @@
= render(:partial => 'shared/provider_paused', :locals => {:record => @record})

#main_div
= render(:partial => 'layouts/x_gtl')
45 changes: 27 additions & 18 deletions spec/controllers/automation_manager_controller_spec.rb
Expand Up @@ -95,9 +95,7 @@
end

context "asserts correct privileges" do
before do
login_as user_with_feature %w(automation_manager_provider_tag)
end
before { login_as user_with_feature %w[automation_manager_provider_tag] }

it "should raise an error for feature that user has no access to" do
expect { controller.send(:assert_privileges, "automation_manager_add_provider") }
Expand Down Expand Up @@ -126,10 +124,8 @@
expect(assigns(:flash_array).first[:message]).to include("has already been taken")
end

context "#edit" do
before do
stub_user(:features => :all)
end
describe "#edit" do
before { stub_user(:features => :all) }

it "renders the edit page when the manager id is supplied" do
post :edit, :params => { :id => @automation_manager1.id }
Expand Down Expand Up @@ -170,7 +166,7 @@
end
end

context "#refresh" do
describe "#refresh" do
before do
stub_user(:features => :all)
allow(controller).to receive(:x_node).and_return("root")
Expand All @@ -197,10 +193,8 @@
end
end

context "#delete" do
before do
stub_user(:features => :all)
end
describe "#delete" do
before { stub_user(:features => :all) }

it "deletes the provider when the manager id is supplied" do
allow(controller).to receive(:replace_right_cell)
Expand Down Expand Up @@ -239,6 +233,7 @@
allow(controller).to receive(:current_page).and_return(1)
controller.send(:build_accordions_and_trees)
end

it "renders right cell text for root node" do
controller.send(:get_node_info, "root")
right_cell_text = controller.instance_variable_get(:@right_cell_text)
Expand All @@ -248,9 +243,7 @@
context 'searching text' do
let(:search) { "some_text" }

before do
controller.instance_variable_set(:@search_text, search)
end
before { controller.instance_variable_set(:@search_text, search) }

it 'updates right cell text according to search text' do
controller.send(:get_node_info, "root")
Expand Down Expand Up @@ -510,6 +503,7 @@
login_as user_with_feature(%w(automation_manager_providers automation_manager_cs_filter_accord automation_manager_configuration_scripts_accord))
controller.instance_variable_set(:@right_cell_text, nil)
end

render_views

it 'can render details for a job template' do
Expand Down Expand Up @@ -567,7 +561,7 @@
end
end

context "#build_credentials" do
describe "#build_credentials" do
it "uses params[:default_password] for validation if one exists" do
controller.params = {:default_userid => "userid",
:default_password => "password2"}
Expand All @@ -589,6 +583,7 @@
@user = user_with_feature %w(automation_manager_providers automation_manager_configured_system)
login_as @user
end

it "builds foreman tree with no nodes after rbac filtering" do
user_filters = {'belongs' => [], 'managed' => [tags]}
allow(@user).to receive(:get_filters).and_return(user_filters)
Expand All @@ -598,7 +593,7 @@
end
end

context "#configscript_service_dialog" do
describe "#configscript_service_dialog" do
before do
stub_user(:features => :all)
@cs = FactoryBot.create(:ansible_configuration_script)
Expand Down Expand Up @@ -631,8 +626,9 @@
end
end

context "#tags_edit" do
describe "#tags_edit" do
let!(:user) { stub_user(:features => :all) }

before do
EvmSpecHelper.create_guid_miq_server_zone
allow(@ans_configured_system).to receive(:tagged_with).with(:cat => user.userid).and_return("my tags")
Expand Down Expand Up @@ -674,6 +670,19 @@
end
end

describe '#show' do
before { controller.params = {:id => @automation_manager1.id} }

it 'displays Automation Manager provider thru Tenants textual summary' do
expect(controller).to receive(:build_accordions_and_trees)
expect(controller).to receive(:generic_x_show)
controller.send(:show)
expect(controller.instance_variable_get(:@explorer)).to be(true)
expect(controller.instance_variable_get(:@record)).to eq(@automation_manager1)
expect(controller.x_node).to eq("at-#{controller.params[:id]}")
end
end

def find_treenode_for_provider(provider, tree)
key = ems_key_for_provider(provider)
tree[0][:nodes]&.find { |c| c['key'] == key }
Expand Down
3 changes: 1 addition & 2 deletions spec/controllers/ops_controller_spec.rb
Expand Up @@ -557,8 +557,7 @@
:breadcrumb_title => _('Providers'),
:association => :nested_providers,
:parent => record,
:no_checkboxes => true,
:clickable => false
:no_checkboxes => true
}
end

Expand Down
43 changes: 26 additions & 17 deletions spec/controllers/provider_foreman_controller_spec.rb
Expand Up @@ -100,9 +100,7 @@
end

context "asserts correct privileges" do
before do
login_as user_with_feature %w(configured_system_provision)
end
before { login_as user_with_feature %w[configured_system_provision] }

it "should not raise an error for feature that user has access to" do
expect { controller.send(:assert_privileges, "configured_system_provision") }.not_to raise_error
Expand Down Expand Up @@ -148,10 +146,8 @@
expect(assigns(:flash_array).last[:message]).to include("Name has already been taken")
end

context "#edit" do
before do
stub_user(:features => :all)
end
describe "#edit" do
before { stub_user(:features => :all) }

it "renders the edit page when the configuration manager id is supplied" do
post :edit, :params => { :id => @config_mgr.id }
Expand Down Expand Up @@ -205,7 +201,7 @@
end
end

context "#refresh" do
describe "#refresh" do
before do
stub_user(:features => :all)
allow(controller).to receive(:x_node).and_return("root")
Expand All @@ -232,10 +228,8 @@
end
end

context "#delete" do
before do
stub_user(:features => :all)
end
describe "#delete" do
before { stub_user(:features => :all) }

it "deletes the provider when the configuration manager id is supplied" do
allow(controller).to receive(:replace_right_cell)
Expand Down Expand Up @@ -593,7 +587,7 @@
end
end

context "#build_credentials" do
describe "#build_credentials" do
it "uses params[:default_password] for validation if one exists" do
controller.params = {:default_userid => "userid",
:default_password => "password2"}
Expand All @@ -611,9 +605,8 @@
end

context "when user with specific tag settings logs in" do
before do
login_as user_with_feature %w(providers_accord configured_systems_filter_accord)
end
before { login_as user_with_feature %w[providers_accord configured_systems_filter_accord] }

it "builds foreman tree with no nodes after rbac filtering" do
user_filters = {'belongs' => [], 'managed' => [tags]}
allow_any_instance_of(User).to receive(:get_filters).and_return(user_filters)
Expand Down Expand Up @@ -649,8 +642,9 @@
end
end

context "#tags_edit" do
describe "#tags_edit" do
let!(:user) { stub_user(:features => :all) }

before do
EvmSpecHelper.create_guid_miq_server_zone
allow(@configured_system).to receive(:tagged_with).with(:cat => user.userid).and_return("my tags")
Expand Down Expand Up @@ -729,6 +723,21 @@
end
end

describe '#show' do
let!(:foreman) { FactoryBot.create(:configuration_manager) }

before { controller.params = {:id => foreman.id} }

it 'displays Satellite provider thru Tenants textual summary' do
expect(controller).to receive(:provider_node).with(controller.params[:id], 'ManageIQ::Providers::Foreman::ConfigurationManager')
expect(controller).to receive(:build_accordions_and_trees)
expect(controller).to receive(:render).with(:layout => 'application')
controller.send(:show)
expect(controller.instance_variable_get(:@explorer)).to be(true)
expect(controller.params[:action]).to eq('tree-select')
end
end

def find_treenode_for_foreman_provider(tree, provider)
key = ems_key_for_provider(provider)
tree.tree_nodes[0][:nodes]&.find { |c| c[:key] == key }
Expand Down
13 changes: 11 additions & 2 deletions spec/helpers/application_helper_spec.rb
Expand Up @@ -1294,15 +1294,24 @@ def controller
end

describe '#view_to_url' do
before { allow(helper).to receive(:url_for_only_path).and_call_original }

context 'displaying Automate Domain thru Tenant summary' do
let(:view) { MiqReport.new(:db => 'MiqAeDomain') }

before { allow(helper).to receive(:url_for_only_path).and_call_original }

it 'sets controller to miq_ae_class and returns proper url' do
expect(helper).to receive(:url_for_only_path).with(:controller => 'miq_ae_class', :action => 'show', :id => nil)
helper.view_to_url(view)
end
end

context 'displaying Provider thru Tenant summary' do
let(:view) { MiqReport.new(:db => 'ExtManagementSystem') }

it 'sets controller to miq_ae_class and returns proper url' do
expect(helper).to receive(:url_for_only_path).with(:controller => 'restful_redirect', :model => 'ExtManagementSystem')
helper.view_to_url(view)
end
end
end
end
13 changes: 13 additions & 0 deletions spec/views/provider_foreman/show.html.haml_spec.rb
@@ -0,0 +1,13 @@
describe 'provider_foreman/show.html.haml' do
helper(GtlHelper)

let(:foreman) { FactoryBot.create(:configuration_manager) }

before { assign(:record, foreman) }

it 'renders show template' do
expect(view).to receive(:render_gtl_outer)
render
expect(view).to render_template(:partial => 'shared/provider_paused', :locals => {:record => foreman})
end
end

0 comments on commit 3d56794

Please sign in to comment.