Skip to content

Commit

Permalink
Merge pull request #3721 from hstastna/Tagging_Ansible_Incorrect_tag_…
Browse files Browse the repository at this point in the history
…page_playbooks_through_repo

Fix opening incorrect tag page, opened for Ansible Playbooks navigated through Repository summary page
(cherry picked from commit 09a453a)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1583779
  • Loading branch information
martinpovolny authored and simaishi committed May 29, 2018
1 parent 3943aa0 commit 8680d2f
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app/controllers/ansible_credential_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class AnsibleCredentialController < ApplicationController
include Mixins::EmbeddedAnsibleRefreshMixin

menu_section :ansible_credentials
toolbar :ansible_credential

def self.display_methods
%w(repositories)
Expand All @@ -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

Expand Down
1 change: 0 additions & 1 deletion app/controllers/ansible_playbook_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/ansible_repository_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class AnsibleRepositoryController < ApplicationController
include Mixins::EmbeddedAnsibleRefreshMixin

menu_section :ansible_repositories
toolbar :ansible_repository

def self.display_methods
%w(playbooks)
Expand Down Expand Up @@ -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

Expand Down
20 changes: 20 additions & 0 deletions app/helpers/application_helper/toolbar_chooser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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'
Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions spec/controllers/ansible_credential_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
5 changes: 5 additions & 0 deletions spec/controllers/ansible_playbook_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 20 additions & 2 deletions spec/controllers/ansible_repository_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
34 changes: 34 additions & 0 deletions spec/helpers/application_helper/toolbar_chooser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8680d2f

Please sign in to comment.