From 2900b7e7cc6f7050d3ae22a33261c58b9ff117a5 Mon Sep 17 00:00:00 2001 From: Hilda Stastna Date: Fri, 2 Mar 2018 14:39:39 +0100 Subject: [PATCH 1/6] Add Policy button to enable tagging in Ansible Credentials Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1526219 Add Policy toolbar button to enable tagging in Automation > Ansible > Credentials. --- .../toolbar/ansible_credentials_center.rb | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/helpers/application_helper/toolbar/ansible_credentials_center.rb b/app/helpers/application_helper/toolbar/ansible_credentials_center.rb index 31d42483605..35b05c0bdc5 100644 --- a/app/helpers/application_helper/toolbar/ansible_credentials_center.rb +++ b/app/helpers/application_helper/toolbar/ansible_credentials_center.rb @@ -38,4 +38,26 @@ class ApplicationHelper::Toolbar::AnsibleCredentialsCenter < ApplicationHelper:: ] ) ]) + button_group('embedded_ansible_credentials_policy', [ + select( + :embedded_ansible_credentials_policy_choice, + 'fa fa-shield fa-lg', + t = N_('Policy'), + t, + :enabled => false, + :onwhen => "1+", + :items => [ + button( + :ansible_credential_tag, + 'pficon pficon-edit fa-lg', + N_('Edit Tags for the selected Ansible Credentials'), + N_('Edit Tags'), + :url_parms => "main_div", + :send_checked => true, + :enabled => false, + :onwhen => "1+" + ), + ] + ) + ]) end From 60c6d6a1a02a698f8b5c6141159aa299f39565c4 Mon Sep 17 00:00:00 2001 From: Hilda Stastna Date: Fri, 2 Mar 2018 15:11:32 +0100 Subject: [PATCH 2/6] Add tagging_edit to routes to enable tagging for Ansible Credentials Add also tag_edit_form_field_changed for proper rendering of tagging screen. --- config/routes.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/routes.rb b/config/routes.rb index 35a7875bd9c..28c48077a42 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2069,10 +2069,13 @@ new show show_list + tagging_edit ), :post => %w( button show_list + tag_edit_form_field_changed + tagging_edit ) }, From f2ba7a4fdc0b9429d382161d6593c86ffd1501a9 Mon Sep 17 00:00:00 2001 From: Hilda Stastna Date: Fri, 2 Mar 2018 17:51:02 +0100 Subject: [PATCH 3/6] Add calling tag method to ansible credential controller Add calling tag method to button method in ansible credential controller and also small refactoring of button method, for tagging support of Ansible Credentials. --- app/controllers/ansible_credential_controller.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/controllers/ansible_credential_controller.rb b/app/controllers/ansible_credential_controller.rb index 438f4b644e7..11708d222b1 100644 --- a/app/controllers/ansible_credential_controller.rb +++ b/app/controllers/ansible_credential_controller.rb @@ -26,12 +26,15 @@ def display_repositories end def button - if params[:pressed] == 'embedded_automation_manager_credentials_add' + case params[:pressed] + when 'embedded_automation_manager_credentials_add' javascript_redirect :action => 'new' - elsif params[:pressed] == 'embedded_automation_manager_credentials_edit' + when 'embedded_automation_manager_credentials_edit' javascript_redirect :action => 'edit', :id => params[:miq_grid_checks] - elsif params[:pressed] == 'embedded_automation_manager_credentials_delete' + when 'embedded_automation_manager_credentials_delete' delete_credentials + when 'ansible_credential_tag' + tag(self.class.model) end end From 20ef4db79bda0c9dfe563cfac7b3302e83d8b2cb Mon Sep 17 00:00:00 2001 From: Hilda Stastna Date: Fri, 2 Mar 2018 20:14:17 +0100 Subject: [PATCH 4/6] Add displaying tags to summary screen of a credential Add displaying tags in the table in summary screen of a chosen credential, in Automation > Ansible > Credentials. --- app/controllers/ansible_credential_controller.rb | 2 +- app/helpers/ansible_credential_helper/textual_summary.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/ansible_credential_controller.rb b/app/controllers/ansible_credential_controller.rb index 11708d222b1..271b8831e08 100644 --- a/app/controllers/ansible_credential_controller.rb +++ b/app/controllers/ansible_credential_controller.rb @@ -57,7 +57,7 @@ def edit private def textual_group_list - [%i(properties relationships options)] + [%i(properties relationships options smart_management)] end helper_method :textual_group_list diff --git a/app/helpers/ansible_credential_helper/textual_summary.rb b/app/helpers/ansible_credential_helper/textual_summary.rb index 0a7facdb17b..204cf938f20 100644 --- a/app/helpers/ansible_credential_helper/textual_summary.rb +++ b/app/helpers/ansible_credential_helper/textual_summary.rb @@ -29,6 +29,10 @@ def textual_group_options TextualGroup.new(_("Credential Options"), options) end + def textual_group_smart_management + TextualTags.new(_("Smart Management"), %i(tags)) + end + def textual_type {:label => _("Authentication Type"), :value => ui_lookup(:model => @record.type)} end From c5305c4bb6f25a8e7b36357e93c65af92334c4d1 Mon Sep 17 00:00:00 2001 From: Hilda Stastna Date: Mon, 5 Mar 2018 10:31:58 +0100 Subject: [PATCH 5/6] Add Policy button to enable tagging of Ansible Credential Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1526219 Add Policy toolbar button to enable tagging of any Ansible Credential from its summary page. --- .../toolbar/ansible_credential_center.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/helpers/application_helper/toolbar/ansible_credential_center.rb b/app/helpers/application_helper/toolbar/ansible_credential_center.rb index e32ce515280..7fd91425401 100644 --- a/app/helpers/application_helper/toolbar/ansible_credential_center.rb +++ b/app/helpers/application_helper/toolbar/ansible_credential_center.rb @@ -24,4 +24,20 @@ class ApplicationHelper::Toolbar::AnsibleCredentialCenter < ApplicationHelper::T ] ), ]) + button_group('embedded_ansible_credentials_policy', [ + select( + :embedded_ansible_credentials_policy_choice, + 'fa fa-shield fa-lg', + t = N_('Policy'), + t, + :items => [ + button( + :ansible_credential_tag, + 'pficon pficon-edit fa-lg', + N_('Edit Tags for the selected Ansible Credentials'), + N_('Edit Tags'), + ), + ] + ) + ]) end From 95863349d307f6ff4776f13eaba9c9c9092ac31d Mon Sep 17 00:00:00 2001 From: Hilda Stastna Date: Mon, 5 Mar 2018 13:04:37 +0100 Subject: [PATCH 6/6] Add spec test for button method in ansible credential controller --- .../ansible_credential_controller_spec.rb | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/spec/controllers/ansible_credential_controller_spec.rb b/spec/controllers/ansible_credential_controller_spec.rb index c06d8458c6d..7c27c21adbc 100644 --- a/spec/controllers/ansible_credential_controller_spec.rb +++ b/spec/controllers/ansible_credential_controller_spec.rb @@ -4,7 +4,7 @@ login_as FactoryGirl.create(:user_admin) end - context "#show" do + describe "#show" do let(:machine_credential) { FactoryGirl.create(:embedded_ansible_scm_credential, :options=>{}) } subject { get :show, :params => {:id => machine_credential.id} } render_views @@ -17,7 +17,7 @@ end end - context "#show_list" do + describe "#show_list" do subject { get :show_list, :params => {} } render_views @@ -29,4 +29,46 @@ is_expected.to render_template(:partial => "layouts/_gtl") end end + + describe '#button' do + before do + controller.instance_variable_set(:@_params, params) + end + + context 'adding a new ansible credential' do + let(:params) { {:pressed => "embedded_automation_manager_credentials_add"} } + + it 'redirects to action new' do + expect(controller).to receive(:javascript_redirect).with(:action => 'new') + controller.send(:button) + end + end + + context 'editing one or more ansible credentials' do + let(:params) { {:pressed => "embedded_automation_manager_credentials_edit"} } + + it 'redirects to action edit' do + expect(controller).to receive(:javascript_redirect).with(:action => 'edit', :id => params[:miq_grid_checks]) + controller.send(:button) + end + end + + context 'deleting one or more ansible credentials from inventory' do + let(:params) { {:pressed => "embedded_automation_manager_credentials_delete"} } + + it 'calls delete_credentials method' do + expect(controller).to receive(:delete_credentials) + controller.send(:button) + end + end + + context 'tagging one or more ansible credentials' do + let(:params) { {:pressed => "ansible_credential_tag"} } + + it 'calls tag method' do + expect(controller).to receive(:tag).with(controller.class.model) + controller.send(:button) + end + end + end end