foreman_puppet 11.0.0 → 11.2.0

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 (97) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/foreman_puppet/locale/ca/foreman_puppet.js +181 -1
  3. data/app/assets/javascripts/foreman_puppet/locale/cs_CZ/foreman_puppet.js +181 -1
  4. data/app/assets/javascripts/foreman_puppet/locale/de/foreman_puppet.js +181 -1
  5. data/app/assets/javascripts/foreman_puppet/locale/en/foreman_puppet.js +181 -1
  6. data/app/assets/javascripts/foreman_puppet/locale/en_GB/foreman_puppet.js +181 -1
  7. data/app/assets/javascripts/foreman_puppet/locale/es/foreman_puppet.js +181 -1
  8. data/app/assets/javascripts/foreman_puppet/locale/fr/foreman_puppet.js +181 -1
  9. data/app/assets/javascripts/foreman_puppet/locale/gl/foreman_puppet.js +181 -1
  10. data/app/assets/javascripts/foreman_puppet/locale/it/foreman_puppet.js +181 -1
  11. data/app/assets/javascripts/foreman_puppet/locale/ja/foreman_puppet.js +181 -1
  12. data/app/assets/javascripts/foreman_puppet/locale/ka/foreman_puppet.js +192 -12
  13. data/app/assets/javascripts/foreman_puppet/locale/ko/foreman_puppet.js +181 -1
  14. data/app/assets/javascripts/foreman_puppet/locale/nl_NL/foreman_puppet.js +181 -1
  15. data/app/assets/javascripts/foreman_puppet/locale/pl/foreman_puppet.js +181 -1
  16. data/app/assets/javascripts/foreman_puppet/locale/pt_BR/foreman_puppet.js +181 -1
  17. data/app/assets/javascripts/foreman_puppet/locale/ru/foreman_puppet.js +181 -1
  18. data/app/assets/javascripts/foreman_puppet/locale/sv_SE/foreman_puppet.js +181 -1
  19. data/app/assets/javascripts/foreman_puppet/locale/zh_CN/foreman_puppet.js +181 -1
  20. data/app/assets/javascripts/foreman_puppet/locale/zh_TW/foreman_puppet.js +181 -1
  21. data/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb +1 -1
  22. data/app/controllers/foreman_puppet/api/v2/hosts_bulk_actions_controller.rb +75 -1
  23. data/app/models/foreman_puppet/config_group.rb +3 -1
  24. data/app/models/foreman_puppet/host_config_group.rb +12 -0
  25. data/app/models/foreman_puppet/puppetclass.rb +14 -3
  26. data/app/services/concerns/foreman_puppet/extensions/bulk_hosts_manager.rb +18 -0
  27. data/config/api_routes.rb +1 -0
  28. data/db/seeds.d/111_puppet_proxy_feature.rb +1 -1
  29. data/lib/foreman_puppet/register.rb +1 -0
  30. data/lib/foreman_puppet/version.rb +1 -1
  31. data/locale/ca/LC_MESSAGES/foreman_puppet.mo +0 -0
  32. data/locale/ca/foreman_puppet.po +187 -1
  33. data/locale/cs_CZ/LC_MESSAGES/foreman_puppet.mo +0 -0
  34. data/locale/cs_CZ/foreman_puppet.po +187 -1
  35. data/locale/de/LC_MESSAGES/foreman_puppet.mo +0 -0
  36. data/locale/de/foreman_puppet.po +188 -2
  37. data/locale/en/LC_MESSAGES/foreman_puppet.mo +0 -0
  38. data/locale/en/foreman_puppet.po +187 -1
  39. data/locale/en_GB/LC_MESSAGES/foreman_puppet.mo +0 -0
  40. data/locale/en_GB/foreman_puppet.po +187 -1
  41. data/locale/es/LC_MESSAGES/foreman_puppet.mo +0 -0
  42. data/locale/es/foreman_puppet.po +187 -1
  43. data/locale/foreman_puppet.pot +312 -13
  44. data/locale/fr/LC_MESSAGES/foreman_puppet.mo +0 -0
  45. data/locale/fr/foreman_puppet.po +187 -1
  46. data/locale/gl/LC_MESSAGES/foreman_puppet.mo +0 -0
  47. data/locale/gl/foreman_puppet.po +187 -1
  48. data/locale/it/LC_MESSAGES/foreman_puppet.mo +0 -0
  49. data/locale/it/foreman_puppet.po +187 -1
  50. data/locale/ja/LC_MESSAGES/foreman_puppet.mo +0 -0
  51. data/locale/ja/foreman_puppet.po +187 -1
  52. data/locale/ka/LC_MESSAGES/foreman_puppet.mo +0 -0
  53. data/locale/ka/foreman_puppet.po +199 -13
  54. data/locale/ko/LC_MESSAGES/foreman_puppet.mo +0 -0
  55. data/locale/ko/foreman_puppet.po +187 -1
  56. data/locale/nl_NL/LC_MESSAGES/foreman_puppet.mo +0 -0
  57. data/locale/nl_NL/foreman_puppet.po +187 -1
  58. data/locale/pl/LC_MESSAGES/foreman_puppet.mo +0 -0
  59. data/locale/pl/foreman_puppet.po +187 -1
  60. data/locale/pt_BR/LC_MESSAGES/foreman_puppet.mo +0 -0
  61. data/locale/pt_BR/foreman_puppet.po +187 -1
  62. data/locale/ru/LC_MESSAGES/foreman_puppet.mo +0 -0
  63. data/locale/ru/foreman_puppet.po +187 -1
  64. data/locale/sv_SE/LC_MESSAGES/foreman_puppet.mo +0 -0
  65. data/locale/sv_SE/foreman_puppet.po +187 -1
  66. data/locale/zh_CN/LC_MESSAGES/foreman_puppet.mo +0 -0
  67. data/locale/zh_CN/foreman_puppet.po +187 -1
  68. data/locale/zh_TW/LC_MESSAGES/foreman_puppet.mo +0 -0
  69. data/locale/zh_TW/foreman_puppet.po +187 -1
  70. data/test/controllers/foreman_puppet/api/v2/hosts_bulk_actions_controller_test.rb +93 -0
  71. data/test/models/foreman_puppet/host_test.rb +50 -0
  72. data/test/models/foreman_puppet/hostgroup_test.rb +50 -0
  73. data/test/services/foreman_puppet/bulk_hosts_manager_test.rb +45 -0
  74. data/webpack/__mocks__/foremanReact/redux/API/index.js +8 -0
  75. data/webpack/global_index.js +18 -1
  76. data/webpack/src/Extends/Hosts/ActionsBar/index.js +20 -0
  77. data/webpack/src/Extends/Hosts/BulkActions/BulkChangeProxyCommon/__tests__/actions.test.js +0 -7
  78. data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetEnvironment/BulkChangePuppetEnvironmentModal.js +239 -0
  79. data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetEnvironment/__tests__/BulkChangePuppetEnvironmentModal.test.js +155 -0
  80. data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetEnvironment/__tests__/actions.test.js +49 -0
  81. data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetEnvironment/__tests__/index.test.js +66 -0
  82. data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetEnvironment/actions.js +37 -0
  83. data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetEnvironment/index.js +30 -0
  84. data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetProxy/__tests__/index.test.js +160 -47
  85. data/webpack/src/Extends/Hosts/BulkActions/BulkRemoveProxyCommon/__tests__/actions.test.js +0 -6
  86. data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetCAProxy/__tests__/index.test.js +136 -39
  87. data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetEnvironment/BulkRemovePuppetEnvironmentModal.js +148 -0
  88. data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetEnvironment/__tests__/BulkRemovePuppetEnvironmentModal.test.js +80 -0
  89. data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetEnvironment/__tests__/index.test.js +66 -0
  90. data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetEnvironment/index.js +30 -0
  91. data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetProxy/__tests__/index.test.js +123 -34
  92. data/webpack/src/Router/routes.fixtures.js +13 -0
  93. data/webpack/src/Router/routes.test.js +68 -8
  94. data/webpack/src/foreman_puppet_host_form.test.js +3 -1
  95. data/webpack/test_setup.js +1 -0
  96. metadata +14 -3
  97. data/webpack/src/Router/__snapshots__/routes.test.js.snap +0 -3
@@ -10,7 +10,7 @@
10
10
  #
11
11
  msgid ""
12
12
  msgstr ""
13
- "Project-Id-Version: foreman_puppet 9.0.0\n"
13
+ "Project-Id-Version: foreman_puppet 11.1.0\n"
14
14
  "Report-Msgid-Bugs-To: \n"
15
15
  "PO-Revision-Date: 2021-02-03 16:30+0000\n"
16
16
  "Last-Translator: 0868a4d1af5275b3f70b0a6dac4c99a4, 2023\n"
@@ -55,6 +55,12 @@ msgid ""
55
55
  " <b>Inherited value:</b> %{inherited_value}"
56
56
  msgstr ""
57
57
 
58
+ msgid "A Puppet environment with id %{id} could not be found."
59
+ msgstr ""
60
+
61
+ msgid "A Smart Proxy with id %{id} and the %{proxy_type} feature could not be found."
62
+ msgstr ""
63
+
58
64
  msgid "A config group provides a one-step method of associating many Puppet classes to either a host or host group. Typically this would be used to add a particular application profile or stack in one step."
59
65
  msgstr ""
60
66
 
@@ -79,6 +85,9 @@ msgstr "新增範本組合"
79
85
  msgid "Add:"
80
86
  msgstr "新增:"
81
87
 
88
+ msgid "All"
89
+ msgstr ""
90
+
82
91
  msgid "All environments - (not filtered)"
83
92
  msgstr "所有環境 -(未篩選)"
84
93
 
@@ -106,15 +115,54 @@ msgstr "取消"
106
115
  msgid "Change Environment"
107
116
  msgstr "更改環境"
108
117
 
118
+ msgid "Change Puppet (CA) Proxy"
119
+ msgstr ""
120
+
121
+ msgid "Change Puppet CA Proxy"
122
+ msgstr ""
123
+
124
+ msgid "Change Puppet CA proxy"
125
+ msgstr ""
126
+
127
+ msgid "Change Puppet Environment"
128
+ msgstr ""
129
+
109
130
  msgid "Change Puppet Master"
110
131
  msgstr "改變 Puppet Master"
111
132
 
133
+ msgid "Change Puppet Proxy"
134
+ msgstr ""
135
+
136
+ msgid "Change Puppet environment"
137
+ msgstr ""
138
+
139
+ msgid "Change Puppet proxy"
140
+ msgstr ""
141
+
112
142
  msgid "Changed"
113
143
  msgstr ""
114
144
 
115
145
  msgid "Changed environments"
116
146
  msgstr "已更改的環境"
117
147
 
148
+ msgid "Changing the Puppet CA proxy will affect {boldCount} selected hosts. Some hosts may already have been associated with the selected Puppet CA proxy."
149
+ msgstr ""
150
+
151
+ msgid "Changing the Puppet CA proxy will affect {boldCount} selected {count, plural, one {host} other {hosts}}. Some hosts may already have been associated with the selected Puppet CA proxy."
152
+ msgstr ""
153
+
154
+ msgid "Changing the Puppet environment will affect {boldCount} selected hosts. Some hosts may already have been associated with the selected environment."
155
+ msgstr ""
156
+
157
+ msgid "Changing the Puppet environment will affect {boldCount} selected {count, plural, one {host} other {hosts}}. Some hosts may already have been associated with the selected environment."
158
+ msgstr ""
159
+
160
+ msgid "Changing the Puppet proxy will affect {boldCount} selected hosts. Some hosts may already have been associated with the selected Puppet proxy."
161
+ msgstr ""
162
+
163
+ msgid "Changing the Puppet proxy will affect {boldCount} selected {count, plural, one {host} other {hosts}}. Some hosts may already have been associated with the selected Puppet proxy."
164
+ msgstr ""
165
+
118
166
  msgid "Check/Uncheck all"
119
167
  msgstr "選取/反選全部"
120
168
 
@@ -271,12 +319,51 @@ msgstr "詳情"
271
319
  msgid "Failed"
272
320
  msgstr ""
273
321
 
322
+ msgid "Failed to change %{proxy_type} for %{count} host"
323
+ msgid_plural "Failed to change %{proxy_type} for %{count} hosts"
324
+ msgstr[0] ""
325
+ msgstr[1] ""
326
+
327
+ msgid "Failed to change Puppet CA Proxy"
328
+ msgstr ""
329
+
330
+ msgid "Failed to change Puppet Environment"
331
+ msgstr ""
332
+
333
+ msgid "Failed to change Puppet Proxy"
334
+ msgstr ""
335
+
336
+ msgid "Failed to change environment for %{count} host"
337
+ msgid_plural "Failed to change environment for %{count} hosts"
338
+ msgstr[0] ""
339
+ msgstr[1] ""
340
+
274
341
  msgid "Failed to import %{klass} for %{name}: doesn't exists in our database - ignoring"
275
342
  msgstr "為 %{name} 匯入 %{klass} 失敗:不存在我們的資料庫中 - 將被忽略"
276
343
 
344
+ msgid "Failed to remove %{proxy_type} for %{count} host"
345
+ msgid_plural "Failed to remove %{proxy_type} for %{count} hosts"
346
+ msgstr[0] ""
347
+ msgstr[1] ""
348
+
349
+ msgid "Failed to remove Puppet CA Proxy"
350
+ msgstr ""
351
+
352
+ msgid "Failed to remove Puppet Environment"
353
+ msgstr ""
354
+
355
+ msgid "Failed to remove Puppet Proxy"
356
+ msgstr ""
357
+
277
358
  msgid "Failed to set %{proxy_type} proxy for %{host}."
278
359
  msgstr "設定 %{proxy_type} 代理給 %{host} 時失敗。"
279
360
 
361
+ msgid "Failed to set Puppet environment for %{host}."
362
+ msgstr ""
363
+
364
+ msgid "Failed to set proxy for %{host}."
365
+ msgstr ""
366
+
280
367
  msgid "Failed to start"
281
368
  msgstr ""
282
369
 
@@ -358,6 +445,15 @@ msgstr "主機群組的 ID"
358
445
  msgid "ID of puppet environment"
359
446
  msgstr ""
360
447
 
448
+ msgid "ID of the Puppet environment to set for the selected hosts"
449
+ msgstr ""
450
+
451
+ msgid "ID of the Puppet proxy to reassign the hosts to"
452
+ msgstr ""
453
+
454
+ msgid "ID of the organization"
455
+ msgstr ""
456
+
361
457
  msgid "IDs of associated ConfigGroups"
362
458
  msgstr ""
363
459
 
@@ -460,6 +556,12 @@ msgstr "列出各個環境中的主機"
460
556
  msgid "List of config groups"
461
557
  msgstr "配置群組清單"
462
558
 
559
+ msgid "List of host ids to exclude and not run an action on"
560
+ msgstr ""
561
+
562
+ msgid "List of host ids to perform an action on"
563
+ msgstr ""
564
+
463
565
  msgid "List of override values for a specific smart class parameter"
464
566
  msgstr "特定智慧型類別參數的置換值之清單"
465
567
 
@@ -607,6 +709,9 @@ msgstr "Puppet CA"
607
709
  msgid "Puppet CA Smart Proxy"
608
710
  msgstr ""
609
711
 
712
+ msgid "Puppet CA proxy"
713
+ msgstr ""
714
+
610
715
  msgid "Puppet Class"
611
716
  msgstr "Puppet 類別"
612
717
 
@@ -661,6 +766,9 @@ msgstr ""
661
766
  msgid "Puppet parameter"
662
767
  msgstr "Puppet 參數"
663
768
 
769
+ msgid "Puppet proxy"
770
+ msgstr ""
771
+
664
772
  msgid "Puppetclass|Name"
665
773
  msgstr "名稱"
666
774
 
@@ -670,6 +778,27 @@ msgstr "移除"
670
778
  msgid "Remove Combination"
671
779
  msgstr ""
672
780
 
781
+ msgid "Remove Puppet (CA) Proxy"
782
+ msgstr ""
783
+
784
+ msgid "Remove Puppet CA Proxy"
785
+ msgstr ""
786
+
787
+ msgid "Remove Puppet CA proxy"
788
+ msgstr ""
789
+
790
+ msgid "Remove Puppet Environment"
791
+ msgstr ""
792
+
793
+ msgid "Remove Puppet Proxy"
794
+ msgstr ""
795
+
796
+ msgid "Remove Puppet environment"
797
+ msgstr ""
798
+
799
+ msgid "Remove Puppet proxy"
800
+ msgstr ""
801
+
673
802
  msgid "Remove a Puppet class from host"
674
803
  msgstr "從主機移除一個 Puppet 類別"
675
804
 
@@ -685,6 +814,24 @@ msgstr "移除此置換"
685
814
  msgid "Remove:"
686
815
  msgstr "移除:"
687
816
 
817
+ msgid "Removing the Puppet CA proxy will affect {boldCount} selected hosts. Warning: If a Puppet Proxy is still set, the Puppet CA Proxy will fall back to that value after removal!"
818
+ msgstr ""
819
+
820
+ msgid "Removing the Puppet CA proxy will affect {boldCount} selected {count, plural, one {host} other {hosts}}. Warning: If a Puppet Proxy is still set, the Puppet CA Proxy will fall back to that value after removal!"
821
+ msgstr ""
822
+
823
+ msgid "Removing the Puppet environment will affect {boldCount} selected hosts."
824
+ msgstr ""
825
+
826
+ msgid "Removing the Puppet environment will affect {boldCount} selected {count, plural, one {host} other {hosts}}."
827
+ msgstr ""
828
+
829
+ msgid "Removing the Puppet proxy will affect {boldCount} selected hosts."
830
+ msgstr ""
831
+
832
+ msgid "Removing the Puppet proxy will affect {boldCount} selected {count, plural, one {host} other {hosts}}."
833
+ msgstr ""
834
+
688
835
  msgid "Reports"
689
836
  msgstr "報告"
690
837
 
@@ -697,12 +844,27 @@ msgstr ""
697
844
  msgid "Scheduled"
698
845
  msgstr ""
699
846
 
847
+ msgid "Search string for hosts to perform an action on"
848
+ msgstr ""
849
+
850
+ msgid "Select a Puppet CA Proxy"
851
+ msgstr ""
852
+
853
+ msgid "Select a Puppet Proxy"
854
+ msgstr ""
855
+
856
+ msgid "Select an Environment"
857
+ msgstr ""
858
+
700
859
  msgid "Select environment"
701
860
  msgstr "選擇環境"
702
861
 
703
862
  msgid "Select the changes you want to apply to Foreman"
704
863
  msgstr ""
705
864
 
865
+ msgid "Selected Puppet environment is not assigned to the proper organization and/or location for all hosts."
866
+ msgstr ""
867
+
706
868
  msgid "Set parameters to defaults"
707
869
  msgstr "將參數設為預設值"
708
870
 
@@ -789,6 +951,9 @@ msgstr ""
789
951
  msgid "There are no puppet environments set up on this puppet master. Please check the puppet master configuration."
790
952
  msgstr "此 puppet master 上並未設定 puppet 環境。請檢查 puppet master 的配置。"
791
953
 
954
+ msgid "There is no Smart Proxy with the feature '%s' available."
955
+ msgstr ""
956
+
792
957
  msgid "This Puppet class has no parameters in its signature."
793
958
  msgstr "此 puppet 類別的簽章中沒有參數。"
794
959
 
@@ -810,6 +975,12 @@ msgstr "切換"
810
975
  msgid "Total"
811
976
  msgstr "總數"
812
977
 
978
+ msgid "True, if Puppet CA proxy should be changed instead of the Puppet proxy"
979
+ msgstr ""
980
+
981
+ msgid "True, if Puppet CA proxy should be removed instead of the Puppet proxy"
982
+ msgstr ""
983
+
813
984
  msgid "Types of validation values"
814
985
  msgstr "驗證值的類型"
815
986
 
@@ -849,6 +1020,21 @@ msgstr "更新:"
849
1020
  msgid "Updated"
850
1021
  msgstr "已更新"
851
1022
 
1023
+ msgid "Updated host: changed %{proxy_type}"
1024
+ msgid_plural "Updated hosts: changed %{proxy_type}"
1025
+ msgstr[0] ""
1026
+ msgstr[1] ""
1027
+
1028
+ msgid "Updated host: changed environment"
1029
+ msgid_plural "Updated hosts: changed environment"
1030
+ msgstr[0] ""
1031
+ msgstr[1] ""
1032
+
1033
+ msgid "Updated host: removed %{proxy_type}"
1034
+ msgid_plural "Updated hosts: removed %{proxy_type}"
1035
+ msgstr[0] ""
1036
+ msgstr[1] ""
1037
+
852
1038
  msgid "Updated hosts: changed environment"
853
1039
  msgstr "已更新主機:已更改的環境"
854
1040
 
@@ -16,8 +16,101 @@ module ForemanPuppet
16
16
  organization: host.organization,
17
17
  location: host.location)
18
18
  end
19
+ let(:environment) { FactoryBot.create(:environment, organizations: [host.organization], locations: [host.location]) }
20
+ let(:hostgroup_environment) { FactoryBot.create(:environment, organizations: [host.organization], locations: [host.location]) }
21
+ let(:hostgroup) do
22
+ FactoryBot.create(:hostgroup, :with_puppet_enc,
23
+ environment: hostgroup_environment,
24
+ organizations: [host.organization],
25
+ locations: [host.location])
26
+ end
19
27
  let(:proxy) { FactoryBot.create(:puppet_and_ca_smart_proxy, organizations: [host.organization], locations: [host.location]) }
20
28
 
29
+ def put_change_puppet_environment(params:, session: nil)
30
+ put :change_puppet_environment, params: params, session: session
31
+ end
32
+
33
+ test 'changes puppet environment for selected hosts' do
34
+ put_change_puppet_environment(params: bulk_params.merge(environment_id: environment.id))
35
+
36
+ assert_response :success
37
+ assert_equal environment.id, host2.reload.puppet.environment_id
38
+ assert_equal environment.id, host.reload.puppet.environment_id
39
+ end
40
+
41
+ test 'inherits puppet environment from hostgroups for selected hosts' do
42
+ host.update!(hostgroup: hostgroup)
43
+ host2.update!(hostgroup: hostgroup)
44
+
45
+ put_change_puppet_environment(params: bulk_params.merge(environment_id: 'inherit'))
46
+
47
+ assert_response :success
48
+ assert_equal hostgroup_environment.id, host2.reload.puppet.environment_id
49
+ assert_equal hostgroup_environment.id, host.reload.puppet.environment_id
50
+ end
51
+
52
+ test 'clears puppet environment for selected hosts' do
53
+ host.puppet.update!(environment: environment)
54
+ host2.puppet.update!(environment: environment)
55
+
56
+ put_change_puppet_environment(
57
+ params: bulk_params.merge(environment_id: nil),
58
+ session: set_session_user
59
+ )
60
+
61
+ assert_response :success
62
+ assert_nil host.reload.puppet.environment
63
+ assert_nil host2.reload.puppet.environment
64
+ end
65
+
66
+ test 'returns error when puppet environment is missing' do
67
+ missing_environment_id = 999_999
68
+
69
+ put_change_puppet_environment(
70
+ params: bulk_params.merge(environment_id: missing_environment_id),
71
+ session: set_session_user
72
+ )
73
+
74
+ assert_response :unprocessable_entity
75
+ response = JSON.parse(@response.body)
76
+ assert_equal "A Puppet environment with id #{missing_environment_id} could not be found.",
77
+ response.dig('error', 'message')
78
+ end
79
+
80
+ test 'returns error when changing puppet environment fails for some hosts' do
81
+ ::BulkHostsManager.any_instance.expects(:change_puppet_environment)
82
+ .with(environment)
83
+ .returns([host2.id])
84
+
85
+ put_change_puppet_environment(
86
+ params: bulk_params.merge(environment_id: environment.id),
87
+ session: set_session_user
88
+ )
89
+
90
+ assert_response :unprocessable_entity
91
+ response = JSON.parse(@response.body)
92
+ assert_equal 'Failed to change environment for 1 host',
93
+ response.dig('error', 'message')
94
+ assert_equal [host2.id], response.dig('error', 'failed_host_ids')
95
+ end
96
+
97
+ test 'returns error when puppet environment is outside host taxonomies' do
98
+ invalid_environment = FactoryBot.create(:environment,
99
+ organizations: [host.organization],
100
+ locations: [FactoryBot.create(:location)])
101
+
102
+ put_change_puppet_environment(
103
+ params: bulk_params.merge(environment_id: invalid_environment.id),
104
+ session: set_session_user
105
+ )
106
+
107
+ assert_response :unprocessable_entity
108
+ response = JSON.parse(@response.body)
109
+ assert_equal 'Selected Puppet environment is not assigned to the proper organization and/or location for all hosts.',
110
+ response.dig('error', 'message')
111
+ assert_equal [host.id, host2.id].sort, response.dig('error', 'failed_host_ids').sort
112
+ end
113
+
21
114
  test 'changes puppet proxy for selected hosts' do
22
115
  put :change_puppet_proxy,
23
116
  params: bulk_params.merge(proxy_id: proxy.id, ca_proxy: false)
@@ -176,6 +176,56 @@ module ForemanPuppet
176
176
  assert_not_includes completions, %(config_group = "#{config_group.name}")
177
177
  end
178
178
 
179
+ test 'limits Puppet assignment completions to the current organization' do
180
+ organization = taxonomies(:organization1)
181
+ location = taxonomies(:location1)
182
+ hidden_organization = FactoryBot.create(:organization)
183
+ visible_environment = FactoryBot.create(
184
+ :environment,
185
+ organizations: [organization],
186
+ locations: [location]
187
+ )
188
+ hidden_environment = FactoryBot.create(
189
+ :environment,
190
+ organizations: [hidden_organization],
191
+ locations: [location]
192
+ )
193
+ visible_host = FactoryBot.create(
194
+ :host,
195
+ :with_puppet_enc,
196
+ :with_puppetclass,
197
+ environment: visible_environment,
198
+ organization: organization,
199
+ location: location
200
+ )
201
+ hidden_host = FactoryBot.create(
202
+ :host,
203
+ :with_puppet_enc,
204
+ :with_puppetclass,
205
+ environment: hidden_environment,
206
+ organization: hidden_organization,
207
+ location: location
208
+ )
209
+ visible_config_group = FactoryBot.create(:config_group)
210
+ hidden_config_group = FactoryBot.create(:config_group)
211
+ visible_host.puppet.config_groups << visible_config_group
212
+ hidden_host.puppet.config_groups << hidden_config_group
213
+ Organization.current = organization
214
+ Location.current = nil
215
+
216
+ visible_puppetclass = visible_host.puppet.puppetclasses.first
217
+ hidden_puppetclass = hidden_host.puppet.puppetclasses.first
218
+ visible_puppetclasses = ::Host::Managed.complete_for("puppetclass = #{visible_puppetclass.name}")
219
+ hidden_puppetclasses = ::Host::Managed.complete_for("puppetclass = #{hidden_puppetclass.name}")
220
+ visible_config_groups = ::Host::Managed.complete_for("config_group = #{visible_config_group.name}")
221
+ hidden_config_groups = ::Host::Managed.complete_for("config_group = #{hidden_config_group.name}")
222
+
223
+ assert_includes visible_puppetclasses, %(puppetclass = "#{visible_puppetclass.name}")
224
+ assert_not_includes hidden_puppetclasses, %(puppetclass = "#{hidden_puppetclass.name}")
225
+ assert_includes visible_config_groups, %(config_group = "#{visible_config_group.name}")
226
+ assert_not_includes hidden_config_groups, %(config_group = "#{hidden_config_group.name}")
227
+ end
228
+
179
229
  test 'preserves core host value completions' do
180
230
  completions = as_admin { ::Host::Managed.complete_for('user.login =') }
181
231
 
@@ -47,6 +47,56 @@ module ForemanPuppet
47
47
  assert_includes completions, %(puppetclass = "#{puppetclass.name}")
48
48
  end
49
49
 
50
+ test 'limits Puppet assignment completions to the current location' do
51
+ organization = taxonomies(:organization1)
52
+ location = taxonomies(:location1)
53
+ hidden_location = FactoryBot.create(:location)
54
+ visible_environment = FactoryBot.create(
55
+ :environment,
56
+ organizations: [organization],
57
+ locations: [location]
58
+ )
59
+ hidden_environment = FactoryBot.create(
60
+ :environment,
61
+ organizations: [organization],
62
+ locations: [hidden_location]
63
+ )
64
+ visible_hostgroup = FactoryBot.create(
65
+ :hostgroup,
66
+ :with_puppet_enc,
67
+ :with_puppetclass,
68
+ :with_config_group,
69
+ environment: visible_environment,
70
+ organizations: [organization],
71
+ locations: [location]
72
+ )
73
+ hidden_hostgroup = FactoryBot.create(
74
+ :hostgroup,
75
+ :with_puppet_enc,
76
+ :with_puppetclass,
77
+ :with_config_group,
78
+ environment: hidden_environment,
79
+ organizations: [organization],
80
+ locations: [hidden_location]
81
+ )
82
+ visible_config_group = visible_hostgroup.puppet.config_groups.first
83
+ hidden_config_group = hidden_hostgroup.puppet.config_groups.first
84
+ Organization.current = nil
85
+ Location.current = location
86
+
87
+ visible_puppetclass = visible_hostgroup.puppet.puppetclasses.first
88
+ hidden_puppetclass = hidden_hostgroup.puppet.puppetclasses.first
89
+ visible_puppetclasses = ::Hostgroup.complete_for("puppetclass = #{visible_puppetclass.name}")
90
+ hidden_puppetclasses = ::Hostgroup.complete_for("puppetclass = #{hidden_puppetclass.name}")
91
+ visible_config_groups = ::Hostgroup.complete_for("config_group = #{visible_config_group.name}")
92
+ hidden_config_groups = ::Hostgroup.complete_for("config_group = #{hidden_config_group.name}")
93
+
94
+ assert_includes visible_puppetclasses, %(puppetclass = "#{visible_puppetclass.name}")
95
+ assert_not_includes hidden_puppetclasses, %(puppetclass = "#{hidden_puppetclass.name}")
96
+ assert_includes visible_config_groups, %(config_group = "#{visible_config_group.name}")
97
+ assert_not_includes hidden_config_groups, %(config_group = "#{hidden_config_group.name}")
98
+ end
99
+
50
100
  test 'searches Puppet class values assigned through a config group' do
51
101
  config_group = hostgroup.puppet.config_groups.first
52
102
  puppetclass = FactoryBot.create(:puppetclass)
@@ -4,6 +4,51 @@ class BulkHostsManagerTest < ActiveSupport::TestCase
4
4
  let(:hosts) { FactoryBot.create_list(:host, 2, :with_puppet_enc) }
5
5
  let(:manager) { ::BulkHostsManager.new(hosts: hosts) }
6
6
  let(:proxy) { FactoryBot.create(:puppet_smart_proxy) }
7
+ let(:environment) { FactoryBot.create(:environment, organizations: [hosts.first.organization], locations: [hosts.first.location]) }
8
+
9
+ test 'changes puppet environment for hosts' do
10
+ manager.change_puppet_environment(environment)
11
+
12
+ hosts.each do |host|
13
+ assert_equal environment.id, host.reload.puppet.environment_id
14
+ end
15
+ end
16
+
17
+ test 'inherits puppet environment from hostgroup' do
18
+ organization = FactoryBot.create(:organization)
19
+ location = FactoryBot.create(:location)
20
+ inherited_environment = FactoryBot.create(:environment, organizations: [organization], locations: [location])
21
+ initial_environment = FactoryBot.create(:environment, organizations: [organization], locations: [location])
22
+ hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc,
23
+ environment: inherited_environment,
24
+ organizations: [organization],
25
+ locations: [location])
26
+ inherited_hosts = FactoryBot.create_list(:host, 2, :with_puppet_enc,
27
+ environment: initial_environment,
28
+ hostgroup: hostgroup,
29
+ organization: organization,
30
+ location: location)
31
+
32
+ inherited_hosts.each do |host|
33
+ assert_not_equal inherited_environment.id, host.reload.puppet.environment_id
34
+ end
35
+
36
+ ::BulkHostsManager.new(hosts: inherited_hosts).change_puppet_environment('inherit')
37
+
38
+ inherited_hosts.each do |host|
39
+ assert_equal inherited_environment.id, host.reload.puppet.environment_id
40
+ end
41
+ end
42
+
43
+ test 'clears puppet environment when environment is nil' do
44
+ hosts.each { |host| host.puppet.update!(environment: environment) }
45
+
46
+ manager.change_puppet_environment(nil)
47
+
48
+ hosts.each do |host|
49
+ assert_nil host.reload.puppet.environment
50
+ end
51
+ end
7
52
 
8
53
  test 'changes puppet proxy for hosts' do
9
54
  manager.change_puppet_proxy(proxy, false)
@@ -6,5 +6,13 @@ export const API = {
6
6
  patch: jest.fn(),
7
7
  };
8
8
 
9
+ export const APIActions = {
10
+ get: jest.fn(),
11
+ post: jest.fn(),
12
+ put: jest.fn(),
13
+ patch: jest.fn(),
14
+ delete: jest.fn(),
15
+ };
16
+
9
17
  export const get = data => ({ type: 'get-some-type', ...data });
10
18
  export const post = data => ({ type: 'post-some-type', ...data });
@@ -7,12 +7,15 @@ import reducers from './src/reducers';
7
7
  import { registerFills } from './src/Extends/Fills';
8
8
  import { registerLegacy } from './legacy';
9
9
  import HostsIndexActionsBar from './src/Extends/Hosts/ActionsBar';
10
+ import BulkChangePuppetEnvironment from './src/Extends/Hosts/BulkActions/BulkChangePuppetEnvironment';
11
+ import BulkRemovePuppetEnvironment from './src/Extends/Hosts/BulkActions/BulkRemovePuppetEnvironment';
10
12
  import BulkChangePuppetProxy from './src/Extends/Hosts/BulkActions/BulkChangePuppetProxy';
11
13
  import BulkChangePuppetCAProxy from './src/Extends/Hosts/BulkActions/BulkChangePuppetCAProxy';
12
14
  import BulkRemovePuppetProxy from './src/Extends/Hosts/BulkActions/BulkRemovePuppetProxy';
13
15
  import BulkRemovePuppetCAProxy from './src/Extends/Hosts/BulkActions/BulkRemovePuppetCAProxy';
14
16
 
15
17
  const GLOBAL_FILL_PRIORITY = 100;
18
+ const PUPPET_ENV_COLUMN_WEIGHT = 2700;
16
19
 
17
20
  // register reducers
18
21
  registerReducer('puppet', reducers);
@@ -28,7 +31,7 @@ const puppetHostsIndexColumns = [
28
31
  title: __('Puppet env'),
29
32
  isSorted: true,
30
33
  wrapper: hostDetails => hostDetails.environment_name,
31
- weight: 2700,
34
+ weight: PUPPET_ENV_COLUMN_WEIGHT,
32
35
  },
33
36
  ];
34
37
 
@@ -45,6 +48,20 @@ addGlobalFill(
45
48
  GLOBAL_FILL_PRIORITY
46
49
  );
47
50
 
51
+ addGlobalFill(
52
+ '_all-hosts-modals',
53
+ 'BulkChangePuppetEnvironment',
54
+ <BulkChangePuppetEnvironment key="bulk-change-puppet-environment" />,
55
+ GLOBAL_FILL_PRIORITY
56
+ );
57
+
58
+ addGlobalFill(
59
+ '_all-hosts-modals',
60
+ 'BulkRemovePuppetEnvironment',
61
+ <BulkRemovePuppetEnvironment key="bulk-remove-puppet-environment" />,
62
+ GLOBAL_FILL_PRIORITY
63
+ );
64
+
48
65
  addGlobalFill(
49
66
  '_all-hosts-modals',
50
67
  'BulkChangePuppetProxy',
@@ -24,6 +24,26 @@ const HostActionsBar = () => {
24
24
  <Menu ouiaId="content-flyout-menu" onSelect={() => setMenuOpen(false)}>
25
25
  <MenuContent>
26
26
  <MenuList>
27
+ <MenuItem
28
+ itemId="bulk-change-puppet-environment-menu-item"
29
+ key="bulk-change-puppet-environment-menu-item"
30
+ onClick={() =>
31
+ handleOpenBulkModal('bulk-change-puppet-environment')
32
+ }
33
+ isDisabled={selectedCount === 0}
34
+ >
35
+ {__('Change Puppet environment')}
36
+ </MenuItem>
37
+ <MenuItem
38
+ itemId="bulk-remove-puppet-environment-menu-item"
39
+ key="bulk-remove-puppet-environment-menu-item"
40
+ onClick={() =>
41
+ handleOpenBulkModal('bulk-remove-puppet-environment')
42
+ }
43
+ isDisabled={selectedCount === 0}
44
+ >
45
+ {__('Remove Puppet environment')}
46
+ </MenuItem>
27
47
  <MenuItem
28
48
  itemId="bulk-change-puppet-proxy-menu-item"
29
49
  key="bulk-change-puppet-proxy-menu-item"
@@ -9,13 +9,6 @@ import {
9
9
  BULK_CHANGE_PUPPET_PROXY_KEY,
10
10
  } from '../actions';
11
11
 
12
- jest.mock('foremanReact/redux/API', () => ({
13
- APIActions: {
14
- get: jest.fn(),
15
- put: jest.fn(),
16
- },
17
- }));
18
-
19
12
  describe('BulkChangeProxyCommon actions', () => {
20
13
  const smartProxiesUrl = foremanUrl('/api/smart_proxies');
21
14
  const bulkChangeUrl = foremanUrl('/api/v2/hosts/bulk/change_puppet_proxy');