foreman_puppet 0.0.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +61 -7
- data/app/controllers/concerns/foreman_puppet/environments_import.rb +1 -1
- data/app/controllers/concerns/foreman_puppet/extensions/api_base_controller.rb +28 -0
- data/app/controllers/concerns/foreman_puppet/extensions/api_template_combinations_controller.rb +1 -1
- data/app/controllers/concerns/foreman_puppet/extensions/hostgroups_controller_extensions.rb +1 -1
- data/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb +1 -1
- data/app/controllers/concerns/foreman_puppet/extensions/parameters_host.rb +3 -10
- data/app/controllers/concerns/foreman_puppet/parameters/puppetclass_lookup_key.rb +2 -2
- data/app/controllers/foreman_puppet/api/v2/config_groups_controller.rb +9 -1
- data/app/controllers/foreman_puppet/api/v2/environments_controller.rb +5 -2
- data/app/controllers/foreman_puppet/api/v2/host_classes_controller.rb +9 -1
- data/app/controllers/foreman_puppet/api/v2/hostgroup_classes_controller.rb +9 -1
- data/app/controllers/foreman_puppet/api/v2/override_values_controller.rb +1 -2
- data/app/controllers/foreman_puppet/api/v2/{base_controller.rb → puppet_base_controller.rb} +3 -4
- data/app/controllers/foreman_puppet/api/v2/{lookups_common_controller.rb → puppet_lookups_common_controller.rb} +6 -2
- data/app/controllers/foreman_puppet/api/v2/puppetclasses_controller.rb +5 -1
- data/app/controllers/foreman_puppet/api/v2/smart_class_parameters_controller.rb +1 -2
- data/app/controllers/foreman_puppet/config_groups_controller.rb +4 -0
- data/app/controllers/foreman_puppet/puppet_smart_proxies_controller.rb +4 -0
- data/app/controllers/foreman_puppet/puppetclass_lookup_keys_controller.rb +2 -2
- data/app/controllers/foreman_puppet/puppetclasses_controller.rb +12 -4
- data/app/graphgl/concerns/foreman_puppet/mutations/hosts/create_extensions.rb +29 -0
- data/app/graphgl/concerns/foreman_puppet/types/host_extensions.rb +13 -0
- data/app/graphgl/concerns/foreman_puppet/types/hostgroup_extensions.rb +13 -0
- data/app/graphgl/concerns/foreman_puppet/types/interface_attributes_input_extensions.rb +9 -0
- data/app/graphgl/concerns/foreman_puppet/types/location_extensions.rb +14 -0
- data/app/graphgl/concerns/foreman_puppet/types/organization_extensions.rb +14 -0
- data/app/graphgl/foreman_puppet/types/environment.rb +20 -0
- data/app/graphgl/foreman_puppet/types/puppetclass.rb +20 -0
- data/app/helpers/foreman_puppet/environments_helper.rb +1 -1
- data/app/helpers/foreman_puppet/hosts_helper.rb +15 -0
- data/app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb +2 -2
- data/app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb +1 -1
- data/app/helpers/foreman_puppet/puppetclasses_helper.rb +2 -2
- data/app/models/concerns/foreman_puppet/extensions/host.rb +24 -9
- data/app/models/concerns/foreman_puppet/extensions/host_common.rb +17 -0
- data/app/models/concerns/foreman_puppet/extensions/hostgroup.rb +13 -7
- data/app/models/concerns/foreman_puppet/extensions/operatingsystem.rb +1 -1
- data/app/models/concerns/foreman_puppet/extensions/provisioning_template.rb +19 -13
- data/app/models/concerns/foreman_puppet/extensions/report.rb +18 -0
- data/app/models/concerns/foreman_puppet/extensions/taxonomy.rb +1 -1
- data/app/models/concerns/foreman_puppet/extensions/template_combination.rb +1 -1
- data/app/models/concerns/foreman_puppet/extensions/user.rb +19 -12
- data/app/models/foreman_puppet/environment.rb +2 -0
- data/app/models/foreman_puppet/environment_class.rb +1 -1
- data/app/models/foreman_puppet/host_class.rb +1 -1
- data/app/models/foreman_puppet/host_puppet_facet.rb +6 -5
- data/app/models/foreman_puppet/hostgroup_puppet_facet.rb +1 -1
- data/app/models/{concerns/foreman_puppet/host_common.rb → foreman_puppet/puppet_facet_common.rb} +1 -1
- data/app/models/foreman_puppet/puppetclass.rb +15 -1
- data/app/{views/api/v2/template_combinations/base.json.erb → prepend_views/api/v2/template_combinations/base.json.rabl} +0 -0
- data/app/services/foreman_puppet/host_info_providers/config_groups_info.rb +2 -0
- data/app/services/foreman_puppet/puppet_class_importer.rb +17 -18
- data/app/views/foreman_puppet/common/_puppetclasses_or_envs_changed.html.erb +62 -0
- data/app/views/foreman_puppet/config_groups/index.html.erb +2 -2
- data/app/views/foreman_puppet/config_groups/welcome.html.erb +12 -11
- data/app/views/foreman_puppet/environments/index.html.erb +1 -1
- data/app/views/foreman_puppet/environments/welcome.html.erb +3 -15
- data/app/views/foreman_puppet/puppetclass_lookup_keys/welcome.html.erb +10 -8
- data/app/views/foreman_puppet/puppetclasses/_classes.html.erb +1 -1
- data/app/views/foreman_puppet/puppetclasses/_selected_classes.html.erb +1 -1
- data/app/views/foreman_puppet/puppetclasses/index.html.erb +1 -1
- data/app/views/hosts/_form_puppet_enc_tab.html.erb +1 -1
- data/app/views/hosts/select_multiple_environment.html.erb +1 -1
- data/app/views/smart_proxies/plugins/_puppet_ca.html.erb +44 -0
- data/config/initializers/api_reroute.rb +13 -0
- data/db/migrate/20200803113903_migrate_host_type_in_host_config_groups.foreman_puppet.rb +37 -12
- data/db/migrate/20201125113903_migrate_puppetclasses_to_facets.foreman_puppet.rb +13 -1
- data/lib/foreman_puppet/engine.rb +68 -20
- data/lib/foreman_puppet/register.rb +7 -2
- data/lib/foreman_puppet/version.rb +1 -1
- data/lib/foreman_puppet.rb +3 -3
- data/locale/Makefile +1 -1
- data/locale/en/LC_MESSAGES/foreman_puppet.mo +0 -0
- data/locale/en/foreman_puppet.edit.po +19 -3
- data/locale/en/foreman_puppet.po +18 -6
- data/locale/en/foreman_puppet.pox +0 -0
- data/locale/foreman_puppet.pot +19 -3
- data/locale/messages.mo +0 -0
- data/test/controllers/foreman_puppet/api/v2/config_groups_controller_test.rb +7 -3
- data/test/controllers/foreman_puppet/api/v2/environments_controller_test.rb +18 -16
- data/test/controllers/foreman_puppet/api/v2/hosts_controller_test.rb +3 -2
- data/test/controllers/foreman_puppet/api/v2/lookups_common_controller_test.rb +1 -1
- data/test/controllers/foreman_puppet/api/v2/provisioning_templates_controller_test.rb +32 -0
- data/test/controllers/foreman_puppet/api/v2/puppetclasses_controller_test.rb +3 -0
- data/test/controllers/foreman_puppet/api/v2/smart_class_parameters_controller_test.rb +7 -1
- data/test/controllers/foreman_puppet/api/v2/template_combinations_controller_test.rb +2 -2
- data/test/controllers/foreman_puppet/config_groups_controller_test.rb +7 -3
- data/test/controllers/foreman_puppet/environments_controller_test.rb +2 -2
- data/test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb +2 -2
- data/test/controllers/foreman_puppet/puppetclasses_controller_test.rb +5 -6
- data/test/factories/foreman_puppet_factories.rb +3 -0
- data/test/factories/host_puppet_enhancements.rb +6 -6
- data/test/graphql/mutations/hosts/create_mutation_test.rb +87 -0
- data/test/graphql/queries/environment_query_test.rb +54 -0
- data/test/graphql/queries/environments_query_test.rb +43 -0
- data/test/{qraphql → graphql}/queries/host_puppet_query_test.rb +3 -8
- data/test/{qraphql → graphql}/queries/hostgroup_puppet_query_test.rb +1 -6
- data/test/graphql/queries/location_query_test.rb +52 -0
- data/test/graphql/queries/organization_query_test.rb +52 -0
- data/test/graphql/queries/puppetclass_query_test.rb +68 -0
- data/test/graphql/queries/puppetclasses_query_test.rb +43 -0
- data/test/integration/foreman_puppet/environment_js_test.rb +4 -1
- data/test/integration/foreman_puppet/host_js_test.rb +1 -1
- data/test/integration/foreman_puppet/puppetclass_js_test.rb +4 -0
- data/test/models/foreman_puppet/config_group_class_test.rb +3 -1
- data/test/models/foreman_puppet/environment_test.rb +2 -0
- data/test/models/foreman_puppet/host_puppet_facet_test.rb +34 -1
- data/test/models/foreman_puppet/host_test.rb +4 -3
- data/test/models/foreman_puppet/hostgroup_puppet_facet_test.rb +2 -3
- data/test/models/foreman_puppet/provisioning_template_test.rb +14 -7
- data/test/models/foreman_puppet/report_test.rb +21 -0
- data/test/models/foreman_puppet/smart_proxy_test.rb +1 -1
- data/test/models/foreman_puppet/user_test.rb +37 -0
- data/test/services/foreman_puppet/host_info_providers/config_groups_info_test.rb +35 -0
- data/test/services/foreman_puppet/host_info_providers/puppet_info_test.rb +159 -197
- data/test/unit/foreman_puppet/puppet_class_importer_test.rb +16 -2
- data/webpack/index.js +3 -4
- data/webpack/src/Components/Environments/Welcome.js +37 -0
- metadata +51 -12
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ForemanPuppet
|
4
|
+
module Mutations
|
5
|
+
module Hosts
|
6
|
+
module CreateExtensions
|
7
|
+
PUPPET_PARAMS = %i[
|
8
|
+
environment
|
9
|
+
puppetclasses
|
10
|
+
].freeze
|
11
|
+
|
12
|
+
extend ActiveSupport::Concern
|
13
|
+
|
14
|
+
included do
|
15
|
+
argument :environment_id, GraphQL::Types::ID, loads: ForemanPuppet::Types::Environment
|
16
|
+
argument :puppetclass_ids, [GraphQL::Types::ID], loads: ForemanPuppet::Types::Puppetclass, as: :puppetclasses
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def initialize_object(params)
|
21
|
+
host = super(params.except(*PUPPET_PARAMS))
|
22
|
+
host.build_puppet(params.slice(*PUPPET_PARAMS))
|
23
|
+
host
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ForemanPuppet
|
4
|
+
module Types
|
5
|
+
module LocationExtensions
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
has_many :environments, ForemanPuppet::Types::Environment
|
10
|
+
has_many :puppetclasses, ForemanPuppet::Types::Puppetclass
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ForemanPuppet
|
4
|
+
module Types
|
5
|
+
module OrganizationExtensions
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
has_many :environments, ForemanPuppet::Types::Environment
|
10
|
+
has_many :puppetclasses, ForemanPuppet::Types::Puppetclass
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ForemanPuppet
|
2
|
+
module Types
|
3
|
+
class Environment < ::Types::BaseObject
|
4
|
+
model_class ForemanPuppet::Environment
|
5
|
+
description 'An Environment'
|
6
|
+
|
7
|
+
global_id_field :id
|
8
|
+
timestamps
|
9
|
+
field :name, String
|
10
|
+
|
11
|
+
has_many :locations, ::Types::Location
|
12
|
+
has_many :organizations, ::Types::Organization
|
13
|
+
has_many :puppetclasses, ForemanPuppet::Types::Puppetclass
|
14
|
+
|
15
|
+
def self.graphql_definition
|
16
|
+
super.tap { |type| type.instance_variable_set(:@name, 'ForemanPuppet::Environment') }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ForemanPuppet
|
2
|
+
module Types
|
3
|
+
class Puppetclass < ::Types::BaseObject
|
4
|
+
model_class ForemanPuppet::Puppetclass
|
5
|
+
description 'A Puppetclass'
|
6
|
+
|
7
|
+
global_id_field :id
|
8
|
+
timestamps
|
9
|
+
field :name, String
|
10
|
+
|
11
|
+
has_many :environments, ForemanPuppet::Types::Environment
|
12
|
+
has_many :locations, ::Types::Location
|
13
|
+
has_many :organizations, ::Types::Organization
|
14
|
+
|
15
|
+
def self.graphql_definition
|
16
|
+
super.tap { |type| type.instance_variable_set(:@name, 'ForemanPuppet::Puppetclass') }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -9,7 +9,7 @@ module ForemanPuppet
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def environments_title_actions
|
12
|
-
title_actions import_proxy_select(hash_for_import_environments_environments_path),
|
12
|
+
title_actions import_proxy_select(hash_for_import_environments_environments_path.merge(engine: foreman_puppet)),
|
13
13
|
button_group(new_link(_('Create Puppet Environment'), engine: foreman_puppet)),
|
14
14
|
button_group(help_button)
|
15
15
|
end
|
@@ -4,6 +4,7 @@ module ForemanPuppet
|
|
4
4
|
multiple_actions_provider :puppet_host_multiple_actions
|
5
5
|
# otherwise registered twice
|
6
6
|
overview_buttons_provider :puppet_host_overview_buttons if ForemanPuppet.extracted_from_core?
|
7
|
+
overview_fields_provider :puppet_host_overview_fields if ForemanPuppet.extracted_from_core?
|
7
8
|
end
|
8
9
|
|
9
10
|
def puppet_host_multiple_actions
|
@@ -28,5 +29,19 @@ module ForemanPuppet
|
|
28
29
|
end
|
29
30
|
buttons
|
30
31
|
end
|
32
|
+
|
33
|
+
def puppet_host_overview_fields(host)
|
34
|
+
fields = []
|
35
|
+
if host.environment.present?
|
36
|
+
fields << {
|
37
|
+
field: [
|
38
|
+
_('Puppet Environment'),
|
39
|
+
link_to(host.puppet.environment, hosts_path(search: "environment = #{host.puppet.environment}")),
|
40
|
+
],
|
41
|
+
priority: 650,
|
42
|
+
}
|
43
|
+
end
|
44
|
+
fields
|
45
|
+
end
|
31
46
|
end
|
32
47
|
end
|
@@ -2,8 +2,8 @@ module ForemanPuppet
|
|
2
2
|
module PuppetclassLookupKeysHelper
|
3
3
|
def puppetclass_lookup_keys_breadcrumbs
|
4
4
|
breadcrumbs(resource_url: api_smart_class_parameters_path,
|
5
|
-
|
6
|
-
|
5
|
+
name_field: 'parameter',
|
6
|
+
switcher_item_url: '/puppetclass_lookup_keys/:id-:name/edit')
|
7
7
|
end
|
8
8
|
|
9
9
|
# ------ Host(group) Form Helpers -----
|
@@ -42,7 +42,7 @@ module ForemanPuppet
|
|
42
42
|
mod_name,
|
43
43
|
rel: 'popover',
|
44
44
|
data: { content: mod_classes[mod_name].sort.join('<br>').html_safe,
|
45
|
-
|
45
|
+
'original-title': format(n_('%{name} has %{num_tag} class', '%{name} has %{num_tag} classes', num), name: mod_name, num_tag: num_tag),
|
46
46
|
trigger: 'focus',
|
47
47
|
container: 'body',
|
48
48
|
html: true },
|
@@ -30,7 +30,7 @@ module ForemanPuppet
|
|
30
30
|
|
31
31
|
def link_to_remove_function(text, options)
|
32
32
|
options.delete_if { |key, _value| !options[key].to_s } # otherwise error during template render
|
33
|
-
title = (_('Click to remove %s') % options[:
|
33
|
+
title = (_('Click to remove %s') % options[:'data-class-name'])
|
34
34
|
link_to_function(text, 'tfm.classEditor.removePuppetClass(this)', options.merge!('data-original-title': title))
|
35
35
|
end
|
36
36
|
|
@@ -43,7 +43,7 @@ module ForemanPuppet
|
|
43
43
|
|
44
44
|
def link_to_add_function(text, options)
|
45
45
|
link_to_function(text, 'tfm.classEditor.addPuppetClass(this)',
|
46
|
-
options.merge('data-original-title': _('Click to add %s') % options[:
|
46
|
+
options.merge('data-original-title': _('Click to add %s') % options[:'data-class-name']))
|
47
47
|
end
|
48
48
|
|
49
49
|
def options_for_puppetclass_selection(klass, type)
|
@@ -3,21 +3,30 @@ module ForemanPuppet
|
|
3
3
|
module Host
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
+
include ForemanPuppet::Extensions::HostCommon if ForemanPuppet.extracted_from_core?
|
7
|
+
|
6
8
|
included do
|
7
9
|
prepend PrependedMethods
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
+
if ForemanPuppet.extracted_from_core?
|
12
|
+
has_one :environment, through: :puppet, class_name: 'ForemanPuppet::Environment'
|
13
|
+
else
|
14
|
+
env_assoc = reflect_on_association(:environment)
|
15
|
+
env_assoc&.instance_variable_set(:@class_name, 'ForemanPuppet::Environment')
|
16
|
+
|
17
|
+
host_classes_assoc = reflect_on_association(:host_classes)
|
18
|
+
host_classes_assoc&.instance_variable_set(:@class_name, 'ForemanPuppet::HostClass')
|
19
|
+
end
|
11
20
|
|
12
21
|
include_in_clone puppet: %i[config_groups host_config_groups host_classes]
|
13
22
|
|
14
23
|
scoped_search relation: :environment, on: :name, complete_value: true, rename: :environment
|
15
24
|
scoped_search relation: :puppetclasses, on: :name, complete_value: true, rename: :class, only_explicit: true, operators: ['= ', '~ '],
|
16
|
-
|
25
|
+
ext_method: :search_by_deprecated_class
|
17
26
|
scoped_search relation: :puppetclasses, on: :name, complete_value: true, rename: :puppetclass, only_explicit: true, operators: ['= ', '~ '],
|
18
|
-
|
27
|
+
ext_method: :search_by_puppetclass
|
19
28
|
scoped_search relation: :config_groups, on: :name, complete_value: true, rename: :config_group, only_explicit: true, operators: ['= ', '~ '],
|
20
|
-
|
29
|
+
ext_method: :search_by_config_group
|
21
30
|
end
|
22
31
|
|
23
32
|
class_methods do
|
@@ -61,6 +70,12 @@ module ForemanPuppet
|
|
61
70
|
end
|
62
71
|
|
63
72
|
module PrependedMethods
|
73
|
+
# TODO: we can drop this once extracted_from_core?
|
74
|
+
def validate_association_taxonomy(association_name)
|
75
|
+
return if association_name.to_sym == :environment
|
76
|
+
super
|
77
|
+
end
|
78
|
+
|
64
79
|
def provisioning_template(opts = {})
|
65
80
|
opts[:environment_id] ||= puppet&.environment_id
|
66
81
|
super(opts)
|
@@ -69,10 +84,10 @@ module ForemanPuppet
|
|
69
84
|
def available_template_kinds(provisioning = nil)
|
70
85
|
kinds = template_kinds(provisioning)
|
71
86
|
kinds.map do |kind|
|
72
|
-
ProvisioningTemplate.find_template({ kind: kind.name,
|
73
|
-
|
74
|
-
|
75
|
-
|
87
|
+
::ProvisioningTemplate.find_template({ kind: kind.name,
|
88
|
+
operatingsystem_id: operatingsystem_id,
|
89
|
+
hostgroup_id: hostgroup_id,
|
90
|
+
environment_id: puppet&.environment_id })
|
76
91
|
end.compact
|
77
92
|
end
|
78
93
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ForemanPuppet
|
2
|
+
module Extensions
|
3
|
+
module HostCommon
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def all_puppetclasses(env = environment)
|
7
|
+
return ForemanPuppet::Puppetclass.none unless puppet
|
8
|
+
puppet.all_puppetclasses(env)
|
9
|
+
end
|
10
|
+
|
11
|
+
def puppetclasses
|
12
|
+
return ForemanPuppet::Puppetclass.none unless puppet
|
13
|
+
puppet.puppetclasses
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -3,13 +3,19 @@ module ForemanPuppet
|
|
3
3
|
module Hostgroup
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
+
include ForemanPuppet::Extensions::HostCommon if ForemanPuppet.extracted_from_core?
|
7
|
+
|
6
8
|
included do
|
7
9
|
class << self
|
8
10
|
prepend PatchedClassMethods
|
9
11
|
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
+
if ForemanPuppet.extracted_from_core?
|
14
|
+
has_one :environment, through: :puppet, class_name: 'ForemanPuppet::Environment'
|
15
|
+
else
|
16
|
+
env_assoc = reflect_on_association(:environment)
|
17
|
+
env_assoc&.instance_variable_set(:@class_name, 'ForemanPuppet::Environment')
|
18
|
+
end
|
13
19
|
|
14
20
|
include_in_clone puppet: %i[host_config_groups config_groups hostgroup_classes]
|
15
21
|
|
@@ -17,11 +23,11 @@ module ForemanPuppet
|
|
17
23
|
scoped_search relation: :environment, on: :name, complete_value: true, rename: :environment, only_explicit: true
|
18
24
|
scoped_search relation: :puppetclasses, on: :name, complete_value: true, rename: :class, only_explicit: true, operators: ['= ', '~ ']
|
19
25
|
scoped_search relation: :config_groups, on: :name,
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
complete_value: true,
|
27
|
+
rename: :config_group,
|
28
|
+
only_explicit: true,
|
29
|
+
operators: ['= ', '~ '],
|
30
|
+
ext_method: :search_by_config_group
|
25
31
|
end
|
26
32
|
|
27
33
|
# Temporary, can be ordinary class_methods do, when removed from core
|
@@ -6,11 +6,11 @@ module ForemanPuppet
|
|
6
6
|
included do
|
7
7
|
if ForemanPuppet.extracted_from_core?
|
8
8
|
has_many :environments, through: :template_combinations
|
9
|
-
before_destroy EnsureNotUsedBy.new(:environments)
|
9
|
+
before_destroy ActiveRecord::Base::EnsureNotUsedBy.new(:environments)
|
10
10
|
|
11
11
|
scoped_search relation: :environments, on: :name, rename: :environment, complete_value: true
|
12
12
|
|
13
|
-
class <<
|
13
|
+
class << self
|
14
14
|
prepend PrependedClassMethods
|
15
15
|
end
|
16
16
|
|
@@ -24,23 +24,29 @@ module ForemanPuppet
|
|
24
24
|
module PrependedClassMethods
|
25
25
|
def templates_by_template_combinations(templates, hosts_or_conditions)
|
26
26
|
if hosts_or_conditions.is_a?(Hash)
|
27
|
-
conditions =
|
28
|
-
|
29
|
-
|
27
|
+
conditions = []
|
28
|
+
if hosts_or_conditions[:hostgroup_id] && hosts_or_conditions[:environment_id]
|
29
|
+
conditions << { hostgroup_id: Array.wrap(hosts_or_conditions[:hostgroup_id]), environment_id: Array.wrap(hosts_or_conditions[:environment_id]) }
|
30
|
+
end
|
31
|
+
conditions << { hostgroup_id: Array.wrap(hosts_or_conditions[:hostgroup_id]), environment_id: [nil] } if hosts_or_conditions[:hostgroup_id]
|
32
|
+
conditions << { hostgroup_id: [nil], environment_id: Array.wrap(hosts_or_conditions[:environment_id]) } if hosts_or_conditions[:environment_id]
|
30
33
|
else
|
31
|
-
conditions = {
|
32
|
-
|
33
|
-
|
34
|
+
conditions = [{
|
35
|
+
hostgroup_id: hosts_or_conditions.pluck(:hostgroup_id) | [nil],
|
36
|
+
environment_id: hosts_or_conditions.joins(:puppet).pluck('host_puppet_facets.environment_id') | [nil],
|
37
|
+
}]
|
34
38
|
end
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
+
tpls = templates.where('1=0')
|
40
|
+
conditions.each do |cond|
|
41
|
+
tpls = templates.joins(:template_combinations).where(template_combinations: cond).distinct
|
42
|
+
return tpls if tpls.any?
|
43
|
+
end
|
44
|
+
tpls
|
39
45
|
end
|
40
46
|
|
41
47
|
def template_includes
|
42
48
|
includes = super
|
43
|
-
tc_include = includes.detect { |i| i.key?(:template_combinations) }
|
49
|
+
tc_include = includes.detect { |i| i.is_a?(Hash) && i.key?(:template_combinations) }
|
44
50
|
tc_include ||= includes << {}
|
45
51
|
tc_include[:template_combinations] = %i[hostgroup environment]
|
46
52
|
includes
|
@@ -5,6 +5,24 @@ module ForemanPuppet
|
|
5
5
|
|
6
6
|
included do
|
7
7
|
has_one :environment, through: :host
|
8
|
+
|
9
|
+
# for cases when class already inherit before we apply the patch
|
10
|
+
self.class.subclasses.each do |subclass|
|
11
|
+
add_environment_search_to(subclass)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class_methods do
|
16
|
+
def inherited(child)
|
17
|
+
add_environment_search_to(child)
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_environment_search_to(klass)
|
22
|
+
klass.instance_eval do
|
23
|
+
scoped_search relation: :environment, on: :name, complete_value: true, rename: :environment
|
24
|
+
end
|
25
|
+
end
|
8
26
|
end
|
9
27
|
end
|
10
28
|
end
|
@@ -6,7 +6,7 @@ module ForemanPuppet
|
|
6
6
|
included do
|
7
7
|
has_many :environments, through: :taxable_taxonomies, source: :taxable, source_type: 'ForemanPuppet::Environment'
|
8
8
|
|
9
|
-
has_many :puppetclasses, through: :environments
|
9
|
+
has_many :puppetclasses, through: :environments, class_name: 'ForemanPuppet::Puppetclass'
|
10
10
|
end
|
11
11
|
|
12
12
|
def dup
|