Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #36974 - show run job button to rex users #858

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 4 additions & 5 deletions app/helpers/remote_execution_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ def template_invocation_actions(task, host, job_invocation, template_invocation)
links << { title: _('Host detail'),
action: { href: current_host_details_path(host), 'data-method': 'get', id: "#{host.name}-actions-detail" } }
end

if authorized_for(hash_for_rerun_job_invocation_path(id: job_invocation, host_ids: [ host.id ], authorizer: job_hosts_authorizer))
if authorized_for(controller: :job_invocations, action: :create) && (!host.infrastructure_host? || User.current.can?(:execute_jobs_on_infrastructure_hosts))
links << { title: (_('Rerun on %s') % host.name),
action: { href: rerun_job_invocation_path(job_invocation, host_ids: [ host.id ]),
'data-method': 'get', id: "#{host.name}-actions-rerun" } }
Expand All @@ -56,7 +55,7 @@ def remote_execution_provider_for(template_invocation)
def job_invocations_buttons
[
documentation_button_rex('3.2ExecutingaJob'),
display_link_if_authorized(_('Run Job'), hash_for_new_job_invocation_path, {:class => "btn btn-primary"}),
authorized_for(controller: :job_invocations, action: :create) ? link_to(_('Run Job'), hash_for_new_job_invocation_path, {:class => "btn btn-primary"}) : '',
]
end

Expand All @@ -70,12 +69,12 @@ def job_invocation_task_buttons(task)
title: _('Create report for this job'),
disabled: task.pending?)
end
if authorized_for(hash_for_new_job_invocation_path)
if authorized_for(controller: :job_invocations, action: :create)
buttons << link_to(_('Rerun'), rerun_job_invocation_path(:id => job_invocation.id),
:class => 'btn btn-default',
:title => _('Rerun the job'))
end
if authorized_for(hash_for_new_job_invocation_path)
if authorized_for(controller: :job_invocations, action: :create)
buttons << link_to(_('Rerun failed'), rerun_job_invocation_path(:id => job_invocation.id, :failed_only => 1),
:class => 'btn btn-default',
:disabled => job_invocation.failed_hosts.none?,
Expand Down
8 changes: 6 additions & 2 deletions lib/foreman_remote_execution/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,11 @@ class Engine < ::Rails::Engine
:'api/v2/job_templates' => [:update],
:'api/v2/template_inputs' => [:create, :update, :destroy],
:'api/v2/foreign_input_sets' => [:create, :update, :destroy]}, :resource_type => 'JobTemplate'
permission :edit_remote_execution_features, { :remote_execution_features => [:index, :show, :update],
:'api/v2/remote_execution_features' => [:index, :show, :update, :available_remote_execution_features]}, :resource_type => 'RemoteExecutionFeature'
permission :view_remote_execution_features, { :remote_execution_features => [:index, :show],
:'api/v2/remote_execution_features' => [:index, :show, :available_remote_execution_features]},
:resource_type => 'RemoteExecutionFeature'
permission :edit_remote_execution_features, { :remote_execution_features => [:update],
:'api/v2/remote_execution_features' => [:update ]}, :resource_type => 'RemoteExecutionFeature'
permission :destroy_job_templates, { :job_templates => [:destroy],
:'api/v2/job_templates' => [:destroy] }, :resource_type => 'JobTemplate'
permission :lock_job_templates, { :job_templates => [:lock, :unlock] }, :resource_type => 'JobTemplate'
Expand All @@ -204,6 +207,7 @@ class Engine < ::Rails::Engine
:create_template_invocations,
:view_hosts,
:view_smart_proxies,
:view_remote_execution_features,
].freeze
MANAGER_PERMISSIONS = USER_PERMISSIONS + [
:cancel_job_invocations,
Expand Down