foreman_ansible 10.3.0 → 10.4.0

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: 3b1b699102370b4e5a97d04d193bd0fcea93579d921cc0e85765e026b367b573
4
- data.tar.gz: 81815947622a3207f02566dd22a90fa812c3c13084344e039d5c398f8ed3d91b
3
+ metadata.gz: 8c30c3eac6e4a49a8d43c6a654d84b672ef9fa58bbacb8fe2044cc74f33b5a28
4
+ data.tar.gz: 8084c75afc69d788093952a8988e3ff883f3726779a94f1de5016c1b857d7435
5
5
  SHA512:
6
- metadata.gz: 3231ccc8fd6ef3f4b7705ea63cacf42cecc35f86332a79dd0d44dafbe2a700e0eb6e81b97a8185c1c3cae7c27657cbe8ee5c998b1f6c008d0905ae4c76d53d01
7
- data.tar.gz: 7ea76ec8df5ebabc52f32f6edcde10892f2578dc74bf452fcaa64e41a0688e1c9b5c4091cbc7cbb6275f10d2e3e4bbe4faf8118be47be6feb582e629e7a28ebf
6
+ metadata.gz: e541db04ed8d5bb3ed65b8239a06366efbda044d57263e4e507534c61a89d566e1270b67593a5c33d423abf13bc7896f76208aa81efc36f58382bd972d40cd7f
7
+ data.tar.gz: 5df022f589352f580358303a3172f8062e476884607e1dafd21ee8f140646e106a93419c018b896df55b4bc4cac102374bb92bd3c46e8dc9e42998c52c2bb26e
@@ -8,12 +8,14 @@ module Types
8
8
  argument :match, String, required: false
9
9
  end
10
10
 
11
- field :meta, ::Types::Meta, resolve: (proc do |object|
11
+ field :meta, ::Types::Meta
12
+
13
+ def meta
12
14
  {
13
15
  :can_edit => ::User.current.can?(object.ansible_variable.permission_name(:edit), object.ansible_variable),
14
16
  :can_destroy => ::User.current.can?(object.ansible_variable.permission_name(:destroy), object.ansible_variable)
15
17
  }
16
- end)
18
+ end
17
19
 
18
20
  def lookup_values(match: nil)
19
21
  return CollectionLoader.for(object.ansible_variable.class, :lookup_values).load(object.ansible_variable) unless match
@@ -3,13 +3,19 @@
3
3
  module ForemanAnsible
4
4
  module AnsibleHostgroupsHelper
5
5
  def ansible_hostgroups_actions(hostgroup)
6
+ actions = []
6
7
  play_roles = if hostgroup.all_ansible_roles.empty?
7
8
  { action: { content: (link_to _('Run all Ansible roles'), 'javascript:void(0);', disabled: true, title: 'No roles assigned', class: 'disabled'), options: { class: 'disabled' } }, priority: 31 }
8
9
  else
9
10
  { action: display_link_if_authorized(_('Run all Ansible roles'), hash_for_play_roles_hostgroup_path(id: hostgroup), 'data-no-turbolink': true, title: _('Run all Ansible roles on hosts belonging to this host group')), priority: 31 }
10
11
  end
11
12
 
12
- [play_roles] if User.current.can?(:create_job_invocations)
13
+ assign_jobs = { action: { content: (link_to _('Configure Ansible Job'), "/ansible/hostgroups/#{hostgroup.id}", class: 'la') }, priority: 32 }
14
+
15
+ actions.push play_roles if User.current.can?(:create_job_invocations)
16
+ actions.push assign_jobs if User.current.can?(:view_job_invocations) && User.current.can?(:view_recurring_logics)
17
+
18
+ actions
13
19
  end
14
20
  end
15
21
  end
@@ -27,7 +27,10 @@ module ForemanAnsible
27
27
 
28
28
  def ansible_module_message(log)
29
29
  msg_json = parsed_message_json(log)
30
- module_action = msg_json['module']
30
+ return _("Execution error: #{msg_json['msg']}") if msg_json['failed'].present?
31
+ return msg_json['censored'] if msg_json['censored'].present?
32
+
33
+ module_action = msg_json.fetch('module', '').delete_prefix('ansible.builtin.').delete_prefix('ansible.legacy.')
31
34
  case module_action
32
35
  when 'package'
33
36
  msg_json['results'].empty? ? msg_json['msg'] : msg_json['results']
@@ -1,5 +1,5 @@
1
1
  class FixAnsibleSettingCategoryToDsl < ActiveRecord::Migration[6.0]
2
2
  def up
3
- Setting.where(category: 'Setting::Ansible').update_all(category: 'Setting')
3
+ Setting.where(category: 'Setting::Ansible').update_all(category: 'Setting') if column_exists?(:settings, :category)
4
4
  end
5
5
  end
@@ -4,5 +4,5 @@
4
4
  # This way other parts of Foreman can just call ForemanAnsible::VERSION
5
5
  # and detect what version the plugin is running.
6
6
  module ForemanAnsible
7
- VERSION = '10.3.0'
7
+ VERSION = '10.4.0'
8
8
  end
@@ -40,4 +40,43 @@ ANSIBLELOG
40
40
  end
41
41
  assert_equal expected_outputs, actual_outputs
42
42
  end
43
+
44
+ test 'accepting an almost empty message' do
45
+ log_value = <<-ANSIBLELOG.strip_heredoc
46
+ {"changed": true, "failed": false, "module": "copy"}
47
+ ANSIBLELOG
48
+ message = FactoryBot.build(:message, value: log_value)
49
+ log = FactoryBot.build(:log)
50
+ log.message = message
51
+ assert_match(
52
+ /Copy/,
53
+ ansible_module_message(log).to_s
54
+ )
55
+ end
56
+
57
+ test 'FQCN module message extraction' do
58
+ log_value = <<-ANSIBLELOG.strip_heredoc
59
+ {"msg": "Nothing to do", "changed": false, "results": [], "rc": 0, "invocation": {"module_args": {"name": ["openssh"], "state": "present", "allow_downgrade": false, "autoremove": false, "bugfix": false, "disable_gpg_check": false, "disable_plugin": [], "disablerepo": [], "download_only": false, "enable_plugin": [], "enablerepo": [], "exclude": [], "installroot": "/", "install_repoquery": true, "install_weak_deps": true, "security": false, "skip_broken": false, "update_cache": false, "update_only": false, "validate_certs": true, "lock_timeout": 30, "conf_file": null, "disable_excludes": null, "download_dir": null, "list": null, "releasever": null}}, "_ansible_no_log": false, "failed": false, "module": "ansible.builtin.package"}
60
+ ANSIBLELOG
61
+ message = FactoryBot.build(:message, value: log_value)
62
+ log = FactoryBot.build(:log)
63
+ log.message = message
64
+ assert_match(
65
+ /Nothing to do/,
66
+ ansible_module_message(log).to_s
67
+ )
68
+ end
69
+
70
+ test 'accepting a censored message' do
71
+ log_value = <<-ANSIBLELOG.strip_heredoc
72
+ {"censored": "the output has been hidden due to the fact that 'no_log: true' was specified for this result", "changed": true, "failed": false, "module": "copy"}
73
+ ANSIBLELOG
74
+ message = FactoryBot.build(:message, value: log_value)
75
+ log = FactoryBot.build(:log)
76
+ log.message = message
77
+ assert_match(
78
+ /output has been hidden/,
79
+ ansible_module_message(log).to_s
80
+ )
81
+ end
43
82
  end
@@ -8,4 +8,9 @@ fragment CurrentUserAttributes on User {
8
8
  name
9
9
  }
10
10
  }
11
+ usergroups {
12
+ nodes {
13
+ admin
14
+ }
15
+ }
11
16
  }
@@ -11,7 +11,10 @@ export const permissionCheck = (user, permissionsRequired) => {
11
11
  );
12
12
  }
13
13
 
14
- if (user.admin) {
14
+ if (
15
+ user.admin ||
16
+ user.usergroups.nodes.find(usergroup => usergroup.admin === true)
17
+ ) {
15
18
  return { allowed: true };
16
19
  }
17
20
 
@@ -71,6 +71,9 @@ export const userFactory = (login, permissions = []) => ({
71
71
  permissions: {
72
72
  nodes: permissions,
73
73
  },
74
+ usergroups: {
75
+ nodes: [],
76
+ },
74
77
  });
75
78
 
76
79
  export const admin = {
@@ -81,6 +84,9 @@ export const admin = {
81
84
  permissions: {
82
85
  nodes: [],
83
86
  },
87
+ usergroups: {
88
+ nodes: [],
89
+ },
84
90
  };
85
91
 
86
92
  export const intruder = userFactory('intruder', [
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_ansible
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.3.0
4
+ version: 10.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Lobato Garcia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-26 00:00:00.000000000 Z
11
+ date: 2023-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: acts_as_list