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
Hilda Stastna committed Sep 18, 2019
1 parent 6ad912d commit 8b5e292
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 25 deletions.
3 changes: 1 addition & 2 deletions app/controllers/ops_controller.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
17 changes: 15 additions & 2 deletions app/controllers/restful_redirect_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ 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])
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 +23,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
= render(:partial => 'shared/provider_paused', :locals => {:record => @record})

#main_div
= render(:partial => 'layouts/x_gtl')
3 changes: 1 addition & 2 deletions spec/controllers/ops_controller_spec.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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 8b5e292

Please sign in to comment.