diff --git a/app/controllers/ansible_credential_controller.rb b/app/controllers/ansible_credential_controller.rb index 438f4b644e7..271b8831e08 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 @@ -54,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 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 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 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 ) }, 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