Skip to content

Commit

Permalink
Fixes #36273 - Use proper permission for editing Ansible variable
Browse files Browse the repository at this point in the history
Add LookupValue permissions to allow editing of Ansible variables,
for non-admin users.

Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
  • Loading branch information
nofaralfasi committed Nov 6, 2023
1 parent 6b2ea73 commit ff31fe2
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AnsibleOverrideValuesController < ::Api::V2::BaseController
param_group :ansible_override_value, :as => :create

def create
@ansible_variable = AnsibleVariable.authorized(:edit_external_variables).
@ansible_variable = AnsibleVariable.authorized(:edit_ansible_variables).
find_by(:id => params[:ansible_variable_id].to_i)
@override_value = @ansible_variable.lookup_values.create!(lookup_value_params['override_value'])
@ansible_variable.update_attribute(:override, true)
Expand Down
2 changes: 1 addition & 1 deletion app/models/ansible_variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def self.humanize_class_name(options = nil)
end

def editable_by_user?
AnsibleVariable.authorized(:edit_external_parameters).
AnsibleVariable.authorized(:edit_ansible_variables).
where(:id => id).exists?
end
end
2 changes: 1 addition & 1 deletion app/views/ansible_variables/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
icon_text((variable.override ? "flag": ""), variable.key.to_s, :kind => 'fa', :title => _('Overriden')),
hash_for_edit_ansible_variable_path(:id => variable).
merge(:auth_object => variable,
:permission => 'edit_external_parameters',
:permission => 'edit_ansible_variables',
:authorizer => authorizer)
) %></td>
<td class="ellipsis"><%= link_to_if_authorized(
Expand Down
3 changes: 2 additions & 1 deletion lib/foreman_ansible/register.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@
:create_job_invocations, :view_job_templates, # to allow the play_roles
:create_template_invocations, :view_smart_proxies, # ...
:view_ansible_roles, :destroy_ansible_roles,
:import_ansible_roles, :view_ansible_variables,
:import_ansible_roles, :view_ansible_variables, :view_lookup_values,
:create_lookup_values, :edit_lookup_values, :destroy_lookup_values,
:create_ansible_variables, :import_ansible_variables,
:edit_ansible_variables, :destroy_ansible_variables, :import_ansible_playbooks]

Expand Down

0 comments on commit ff31fe2

Please sign in to comment.