foreman_puppet 1.0.5 → 2.0.0.alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/foreman_puppet/extensions/api_hostgroups_controller.rb +14 -16
  3. data/app/controllers/concerns/foreman_puppet/{api/import_puppetclasses_common_controller.rb → extensions/api_smart_proxies_controller.rb} +9 -3
  4. data/app/controllers/concerns/foreman_puppet/extensions/api_template_combinations_controller.rb +23 -1
  5. data/app/controllers/concerns/foreman_puppet/extensions/api_v2_hosts_controller.rb +15 -17
  6. data/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb +0 -1
  7. data/app/controllers/concerns/foreman_puppet/extensions/parameters_host.rb +32 -41
  8. data/app/controllers/concerns/foreman_puppet/extensions/parameters_hostgroup.rb +26 -41
  9. data/app/controllers/foreman_puppet/api/v2/environments_controller.rb +0 -1
  10. data/app/controllers/foreman_puppet/puppetclasses_controller.rb +1 -1
  11. data/app/helpers/foreman_puppet/hosts_and_hostgroups_helper.rb +0 -5
  12. data/app/helpers/foreman_puppet/hosts_helper.rb +6 -10
  13. data/app/models/concerns/foreman_puppet/extensions/host.rb +2 -16
  14. data/app/models/concerns/foreman_puppet/extensions/hostgroup.rb +2 -7
  15. data/app/models/concerns/foreman_puppet/extensions/provisioning_template.rb +7 -12
  16. data/app/models/concerns/foreman_puppet/extensions/template_combination.rb +5 -10
  17. data/app/models/foreman_puppet/host_puppet_facet.rb +1 -1
  18. data/app/models/foreman_puppet/hostgroup_puppet_facet.rb +0 -2
  19. data/app/services/foreman_puppet/puppet_class_importer.rb +0 -6
  20. data/app/views/foreman_puppet/api/v2/host_puppet_facets/host_list.json.rabl +3 -0
  21. data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/base.json.rabl +2 -0
  22. data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/hostgroup_list.json.rabl +3 -0
  23. data/config/api_routes.rb +1 -9
  24. data/config/initializers/api_reroute.rb +73 -5
  25. data/db/migrate/20101121140000_add_environment_to_template_combinations.foreman_puppet.rb +1 -1
  26. data/db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb +2 -0
  27. data/db/migrate/20200803113903_migrate_host_type_in_host_config_groups.foreman_puppet.rb +20 -36
  28. data/db/migrate/20210924103241_remove_katello_id_from_environments.foreman_puppet.rb +5 -0
  29. data/db/migrate_foreman/20090722141107_create_environments.rb +2 -2
  30. data/db/migrate_foreman/20090802062223_create_puppetclasses.rb +28 -0
  31. data/db/migrate_foreman/20090905150132_create_hostgroups_puppetclasses.rb +12 -0
  32. data/db/migrate_foreman/20110412103238_remove_unused_fields_from_puppet_classes.rb +9 -0
  33. data/db/migrate_foreman/20110712070522_create_host_class.rb +11 -0
  34. data/db/migrate_foreman/20120824142048_add_some_indexes.rb +14 -0
  35. data/db/migrate_foreman/20121018152459_create_hostgroup_classes.rb +11 -0
  36. data/db/migrate_foreman/20161205142618_delete_orphaned_smart_class_parameters.rb +1 -1
  37. data/db/migrate_foreman/20180816134832_cast_lookup_key_values.rb +1 -31
  38. data/db/migrate_foreman/20180831115634_add_uniqueness_to_puppetclass_name.rb +24 -0
  39. data/db/migrate_foreman/20181023112532_add_environment_puppetclass_id.rb +1 -1
  40. data/lib/foreman_puppet/engine.rb +4 -36
  41. data/lib/foreman_puppet/register.rb +16 -47
  42. data/lib/foreman_puppet/version.rb +1 -1
  43. data/lib/foreman_puppet.rb +1 -6
  44. data/locale/en/LC_MESSAGES/foreman_puppet.mo +0 -0
  45. data/locale/en/foreman_puppet.edit.po +162 -317
  46. data/locale/en/foreman_puppet.po +62 -8
  47. data/locale/foreman_puppet.pot +215 -133
  48. data/locale/gemspec.rb +1 -1
  49. data/package.json +8 -11
  50. data/test/controllers/foreman_puppet/api/v2/environments_controller_test.rb +0 -231
  51. data/test/controllers/foreman_puppet/api/v2/smart_proxies_controller_test.rb +255 -0
  52. data/test/controllers/foreman_puppet/environments_controller_test.rb +2 -2
  53. data/test/controllers/foreman_puppet/hosts_controller_test.rb +0 -1
  54. data/test/factories/foreman_puppet_factories.rb +0 -2
  55. data/test/helpers/foreman_puppet/hosts_and_hostgroups_helper_test.rb +31 -70
  56. data/test/integration/foreman_puppet/host_js_test.rb +0 -1
  57. data/test/integration/foreman_puppet/puppetclass_js_test.rb +1 -1
  58. data/test/models/foreman_puppet/host_puppet_facet_test.rb +1 -7
  59. data/test/models/foreman_puppet/host_test.rb +26 -0
  60. data/test/models/foreman_puppet/user_test.rb +1 -5
  61. data/test/unit/foreman_puppet/puppet_class_importer_test.rb +1 -1
  62. metadata +22 -13
  63. data/db/migrate/20211112130803_cleanup_environment_from_core_tables.foreman_puppet.rb +0 -10
  64. data/locale/cs_CZ/foreman_puppet.edit.po +0 -1085
  65. data/locale/cs_CZ/foreman_puppet.po.time_stamp +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f8a5c7b68f8d77f54787c4c9de924bc02f27d7a0f957fc6539b5b4aa6c64b49
4
- data.tar.gz: 6cd563d9cc2f56c22186bbbb0fb9d3c9679c8718e965d7fd952bbed3efacf222
3
+ metadata.gz: 61b910e24e11c9bd100021c5b87cc45b03eab68bc68260985f90d3510496d016
4
+ data.tar.gz: '08fa8d3c7bdf23231daf2e14332f68be4d2a79fe33195260de1c1b276924c2de'
5
5
  SHA512:
6
- metadata.gz: 1a09cf7ff50545983f0e472b3c03f0708087dddf8d2136dc32978f49a1fd76ba7ca4c716db6e6b3add3055279745754b2d2eddf2cd1630a91e75187ba9683c1e
7
- data.tar.gz: 5c4bb18d77784e2a9c43c7f102adc9df6469b739525fee007d1c89bf635713e1dd051140489101ebeb9d66298100195f56571fa5fb55a1a179c8381cac56a65b
6
+ metadata.gz: cb6a6d40b42d741a4f4010aa81b9bbfa7e0b330473637036522d0a8d7e2fa983cee353ee0a59c3eacd1a64314d3edb17dfa29ee95adb7d47f08938f2380e822a
7
+ data.tar.gz: 1e2f6b9ac9b996cbb368612dfb22d3adc03c89201d3d1931ca7920baf58090769160ded784c5094a3cfd1043ba22bf93b2926ff6de0075294630a7376179be6b
@@ -6,25 +6,23 @@ module ForemanPuppet
6
6
  included do
7
7
  prepend PatchMethods
8
8
 
9
- if ForemanPuppet.extracted_from_core?
10
- method_desc = Apipie.get_method_description(self, :index)
11
- method_desc.apis << Apipie::MethodDescription::Api.new(:GET, '/puppetclasses/:puppetclass_id/hostgroups', N_('List all host groups for a Puppet class'), {})
9
+ method_desc = Apipie.get_method_description(self, :index)
10
+ method_desc.apis << Apipie::MethodDescription::Api.new(:GET, '/puppetclasses/:puppetclass_id/hostgroups', N_('List all host groups for a Puppet class'), {})
12
11
 
13
- apipie_update_methods([:index]) do
14
- param :puppetclass_id, String, desc: N_('ID of Puppetclass')
15
- end
12
+ apipie_update_methods([:index]) do
13
+ param :puppetclass_id, String, desc: N_('ID of Puppetclass')
14
+ end
16
15
 
17
- apipie_update_methods(%i[create update]) do
18
- param :hostgroup, Hash do
19
- param :environment_id, String, desc: N_('Deprecated in favor of hostgroup/puppet_attributes/environment_id')
20
- param :puppetclass_ids, Array, desc: N_('Deprecated in favor of hostgroup/puppet_attributes/puppetclass_ids')
21
- param :config_group_ids, Array, desc: N_('Deprecated in favor of hostgroup/puppet_attributes/config_group_ids')
16
+ apipie_update_methods(%i[create update]) do
17
+ param :hostgroup, Hash do
18
+ param :environment_id, String, desc: N_('Deprecated in favor of hostgroup/puppet_attributes/environment_id')
19
+ param :puppetclass_ids, Array, desc: N_('Deprecated in favor of hostgroup/puppet_attributes/puppetclass_ids')
20
+ param :config_group_ids, Array, desc: N_('Deprecated in favor of hostgroup/puppet_attributes/config_group_ids')
22
21
 
23
- param :puppet_attributes, Hash do
24
- param :environment_id, String, desc: N_('ID of associated puppet Environment')
25
- param :puppetclass_ids, Array, desc: N_('IDs of associated Puppetclasses')
26
- param :config_group_ids, Array, desc: N_('IDs of associated ConfigGroups')
27
- end
22
+ param :puppet_attributes, Hash do
23
+ param :environment_id, String, desc: N_('ID of associated puppet Environment')
24
+ param :puppetclass_ids, Array, desc: N_('IDs of associated Puppetclasses')
25
+ param :config_group_ids, Array, desc: N_('IDs of associated ConfigGroups')
28
26
  end
29
27
  end
30
28
  end
@@ -1,6 +1,6 @@
1
1
  module ForemanPuppet
2
- module Api
3
- module ImportPuppetclassesCommonController
2
+ module Extensions
3
+ module ApiSmartProxiesController
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
@@ -74,7 +74,13 @@ module ForemanPuppet
74
74
  end
75
75
 
76
76
  unless @environments.any?
77
- render_message(_('No changes to your environments detected'))
77
+ # check if environment id/name was valid at all
78
+ if @env_id && \
79
+ Environment.authorized(:view_environments).where(name: @env_id).or(Environment.authorized(:view_environments).where(id: @env_id)).empty?
80
+ render_message(_('The requested environment cannot be found.'))
81
+ else
82
+ render_message(_('No changes to your environments detected'))
83
+ end
78
84
  return false
79
85
  end
80
86
 
@@ -4,7 +4,29 @@ module ForemanPuppet
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- if ForemanPuppet.extracted_from_core?
7
+ if Gem::Dependency.new('', '>= 3.1').match?('', SETTINGS[:version].notag)
8
+ index_desc = Apipie.get_method_description(self, :index)
9
+ index_desc.apis << Apipie::MethodDescription::Api.new(:GET, '/environments/:environment_id/template_combinations', N_('List template combination'), {})
10
+
11
+ create_desc = Apipie.get_method_description(self, :create)
12
+ create_desc.apis << Apipie::MethodDescription::Api.new(:POST, '/environments/:environment_id/template_combinations', N_('Add a template combination'), {})
13
+
14
+ show_desc = Apipie.get_method_description(self, :show)
15
+ show_desc.apis << Apipie::MethodDescription::Api.new(:GET, '/environments/:environment_id/template_combinations/:id', N_('Show template combination'), {})
16
+
17
+ update_desc = Apipie.get_method_description(self, :update)
18
+ update_desc.apis << Apipie::MethodDescription::Api.new(:PUT, '/environments/:environment_id/template_combinations/:id', N_('Update template combination'), {})
19
+
20
+ apipie_update_methods(%i[index create show update]) do
21
+ param :environment_id, String, desc: N_('ID of Puppet environment')
22
+ end
23
+
24
+ apipie_update_methods(%i[create update]) do
25
+ param :template_combination, Hash do
26
+ param :environment_id, :number, allow_nil: true, desc: N_('environment id')
27
+ end
28
+ end
29
+ elsif ForemanPuppet.extracted_from_core?
8
30
  apipie_update_methods(%i[index create show update]) do
9
31
  param :environment_id, nil, desc: N_('ID of environment')
10
32
  end
@@ -6,25 +6,23 @@ module ForemanPuppet
6
6
  included do
7
7
  prepend PatchMethods
8
8
 
9
- if ForemanPuppet.extracted_from_core?
10
- method_desc = Apipie.get_method_description(self, :index)
11
- method_desc.apis << Apipie::MethodDescription::Api.new(:GET, '/environments/:environment_id/hosts', N_('List hosts per environment'), {})
9
+ method_desc = Apipie.get_method_description(self, :index)
10
+ method_desc.apis << Apipie::MethodDescription::Api.new(:GET, '/environments/:environment_id/hosts', N_('List hosts per environment'), {})
12
11
 
13
- apipie_update_methods([:index]) do
14
- param :environment_id, String, desc: N_('ID of puppet environment')
15
- end
12
+ apipie_update_methods([:index]) do
13
+ param :environment_id, String, desc: N_('ID of puppet environment')
14
+ end
16
15
 
17
- apipie_update_methods(%i[create update]) do
18
- param :host, Hash do
19
- param :environment_id, String, desc: N_('Deprecated in favor of host/puppet_attributes/environment_id')
20
- param :puppetclass_ids, Array, desc: N_('Deprecated in favor of host/puppet_attributes/puppetclass_ids')
21
- param :config_group_ids, Array, desc: N_('Deprecated in favor of host/puppet_attributes/config_group_ids')
16
+ apipie_update_methods(%i[create update]) do
17
+ param :host, Hash do
18
+ param :environment_id, String, desc: N_('Deprecated in favor of host/puppet_attributes/environment_id')
19
+ param :puppetclass_ids, Array, desc: N_('Deprecated in favor of host/puppet_attributes/puppetclass_ids')
20
+ param :config_group_ids, Array, desc: N_('Deprecated in favor of host/puppet_attributes/config_group_ids')
22
21
 
23
- param :puppet_attributes, Hash do
24
- param :environment_id, String, desc: N_('ID of associated puppet Environment')
25
- param :puppetclass_ids, Array, desc: N_('IDs of associated Puppetclasses')
26
- param :config_group_ids, Array, desc: N_('IDs of associated ConfigGroups')
27
- end
22
+ param :puppet_attributes, Hash do
23
+ param :environment_id, String, desc: N_('ID of associated puppet Environment')
24
+ param :puppetclass_ids, Array, desc: N_('IDs of associated Puppetclasses')
25
+ param :config_group_ids, Array, desc: N_('IDs of associated ConfigGroups')
28
26
  end
29
27
  end
30
28
  end
@@ -39,7 +37,7 @@ module ForemanPuppet
39
37
 
40
38
  def allowed_nested_id
41
39
  ids = super
42
- ids << 'environment_id' if ForemanPuppet.extracted_from_core?
40
+ ids << 'environment_id'
43
41
  ids.uniq
44
42
  end
45
43
  end
@@ -31,7 +31,6 @@ module ForemanPuppet
31
31
  helper ForemanPuppet::PuppetclassLookupKeysHelper
32
32
  end
33
33
 
34
- # TODO: unless ForemanPuppet.extracted_from_core?
35
34
  def select_multiple_puppet_proxy_hosts_path(*args)
36
35
  foreman_puppet.select_multiple_puppet_proxy_hosts_path(*args)
37
36
  end
@@ -14,7 +14,12 @@ module ForemanPuppet
14
14
  module PatchedClassMethods
15
15
  def host_params_filter
16
16
  super.tap do |filter|
17
- add_host_puppet_params_filter(filter)
17
+ filter.permit :environment_id, :environment_name, :environment,
18
+ config_groups: [], config_group_ids: [], config_group_names: [],
19
+ puppetclasses: [], puppetclass_ids: [], puppetclass_names: []
20
+
21
+ # TODO: bring to core - this is what facets should do, but does not
22
+ filter.permit(puppet_attributes: {})
18
23
  end
19
24
  end
20
25
  end
@@ -22,54 +27,40 @@ module ForemanPuppet
22
27
  module PatchedMethods
23
28
  def host_params(*attrs)
24
29
  params = super(*attrs)
25
- process_deprecated_puppet_params!(params)
26
- params
27
- end
28
- end
29
30
 
30
- class_methods do
31
- def add_host_puppet_params_filter(filter)
32
- filter.permit :environment_id, :environment_name, :environment,
33
- config_groups: [], config_group_ids: [], config_group_names: [],
34
- puppetclasses: [], puppetclass_ids: [], puppetclass_names: []
35
-
36
- # TODO: bring to core - this is what facets should do, but does not
37
- filter.permit(puppet_attributes: {})
31
+ process_deprecated_environment_params!(params)
32
+ process_deprecated_attributes!(params)
33
+ params
38
34
  end
39
- end
40
35
 
41
- def process_deprecated_puppet_params!(params, top_level_hash = controller_name.singularize)
42
- process_deprecated_environment_params!(params, top_level_hash)
43
- process_deprecated_attributes!(params, top_level_hash)
44
- end
45
-
46
- def process_deprecated_environment_params!(params, top_level_hash = 'host')
47
- env_id = params.delete(:environment_id)
48
- env_name = params.delete(:environment_name)
49
- env = params.delete(:environment)
36
+ def process_deprecated_environment_params!(params)
37
+ env_id = params.delete(:environment_id)
38
+ env_name = params.delete(:environment_name)
39
+ env = params.delete(:environment)
50
40
 
51
- return unless env_id || env_name || env
52
- ::Foreman::Deprecation.api_deprecation_warning("param #{top_level_hash}[environment_*] has been deprecated in favor of #{top_level_hash}[puppet_attributes][environment_*]")
41
+ return unless env_id || env_name || env
42
+ ::Foreman::Deprecation.api_deprecation_warning('param host[environment_*] has been deprecated in favor of host[puppet_attributes][environment_*]')
53
43
 
54
- params[:puppet_attributes] ||= {}
55
- params[:puppet_attributes][:environment_id] ||= env_id if env_id
56
- params[:puppet_attributes][:environment_name] ||= env_name if env_name
57
- params[:puppet_attributes][:environment] ||= env if env
58
- end
44
+ params[:puppet_attributes] ||= {}
45
+ params[:puppet_attributes][:environment_id] ||= env_id if env_id
46
+ params[:puppet_attributes][:environment_name] ||= env_name if env_name
47
+ params[:puppet_attributes][:environment] ||= env if env
48
+ end
59
49
 
60
- def process_deprecated_attributes!(params, top_level_hash = 'host')
61
- %w[puppetclass config_group].each do |relation|
62
- ids = params.delete("#{relation}_ids".to_sym)
63
- names = params.delete("#{relation}_names".to_sym)
64
- plains = params.delete(relation.pluralize.to_sym)
50
+ def process_deprecated_attributes!(params)
51
+ %w[puppetclass config_group].each do |relation|
52
+ ids = params.delete("#{relation}_ids".to_sym)
53
+ names = params.delete("#{relation}_names".to_sym)
54
+ plains = params.delete(relation.pluralize.to_sym)
65
55
 
66
- next unless ids || names || plains
67
- ::Foreman::Deprecation.api_deprecation_warning("param #{top_level_hash}[#{relation}_*] has been deprecated in favor of #{top_level_hash}[puppet_attributes][#{relation}_*]")
56
+ next unless ids || names || plains
57
+ ::Foreman::Deprecation.api_deprecation_warning("param host[#{relation}_*] has been deprecated in favor of host[puppet_attributes][#{relation}_*]")
68
58
 
69
- params[:puppet_attributes] ||= {}
70
- params[:puppet_attributes]["#{relation}_ids".to_sym] ||= ids if ids
71
- params[:puppet_attributes]["#{relation}_names".to_sym] ||= names if names
72
- params[:puppet_attributes][relation.pluralize.to_sym] ||= plains if plains
59
+ params[:puppet_attributes] ||= {}
60
+ params[:puppet_attributes]["#{relation}_ids".to_sym] ||= ids if ids
61
+ params[:puppet_attributes]["#{relation}_names".to_sym] ||= names if names
62
+ params[:puppet_attributes][relation.pluralize.to_sym] ||= plains if plains
63
+ end
73
64
  end
74
65
  end
75
66
  end
@@ -14,7 +14,12 @@ module ForemanPuppet
14
14
  module PatchedClassMethods
15
15
  def hostgroup_params_filter
16
16
  super.tap do |filter|
17
- add_hostgroup_puppet_params_filter(filter)
17
+ filter.permit :environment_id, :environment_name,
18
+ config_group_ids: [], config_group_names: [],
19
+ puppetclass_ids: [], puppetclass_names: []
20
+
21
+ # TODO: bring to core - this is what facets should do, but does not
22
+ filter.permit(puppet_attributes: {})
18
23
  end
19
24
  end
20
25
  end
@@ -22,56 +27,36 @@ module ForemanPuppet
22
27
  module PatchedMethods
23
28
  def hostgroup_params(*attrs)
24
29
  params = super(*attrs)
25
- process_deprecated_hostgroup_puppet_params!(params)
26
- params
27
- end
28
- end
29
30
 
30
- class_methods do
31
- def add_hostgroup_puppet_params_filter(filter)
32
- filter.permit :environment_id, :environment_name,
33
- config_group_ids: [], config_group_names: [],
34
- puppetclass_ids: [], puppetclass_names: []
35
-
36
- # TODO: bring to core - this is what facets should do, but does not
37
- filter.permit(puppet_attributes: {})
31
+ process_deprecated_hostgroup_environment_params!(params)
32
+ process_deprecated_hostgroup_attributes!(params)
33
+ params
38
34
  end
39
- end
40
35
 
41
- def process_deprecated_hostgroup_puppet_params!(params, top_level_hash = 'hostgroup')
42
- process_deprecated_hostgroup_environment_params!(params, top_level_hash)
43
- process_deprecated_hostgroup_attributes!(params, top_level_hash)
44
- end
45
-
46
- def process_deprecated_hostgroup_environment_params!(params, top_level_hash = 'hostgroup')
47
- env_id = env_name = nil
48
- if ForemanPuppet.extracted_from_core?
36
+ def process_deprecated_hostgroup_environment_params!(params)
49
37
  env_id = params.delete(:environment_id)
50
38
  env_name = params.delete(:environment_name)
51
- else
52
- env_id = params[:environment_id]
53
- env_name = params[:environment_name]
54
- end
55
39
 
56
- return unless env_id || env_name
57
- ::Foreman::Deprecation.api_deprecation_warning("param #{top_level_hash}[environment_*] has been deprecated in favor of #{top_level_hash}[puppet_attributes][environment_*]")
40
+ return unless env_id || env_name
41
+ ::Foreman::Deprecation.api_deprecation_warning('param hostgroup[environment_*] has been deprecated in favor of hostgroup[puppet_attributes][environment_*]')
58
42
 
59
- params[:puppet_attributes] ||= {}
60
- params[:puppet_attributes][:environment_id] ||= env_id if env_id
61
- params[:puppet_attributes][:environment_name] ||= env_name if env_name
62
- end
43
+ params[:puppet_attributes] ||= {}
44
+ params[:puppet_attributes][:environment_id] ||= env_id if env_id
45
+ params[:puppet_attributes][:environment_name] ||= env_name if env_name
46
+ end
63
47
 
64
- def process_deprecated_hostgroup_attributes!(params, top_level_hash = 'hostgroup')
65
- %w[puppetclass config_group].each do |relation|
66
- ids = params.delete("#{relation}_ids")
67
- names = params.delete("#{relation}_names")
48
+ def process_deprecated_hostgroup_attributes!(params)
49
+ %w[puppetclass config_group].each do |relation|
50
+ ids = params.delete("#{relation}_ids")
51
+ names = params.delete("#{relation}_names")
68
52
 
69
- next unless ids || names
70
- ::Foreman::Deprecation.api_deprecation_warning("param #{top_level_hash}[#{relation}_*] has been deprecated in favor of #{top_level_hash}[puppet_attributes][#{relation}_*]")
53
+ next unless ids || names
54
+ ::Foreman::Deprecation.api_deprecation_warning("param hostgroup[#{relation}_*] has been deprecated in favor of hostgroup[puppet_attributes][#{relation}_*]")
71
55
 
72
- params[:puppet_attributes] ||= {}
73
- params[:puppet_attributes]["#{relation}_ids".to_sym] ||= ids if ids
74
- params[:puppet_attributes]["#{relation}_names".to_sym] ||= names if names
56
+ params[:puppet_attributes] ||= {}
57
+ params[:puppet_attributes]["#{relation}_ids".to_sym] ||= ids if ids
58
+ params[:puppet_attributes]["#{relation}_names".to_sym] ||= names if names
59
+ end
75
60
  end
76
61
  end
77
62
  end
@@ -2,7 +2,6 @@ module ForemanPuppet
2
2
  module Api
3
3
  module V2
4
4
  class EnvironmentsController < ::ForemanPuppet::Api::V2::PuppetBaseController
5
- include ForemanPuppet::Api::ImportPuppetclassesCommonController
6
5
  include ForemanPuppet::Parameters::Environment
7
6
 
8
7
  resource_description do
@@ -14,7 +14,7 @@ module ForemanPuppet
14
14
 
15
15
  helper ForemanPuppet::PuppetclassLookupKeysHelper
16
16
 
17
- # TODO: extracted_from_core?
17
+ # TODO: filter for facets needs improving
18
18
  def host_params(top_level_hash = controller_name.singularize)
19
19
  filter = self.class.host_params_filter
20
20
  filter.permit(puppet_attributes: {})
@@ -1,10 +1,5 @@
1
1
  module ForemanPuppet
2
2
  module HostsAndHostgroupsHelper
3
- # TODO: remove me - prevents the puppetclass tab duplication
4
- # unless ForemanPuppet.extracted_from_core?
5
- def puppetclasses_tab(puppetclasses_receiver)
6
- end
7
-
8
3
  def environment_inherited_by_default?(host)
9
4
  return false unless host.hostgroup && host.hostgroup_id_was.nil?
10
5
  return false if params[:action] == 'clone'
@@ -3,20 +3,16 @@ module ForemanPuppet
3
3
  UI.register_host_description do
4
4
  multiple_actions_provider :puppet_host_multiple_actions
5
5
  # otherwise registered twice
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?
6
+ overview_buttons_provider :puppet_host_overview_buttons
7
+ overview_fields_provider :puppet_host_overview_fields
8
8
  end
9
9
 
10
10
  def puppet_host_multiple_actions
11
- if ForemanPuppet.extracted_from_core?
12
- actions = [{ action: [_('Change Environment'), foreman_puppet.select_multiple_environment_hosts_path], priority: 200 }]
13
- if authorized_for(controller: :hosts, action: :edit) && SmartProxy.unscoped.authorized.with_features('Puppet').exists?
14
- actions << { action: [_('Change Puppet Master'), foreman_puppet.select_multiple_puppet_proxy_hosts_path], priority: 1050 }
15
- end
16
- actions
17
- else
18
- []
11
+ actions = [{ action: [_('Change Environment'), foreman_puppet.select_multiple_environment_hosts_path], priority: 200 }]
12
+ if authorized_for(controller: :hosts, action: :edit) && SmartProxy.unscoped.authorized.with_features('Puppet').exists?
13
+ actions << { action: [_('Change Puppet Master'), foreman_puppet.select_multiple_puppet_proxy_hosts_path], priority: 1050 }
19
14
  end
15
+ actions
20
16
  end
21
17
 
22
18
  def puppet_host_overview_buttons(host)
@@ -3,20 +3,12 @@ module ForemanPuppet
3
3
  module Host
4
4
  extend ActiveSupport::Concern
5
5
 
6
- include ForemanPuppet::Extensions::HostCommon if ForemanPuppet.extracted_from_core?
6
+ include ForemanPuppet::Extensions::HostCommon
7
7
 
8
8
  included do
9
9
  prepend PrependedMethods
10
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
+ has_one :environment, through: :puppet, class_name: 'ForemanPuppet::Environment'
20
12
 
21
13
  include_in_clone puppet: %i[config_groups host_config_groups host_classes]
22
14
 
@@ -70,12 +62,6 @@ module ForemanPuppet
70
62
  end
71
63
 
72
64
  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
-
79
65
  def provisioning_template(opts = {})
80
66
  opts[:environment_id] ||= puppet&.environment_id
81
67
  super(opts)
@@ -3,19 +3,14 @@ module ForemanPuppet
3
3
  module Hostgroup
4
4
  extend ActiveSupport::Concern
5
5
 
6
- include ForemanPuppet::Extensions::HostCommon if ForemanPuppet.extracted_from_core?
6
+ include ForemanPuppet::Extensions::HostCommon
7
7
 
8
8
  included do
9
9
  class << self
10
10
  prepend PatchedClassMethods
11
11
  end
12
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
+ has_one :environment, through: :puppet, class_name: 'ForemanPuppet::Environment'
19
14
 
20
15
  include_in_clone puppet: %i[host_config_groups config_groups hostgroup_classes]
21
16
 
@@ -4,21 +4,16 @@ module ForemanPuppet
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- if ForemanPuppet.extracted_from_core?
8
- has_many :environments, through: :template_combinations
9
- before_destroy ActiveRecord::Base::EnsureNotUsedBy.new(:environments)
7
+ has_many :environments, through: :template_combinations
8
+ before_destroy ActiveRecord::Base::EnsureNotUsedBy.new(:environments)
10
9
 
11
- scoped_search relation: :environments, on: :name, rename: :environment, complete_value: true
10
+ scoped_search relation: :environments, on: :name, rename: :environment, complete_value: true
12
11
 
13
- class << self
14
- prepend PrependedClassMethods
15
- end
16
-
17
- prepend PrependedMethods
18
- else
19
- env_assoc = reflect_on_association(:environments)
20
- env_assoc&.instance_variable_set(:@class_name, 'ForemanPuppet::Environment')
12
+ class << self
13
+ prepend PrependedClassMethods
21
14
  end
15
+
16
+ prepend PrependedMethods
22
17
  end
23
18
 
24
19
  module PrependedClassMethods
@@ -4,19 +4,14 @@ module ForemanPuppet
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- if ForemanPuppet.extracted_from_core?
8
- belongs_to :environment, class_name: 'ForemanPuppet::Environment'
7
+ belongs_to :environment, class_name: 'ForemanPuppet::Environment'
9
8
 
10
- validates :environment_id, uniqueness: { scope: %i[hostgroup_id provisioning_template_id] }
9
+ validates :environment_id, uniqueness: { scope: %i[hostgroup_id provisioning_template_id] }
11
10
 
12
- callback = __callbacks[:validate].detect do |v|
13
- v.filter.is_a?(ActiveRecord::Validations::UniquenessValidator) && v.filter.attributes.include?(:hostgroup_id)
14
- end
15
- callback.filter.options[:scope] << :environment_id
16
- else
17
- env_assoc = reflect_on_association(:environment)
18
- env_assoc&.instance_variable_set(:@class_name, 'ForemanPuppet::Environment')
11
+ callback = __callbacks[:validate].detect do |v|
12
+ v.filter.is_a?(ActiveRecord::Validations::UniquenessValidator) && v.filter.attributes.include?(:hostgroup_id)
19
13
  end
14
+ callback.filter.options[:scope] << :environment_id
20
15
  end
21
16
  end
22
17
  end
@@ -48,7 +48,7 @@ module ForemanPuppet
48
48
 
49
49
  def parent_config_groups
50
50
  return [] unless host.hostgroup
51
- host.hostgroup.puppet&.all_config_groups || []
51
+ host.hostgroup.puppet&.all_config_groups
52
52
  end
53
53
 
54
54
  def ensure_puppet_associations
@@ -48,8 +48,6 @@ module ForemanPuppet
48
48
  Hostgroup.sort_by_ancestry(hostgroup.ancestors.joins(:puppet).where(HostgroupPuppetFacet.arel_table[attr.to_sym].not_eq(nil))).last&.puppet.try(attr)
49
49
  end
50
50
 
51
- delegate :parent_id, to: :hostgroup
52
-
53
51
  # and helpers
54
52
  def parent_facet_id
55
53
  parent_facet&.id
@@ -308,12 +308,6 @@ module ForemanPuppet
308
308
  env.puppetclasses.destroy classes
309
309
  # remove all old classes from hosts
310
310
  HostClass.joins(host: :puppet).where(HostPuppetFacet.arel_table[:environment_id].eq(env.id)).where(puppetclass_id: classes).destroy_all
311
- unless ForemanPuppet.extracted_from_core?
312
- # rubocop:disable Rails/SkipsModelValidations
313
- Host.where(environment_id: env).update_all(environment_id: nil)
314
- Hostgroup.where(environment_id: env).update_all(environment_id: nil)
315
- # rubocop:enable Rails/SkipsModelValidations
316
- end
317
311
  # we can't guaranty that the env would be removed as it might have hosts attached to it.
318
312
  env.destroy if klasses.include? '_destroy_'
319
313
  # remove all klasses that have no environment now
@@ -0,0 +1,3 @@
1
+ glue(@facet) do
2
+ extends 'foreman_puppet/api/v2/host_puppet_facets/base'
3
+ end
@@ -1,3 +1,5 @@
1
+ object @facet
2
+
1
3
  attributes :environment_id, :environment_name
2
4
 
3
5
  ForemanPuppet::HostgroupPuppetFacet.nested_attribute_fields.each do |nested_field|
@@ -0,0 +1,3 @@
1
+ glue(@facet) do
2
+ extends 'foreman_puppet/api/v2/hostgroup_puppet_facets/base'
3
+ end
data/config/api_routes.rb CHANGED
@@ -2,14 +2,6 @@ ForemanPuppet::Engine.routes.draw do
2
2
  namespace :api, defaults: { format: 'json' } do
3
3
  scope '(:apiv)', module: :v2, defaults: { apiv: 'v2' }, apiv: /v1|v2/, constraints: ApiConstraints.new(version: 2, default: true) do
4
4
  constraints(id: %r{[^/]+}) do
5
- resources :puppet_smart_proxies, only: [] do
6
- post :import_puppetclasses, on: :member, controller: 'environments'
7
-
8
- resources :environments, only: [] do
9
- post :import_puppetclasses, on: :member
10
- end
11
- end
12
-
13
5
  resources :config_groups, except: %i[new edit]
14
6
 
15
7
  resources :hosts, only: [] do
@@ -40,7 +32,7 @@ ForemanPuppet::Engine.routes.draw do
40
32
  end
41
33
  end
42
34
  resources :hosts, only: %i[index show], controller: '/api/v2/hosts'
43
- resources :template_combinations, only: %i[index], controller: '/api/v2/template_combinations'
35
+ resources :template_combinations, only: %i[index show create update], controller: '/api/v2/template_combinations'
44
36
  end
45
37
 
46
38
  resources :puppetclasses, except: %i[new edit] do