Skip to content

Commit

Permalink
Merge pull request #3507 from hstastna/Add_RBAC_Tagging_Ansible_Crede…
Browse files Browse the repository at this point in the history
…ntials_ui

Add RBAC and Tagging Support to Ansible Credentials
  • Loading branch information
h-kataria authored Mar 5, 2018
2 parents 6109fa1 + 9586334 commit f45a79b
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 6 deletions.
11 changes: 7 additions & 4 deletions app/controllers/ansible_credential_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
4 changes: 4 additions & 0 deletions app/helpers/ansible_credential_helper/textual_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2069,10 +2069,13 @@
new
show
show_list
tagging_edit
),
:post => %w(
button
show_list
tag_edit_form_field_changed
tagging_edit
)
},

Expand Down
46 changes: 44 additions & 2 deletions spec/controllers/ansible_credential_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,7 +17,7 @@
end
end

context "#show_list" do
describe "#show_list" do
subject { get :show_list, :params => {} }
render_views

Expand All @@ -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

0 comments on commit f45a79b

Please sign in to comment.