From 8680d2f0660cb155940789c668bfbc835285e695 Mon Sep 17 00:00:00 2001 From: Martin Povolny Date: Wed, 23 May 2018 17:17:19 +0200 Subject: [PATCH] Merge pull request #3721 from hstastna/Tagging_Ansible_Incorrect_tag_page_playbooks_through_repo Fix opening incorrect tag page, opened for Ansible Playbooks navigated through Repository summary page (cherry picked from commit 09a453a95bf7a68ff5f5d3d4e868cfcdfe04a118) Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1583779 --- .../ansible_credential_controller.rb | 3 +- .../ansible_playbook_controller.rb | 1 - .../ansible_repository_controller.rb | 3 +- .../application_helper/toolbar_chooser.rb | 20 +++++++++++ .../ansible_credential_controller_spec.rb | 18 ++++++++++ .../ansible_playbook_controller_spec.rb | 5 +++ .../ansible_repository_controller_spec.rb | 22 ++++++++++-- .../toolbar_chooser_spec.rb | 34 +++++++++++++++++++ 8 files changed, 101 insertions(+), 5 deletions(-) diff --git a/app/controllers/ansible_credential_controller.rb b/app/controllers/ansible_credential_controller.rb index fb9ed4a4ea1..060e0909fdf 100644 --- a/app/controllers/ansible_credential_controller.rb +++ b/app/controllers/ansible_credential_controller.rb @@ -11,7 +11,6 @@ class AnsibleCredentialController < ApplicationController include Mixins::EmbeddedAnsibleRefreshMixin menu_section :ansible_credentials - toolbar :ansible_credential def self.display_methods %w(repositories) @@ -35,6 +34,8 @@ def button delete_credentials when 'ansible_credential_tag' tag(self.class.model) + when "ansible_repository_tag" # repositories from nested list + tag(ManageIQ::Providers::EmbeddedAutomationManager::ConfigurationScriptSource) end end diff --git a/app/controllers/ansible_playbook_controller.rb b/app/controllers/ansible_playbook_controller.rb index 662c87861a1..65219849682 100644 --- a/app/controllers/ansible_playbook_controller.rb +++ b/app/controllers/ansible_playbook_controller.rb @@ -10,7 +10,6 @@ class AnsiblePlaybookController < ApplicationController include Mixins::GenericShowMixin menu_section :ansible_playbooks - toolbar :ansible_playbook def self.model ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Playbook diff --git a/app/controllers/ansible_repository_controller.rb b/app/controllers/ansible_repository_controller.rb index 0357b0442f8..792032e2835 100644 --- a/app/controllers/ansible_repository_controller.rb +++ b/app/controllers/ansible_repository_controller.rb @@ -11,7 +11,6 @@ class AnsibleRepositoryController < ApplicationController include Mixins::EmbeddedAnsibleRefreshMixin menu_section :ansible_repositories - toolbar :ansible_repository def self.display_methods %w(playbooks) @@ -49,6 +48,8 @@ def button end when "ansible_repository_tag" tag(self.class.model) + when "embedded_configuration_script_payload_tag" # playbooks from nested list + tag(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Playbook) end end diff --git a/app/helpers/application_helper/toolbar_chooser.rb b/app/helpers/application_helper/toolbar_chooser.rb index 85189e33b2d..efb4266bc54 100644 --- a/app/helpers/application_helper/toolbar_chooser.rb +++ b/app/helpers/application_helper/toolbar_chooser.rb @@ -448,7 +448,9 @@ def center_toolbar_filename_classic security_groups storages middleware_deployments middleware_datasources middleware_messagings middleware_servers) to_display_center = %w(stack_orchestration_template topology cloud_object_store_objects generic_objects physical_servers) + to_display_ansible = %w(playbooks repositories credentials) performance_layouts = %w(vm host ems_container) + if @lastaction == 'show' && (@view || @display != 'main') && !@layout.starts_with?("miq_request") if @display == "vms" || @display == "all_vms" return "vm_infras_center_tb" @@ -464,6 +466,8 @@ def center_toolbar_filename_classic return "#{@layout}_center_tb" elsif to_display.include?(@display) return "#{@display}_center_tb" + elsif to_display_ansible.include?(@display) # toolbars for nested list screens of Ansible Playbooks/Repositories/Credentials + return "ansible_#{@display}_center" elsif to_display_center.include?(@display) return "#{@display}_center" elsif @layout == 'ems_container' @@ -560,12 +564,28 @@ def center_toolbar_filename_classic end elsif %w(my_tasks all_tasks).include?(@layout) return "tasks_center_tb" + elsif @layout.to_s.starts_with?("manageiq") # toolbars for list/summary screens of Ansible Playbooks/Repositories/Credentials + return "#{center_toolbar_filename_embedded_ansible}_center" end end end nil end + def center_toolbar_filename_embedded_ansible + case @layout + when "manageiq/providers/embedded_ansible/automation_manager/playbook" + toolbar_filename = "ansible_playbook" + when "manageiq/providers/embedded_automation_manager/configuration_script_source" + toolbar_filename = "ansible_repository" + when "manageiq/providers/embedded_automation_manager/authentication" + toolbar_filename = "ansible_credential" + else + return + end + %w(show_list).include?(@lastaction) ? toolbar_filename.pluralize : toolbar_filename + end + def center_toolbar_filename_configuration_manager_providers nodes = x_node.split('-') if x_active_tree == :configuration_manager_providers_tree diff --git a/spec/controllers/ansible_credential_controller_spec.rb b/spec/controllers/ansible_credential_controller_spec.rb index 918b3700998..825759a7db2 100644 --- a/spec/controllers/ansible_credential_controller_spec.rb +++ b/spec/controllers/ansible_credential_controller_spec.rb @@ -30,6 +30,11 @@ it "renders correct template" do is_expected.to render_template(:partial => "layouts/_gtl") end + + it 'renders the correct toolbar' do + expect(ApplicationHelper::Toolbar::AnsibleCredentialsCenter).to receive(:definition) + post :show_list + end end describe '#button' do @@ -72,5 +77,18 @@ controller.send(:button) end end + + context 'tagging one or more ansible repositories from nested list' do + let(:params) { {:pressed => "ansible_repository_tag"} } + + before do + controller.instance_variable_set(:@display, "repositories") + end + + it 'calls tag method' do + expect(controller).to receive(:tag).with(ManageIQ::Providers::EmbeddedAutomationManager::ConfigurationScriptSource) + controller.send(:button) + end + end end end diff --git a/spec/controllers/ansible_playbook_controller_spec.rb b/spec/controllers/ansible_playbook_controller_spec.rb index 4fdafcc4f87..1f14766dc3d 100644 --- a/spec/controllers/ansible_playbook_controller_spec.rb +++ b/spec/controllers/ansible_playbook_controller_spec.rb @@ -36,6 +36,11 @@ it "renders correct template" do is_expected.to render_template(:partial => "layouts/_gtl") end + + it 'renders the correct toolbar' do + expect(ApplicationHelper::Toolbar::AnsiblePlaybooksCenter).to receive(:definition) + post :show_list + end end describe "#button" do diff --git a/spec/controllers/ansible_repository_controller_spec.rb b/spec/controllers/ansible_repository_controller_spec.rb index cc6234761e8..b73d99f7a04 100644 --- a/spec/controllers/ansible_repository_controller_spec.rb +++ b/spec/controllers/ansible_repository_controller_spec.rb @@ -6,7 +6,7 @@ login_as FactoryGirl.create(:user_admin) end - context "show" do + describe "#show" do let(:repository) { FactoryGirl.create(:embedded_ansible_configuration_script_source) } subject { get :show, :params => {:id => repository.id} } render_views @@ -20,7 +20,7 @@ end end - context "showList" do + describe "#show_list" do let(:repository) { FactoryGirl.create(:embedded_ansible_configuration_script_source) } subject { get :show_list, :params => {} } render_views @@ -32,6 +32,11 @@ it "render view for list of repositories" do is_expected.to render_template(:partial => "layouts/_gtl") end + + it 'renders the correct toolbar' do + expect(ApplicationHelper::Toolbar::AnsibleRepositoriesCenter).to receive(:definition) + post :show_list + end end describe "#show_association" do @@ -123,5 +128,18 @@ controller.send(:button) end end + + context 'tagging one or more playbooks from nested list' do + let(:params) { {:pressed => "embedded_configuration_script_payload_tag"} } + + before do + controller.instance_variable_set(:@display, "playbooks") + end + + it 'calls tag method' do + expect(controller).to receive(:tag).with(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Playbook) + controller.send(:button) + end + end end end diff --git a/spec/helpers/application_helper/toolbar_chooser_spec.rb b/spec/helpers/application_helper/toolbar_chooser_spec.rb index d534b3ca3e7..7d1dc65e4ad 100644 --- a/spec/helpers/application_helper/toolbar_chooser_spec.rb +++ b/spec/helpers/application_helper/toolbar_chooser_spec.rb @@ -173,4 +173,38 @@ end end end + + describe '#center_toolbar_filename_classic' do + subject { chooser.send(:center_toolbar_filename_classic) } + + { + "manageiq/providers/embedded_ansible/automation_manager/playbook" => "playbook", + "manageiq/providers/embedded_automation_manager/configuration_script_source" => "repository", + "manageiq/providers/embedded_automation_manager/authentication" => "credential" + }.each do |layout, screen| + context "toolbar for summary screen of Ansible #{screen}" do + let(:chooser) { ApplicationHelper::ToolbarChooser.new(nil, nil, :display => "main", :lastaction => "show", :layout => layout) } + + it 'returns proper toolbar filename for the screen' do + expect(subject).to eq("ansible_#{screen}_center") + end + end + + context "toolbars for list screens of Ansible #{screen.pluralize}" do + let(:chooser) { ApplicationHelper::ToolbarChooser.new(nil, nil, :lastaction => "show_list", :layout => layout) } + + it 'returns proper toolbar filename for the screen' do + expect(subject).to eq("ansible_#{screen.pluralize}_center") + end + end + + context "toolbars for nested list screens of Ansible #{screen.pluralize}" do + let(:chooser) { ApplicationHelper::ToolbarChooser.new(nil, nil, :display => screen.pluralize, :lastaction => "show", :layout => layout) } + + it 'returns proper toolbar filename for the screen' do + expect(subject).to eq("ansible_#{screen.pluralize}_center") + end + end + end + end end