foreman_remote_execution 5.0.1 → 5.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd91f2539393453fe888022502baba8ad7597da50682a4d87a8cf78dcaaebbfa
4
- data.tar.gz: 2c97670fa1b3555f9660ea8adee03e48ae83779aff3324d977eae65a70b86956
3
+ metadata.gz: 59eae566c2961d0c2d5cca855d76ece120748f1c1f6303a5b2fca5928f1b4840
4
+ data.tar.gz: 1cbb8e8f418e8b8c5823b9b875eed46873735da31b5214601acc60f236d650b1
5
5
  SHA512:
6
- metadata.gz: 7fbc26b3be07128f7dd015db03b8e46d34faee8f13f8b7e7f3d6ff54f360afd70cdd6f4143862695342591be55cfed9a74f315ae77ef5231cd20bee5f9bf8565
7
- data.tar.gz: 851d5fd53efb928e8a6ce15468af83bc992b98265bc289f23fed310834e1c83753113e981a673f89e3183efaa7d6f76ec270f06f1f41072f79c045947a78b6c8
6
+ metadata.gz: 77c04207ff68fc2cf97061b77b2d06c40b51f197d2cceb4fa803dc29e2e3512eb4b048131964414f2e29dbc23e2a460b1ff46566718b79e804f7632b375f12ea
7
+ data.tar.gz: d9bf1681d7e5834c3cc16941a90c4c4c73db3d1b4e812c91b88ffe866bcb27f52eae3841a49740f77c50d0f8fd570203ea7f4f5100cc855ea140403cd0bda49e
@@ -8,7 +8,7 @@ module ForemanRemoteExecution
8
8
 
9
9
  def multiple_actions
10
10
  res = super
11
- res += [ [_('Schedule Remote Job'), new_job_invocation_path, false] ] if authorized_for(controller: :job_invocations, action: :new)
11
+ res += [ [_('Schedule Remote Job'), new_job_invocation_path, false] ] if can_schedule_jobs?
12
12
  res
13
13
  end
14
14
 
@@ -22,20 +22,20 @@ module ForemanRemoteExecution
22
22
  end
23
23
  end
24
24
 
25
- def rex_host_features(*args)
26
- return unless authorized_for(controller: :job_invocations, action: :create)
25
+ def rex_host_features(host, *_rest)
26
+ return [] unless can_execute_on_host?(host)
27
27
  RemoteExecutionFeature.with_host_action_button.order(:label).map do |feature|
28
- link_to(_('%s') % feature.name, job_invocations_path(:host_ids => [args.first.id], :feature => feature.label), :method => :post)
28
+ link_to(_('%s') % feature.name, job_invocations_path(:host_ids => [host.id], :feature => feature.label), :method => :post)
29
29
  end
30
30
  end
31
31
 
32
- def schedule_job_button(*args)
33
- return unless authorized_for(controller: :job_invocations, action: :new)
34
- link_to(_('Schedule Remote Job'), new_job_invocation_path(:host_ids => [args.first.id]), :id => :run_button, :class => 'btn btn-default')
32
+ def schedule_job_button(host, *_rest)
33
+ return unless can_execute_on_host?(host)
34
+ link_to(_('Schedule Remote Job'), new_job_invocation_path(:host_ids => [host.id]), :id => :run_button, :class => 'btn btn-default')
35
35
  end
36
36
 
37
37
  def web_console_button(host, *args)
38
- return unless authorized_for(permission: 'cockpit_hosts', auth_object: host)
38
+ return if !authorized_for(permission: 'cockpit_hosts', auth_object: host) || !can_execute_on_infrastructure_host?(host)
39
39
 
40
40
  url = SSHExecutionProvider.cockpit_url_for_host(host.name)
41
41
  url ? link_to(_('Web Console'), url, :class => 'btn btn-default', :id => :'web-console-button', :target => '_new') : nil
@@ -46,6 +46,17 @@ module ForemanRemoteExecution
46
46
  button_group(web_console_button(*args)))
47
47
  super(*args)
48
48
  end
49
- end
50
49
 
50
+ def can_schedule_jobs?
51
+ authorized_for(controller: :job_invocations, action: :create)
52
+ end
53
+
54
+ def can_execute_on_host?(host)
55
+ can_schedule_jobs? && can_execute_on_infrastructure_host?(host)
56
+ end
57
+
58
+ def can_execute_on_infrastructure_host?(host)
59
+ !host.infrastructure_host? || User.current.can?(:execute_jobs_on_infrastructure_hosts)
60
+ end
61
+ end
51
62
  end
@@ -31,7 +31,7 @@ module RemoteExecutionHelper
31
31
 
32
32
  if authorized_for(hash_for_host_path(host).merge(auth_object: host, permission: :view_hosts, authorizer: job_hosts_authorizer))
33
33
  links << { title: _('Host detail'),
34
- action: { href: host_path(host), 'data-method': 'get', id: "#{host.name}-actions-detail" } }
34
+ action: { href: current_host_details_path(host), 'data-method': 'get', id: "#{host.name}-actions-detail" } }
35
35
  end
36
36
 
37
37
  if authorized_for(hash_for_rerun_job_invocation_path(id: job_invocation, host_ids: [ host.id ], authorizer: job_hosts_authorizer))
@@ -147,9 +147,10 @@ module RemoteExecutionHelper
147
147
  end
148
148
  end
149
149
 
150
- def invocation_description(invocation)
150
+ def invocation_description(invocation, keep_tooltip: true)
151
151
  description = invocation.description.try(:capitalize) || invocation.job_category
152
- trunc_with_tooltip(description, 80)
152
+ description = trunc_with_tooltip(description, 80) if keep_tooltip
153
+ description
153
154
  end
154
155
 
155
156
  def invocation_result(invocation, key)
@@ -121,6 +121,10 @@ module ForemanRemoteExecution
121
121
  @cached_rex_host_params_hash = nil
122
122
  end
123
123
 
124
+ def infrastructure_host?
125
+ infrastructure_facet&.foreman_instance || infrastructure_facet&.smart_proxy_id
126
+ end
127
+
124
128
  private
125
129
 
126
130
  def extend_host_params_hash(params)
@@ -3,16 +3,18 @@ module ForemanRemoteExecution
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- before_validation :set_execution_flag
7
6
  validate :exclusive_execution_interface
7
+ before_validation :move_execution_flag
8
8
  end
9
9
 
10
10
  private
11
11
 
12
- def set_execution_flag
13
- return unless primary? && host.present?
12
+ def move_execution_flag
13
+ return unless host && self.execution?
14
14
 
15
- self.execution = true if host.interfaces.detect(&:execution).nil?
15
+ host.interfaces
16
+ .select { |i| i.execution? && i != self }
17
+ .each { |i| i.execution = false }
16
18
  end
17
19
 
18
20
  def exclusive_execution_interface
@@ -67,7 +67,7 @@ class Targeting < ApplicationRecord
67
67
  return '' if ids.empty?
68
68
 
69
69
  hosts = Host.execution_scope.where(:id => ids).distinct.pluck(:name)
70
- "name ^ (#{hosts.join(', ')})"
70
+ hosts.any? ? "name ^ (#{hosts.join(', ')})" : ''
71
71
  end
72
72
 
73
73
  def resolved?
@@ -10,7 +10,7 @@
10
10
  </tr>
11
11
  <% JobInvocation.latest_jobs.each do |invocation| %>
12
12
  <tr>
13
- <td class="ellipsis"><%= link_to_if_authorized invocation_description(invocation), hash_for_job_invocation_path(invocation).merge(:auth_object => invocation, :permission => :view_job_invocations, :authorizer => authorizer) %></td>
13
+ <td class="ellipsis"><%= link_to_if_authorized invocation_description(invocation, keep_tooltip: false), hash_for_job_invocation_path(invocation).merge(:auth_object => invocation, :permission => :view_job_invocations, :authorizer => authorizer) %></td>
14
14
  <td><%= link_to_invocation_task_if_authorized(invocation) %></td>
15
15
  <td><%= time_in_words_span(invocation.start_at) %></td>
16
16
  </tr>
@@ -7,7 +7,7 @@
7
7
  <% if @hosts.any? -%>
8
8
  <ul>
9
9
  <% @hosts.each do |host| -%>
10
- <li><%= link_to h(host.name), host_path(host), :target => '_blank' %></li>
10
+ <li><%= link_to h(host.name), current_host_details_path(host), :target => '_blank' %></li>
11
11
  <% end -%>
12
12
 
13
13
  <% if @additional > 0 -%>
@@ -28,7 +28,7 @@ end
28
28
  </div>
29
29
  </div>
30
30
  <% if @host %>
31
- <h3><%= _('Target: ') %><%= link_to(@host.name, host_path(@host)) %></h3>
31
+ <h3><%= _('Target: ') %><%= link_to(@host.name, current_host_details_path(@host)) %></h3>
32
32
 
33
33
  <div class="preview hidden">
34
34
  <%= preview_box(@template_invocation, @host) %>
@@ -69,8 +69,11 @@ handle_zypp_res_codes () {
69
69
 
70
70
  if [ "${ZYPP_RES_CODES[$RETVAL]}" != "" ]; then
71
71
  echo ${ZYPP_RES_CODES[$RETVAL]}
72
+ fi
73
+ if [[ $RETVAL -ge 100 && $RETVAL -le 103 ]]; then
72
74
  RETVAL=0
73
75
  fi
76
+
74
77
  return $RETVAL
75
78
  }
76
79
  <% end -%>
@@ -214,7 +214,11 @@ module ForemanRemoteExecution
214
214
  role 'Remote Execution User', USER_PERMISSIONS, 'Role with permissions to run remote execution jobs against hosts'
215
215
  role 'Remote Execution Manager', MANAGER_PERMISSIONS, 'Role with permissions to manage job templates, remote execution features, cancel jobs and view audit logs'
216
216
 
217
- add_all_permissions_to_default_roles
217
+ add_all_permissions_to_default_roles(except: [:execute_jobs_on_infrastructure_hosts])
218
+ add_permissions_to_default_roles({
219
+ Role::MANAGER => [:execute_jobs_on_infrastructure_hosts],
220
+ Role::SITE_MANAGER => USER_PERMISSIONS + [:execute_jobs_on_infrastructure_hosts],
221
+ })
218
222
 
219
223
  # add menu entry
220
224
  menu :top_menu, :job_templates,
@@ -1,3 +1,3 @@
1
1
  module ForemanRemoteExecution
2
- VERSION = '5.0.1'.freeze
2
+ VERSION = '5.0.4'.freeze
3
3
  end
@@ -67,7 +67,8 @@ class ForemanRemoteExecutionHostExtensionsTest < ActiveSupport::TestCase
67
67
  it 'should only have one execution interface' do
68
68
  host.interfaces << FactoryBot.build(:nic_managed)
69
69
  host.interfaces.each { |interface| interface.execution = true }
70
- _(host).wont_be :valid?
70
+ _(host).must_be :valid?
71
+ _(host.interfaces.count(&:execution?)).must_equal 1
71
72
  end
72
73
 
73
74
  it 'returns the execution interface' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_remote_execution
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.1
4
+ version: 5.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Foreman Remote Execution team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-03 00:00:00.000000000 Z
11
+ date: 2022-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deface