foreman_puppet 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +619 -0
  3. data/README.md +38 -0
  4. data/Rakefile +31 -0
  5. data/app/assets/stylesheets/foreman_puppet.scss +117 -0
  6. data/app/controllers/concerns/foreman_puppet/api/import_puppetclasses_common_controller.rb +139 -0
  7. data/app/controllers/concerns/foreman_puppet/environments_import.rb +61 -0
  8. data/app/controllers/concerns/foreman_puppet/extensions/api_hostgroups_controller.rb +40 -0
  9. data/app/controllers/concerns/foreman_puppet/extensions/api_template_combinations_controller.rb +23 -0
  10. data/app/controllers/concerns/foreman_puppet/extensions/api_v2_hosts_controller.rb +48 -0
  11. data/app/controllers/concerns/foreman_puppet/extensions/hostgroups_controller_extensions.rb +58 -0
  12. data/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb +228 -0
  13. data/app/controllers/concerns/foreman_puppet/extensions/operatingsystems_controller.rb +11 -0
  14. data/app/controllers/concerns/foreman_puppet/extensions/parameters_host.rb +75 -0
  15. data/app/controllers/concerns/foreman_puppet/extensions/parameters_hostgroup.rb +70 -0
  16. data/app/controllers/concerns/foreman_puppet/extensions/parameters_template_combination.rb +21 -0
  17. data/app/controllers/concerns/foreman_puppet/parameters/config_group.rb +17 -0
  18. data/app/controllers/concerns/foreman_puppet/parameters/environment.rb +21 -0
  19. data/app/controllers/concerns/foreman_puppet/parameters/puppetclass.rb +24 -0
  20. data/app/controllers/concerns/foreman_puppet/parameters/puppetclass_lookup_key.rb +24 -0
  21. data/app/controllers/foreman_puppet/api/v2/base_controller.rb +26 -0
  22. data/app/controllers/foreman_puppet/api/v2/config_groups_controller.rb +57 -0
  23. data/app/controllers/foreman_puppet/api/v2/environments_controller.rb +91 -0
  24. data/app/controllers/foreman_puppet/api/v2/host_classes_controller.rb +59 -0
  25. data/app/controllers/foreman_puppet/api/v2/hostgroup_classes_controller.rb +46 -0
  26. data/app/controllers/foreman_puppet/api/v2/lookups_common_controller.rb +114 -0
  27. data/app/controllers/foreman_puppet/api/v2/override_values_controller.rb +99 -0
  28. data/app/controllers/foreman_puppet/api/v2/puppetclasses_controller.rb +99 -0
  29. data/app/controllers/foreman_puppet/api/v2/smart_class_parameters_controller.rb +76 -0
  30. data/app/controllers/foreman_puppet/config_groups_controller.rb +46 -0
  31. data/app/controllers/foreman_puppet/environments_controller.rb +51 -0
  32. data/app/controllers/foreman_puppet/puppet_smart_proxies_controller.rb +39 -0
  33. data/app/controllers/foreman_puppet/puppetclass_lookup_keys_controller.rb +33 -0
  34. data/app/controllers/foreman_puppet/puppetclasses_controller.rb +113 -0
  35. data/app/controllers/foreman_puppet/react_controller.rb +19 -0
  36. data/app/helpers/concerns/foreman_puppet/template_renderer_scope.rb +14 -0
  37. data/app/helpers/foreman_puppet/environments_helper.rb +17 -0
  38. data/app/helpers/foreman_puppet/hosts_and_hostgroups_helper.rb +96 -0
  39. data/app/helpers/foreman_puppet/hosts_helper.rb +32 -0
  40. data/app/helpers/foreman_puppet/puppet_smart_proxies_helper.rb +8 -0
  41. data/app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb +135 -0
  42. data/app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb +55 -0
  43. data/app/helpers/foreman_puppet/puppetclasses_helper.rb +59 -0
  44. data/app/helpers/foreman_puppet/template_combinations_helper.rb +33 -0
  45. data/app/models/concerns/foreman_puppet/extensions/host.rb +88 -0
  46. data/app/models/concerns/foreman_puppet/extensions/hostgroup.rb +40 -0
  47. data/app/models/concerns/foreman_puppet/extensions/nic_managed.rb +11 -0
  48. data/app/models/concerns/foreman_puppet/extensions/operatingsystem.rb +11 -0
  49. data/app/models/concerns/foreman_puppet/extensions/provisioning_template.rb +64 -0
  50. data/app/models/concerns/foreman_puppet/extensions/report.rb +11 -0
  51. data/app/models/concerns/foreman_puppet/extensions/taxonomy.rb +19 -0
  52. data/app/models/concerns/foreman_puppet/extensions/template_combination.rb +23 -0
  53. data/app/models/concerns/foreman_puppet/extensions/user.rb +22 -0
  54. data/app/models/concerns/foreman_puppet/host_common.rb +90 -0
  55. data/app/models/concerns/foreman_puppet/puppet_lookup_value_extensions.rb +13 -0
  56. data/app/models/foreman_puppet/config_group.rb +45 -0
  57. data/app/models/foreman_puppet/config_group_class.rb +19 -0
  58. data/app/models/foreman_puppet/environment.rb +63 -0
  59. data/app/models/foreman_puppet/environment_class.rb +40 -0
  60. data/app/models/foreman_puppet/host_class.rb +23 -0
  61. data/app/models/foreman_puppet/host_config_group.rb +15 -0
  62. data/app/models/foreman_puppet/host_puppet_facet.rb +130 -0
  63. data/app/models/foreman_puppet/hostgroup_class.rb +23 -0
  64. data/app/models/foreman_puppet/hostgroup_puppet_facet.rb +98 -0
  65. data/app/models/foreman_puppet/puppetclass.rb +132 -0
  66. data/app/models/foreman_puppet/puppetclass_lookup_key.rb +58 -0
  67. data/app/services/foreman_puppet/host_info_providers/config_groups_info.rb +10 -0
  68. data/app/services/foreman_puppet/host_info_providers/puppet_info.rb +92 -0
  69. data/app/services/foreman_puppet/input_type/puppet_parameter_input.rb +35 -0
  70. data/app/services/foreman_puppet/proxy_status/puppet.rb +17 -0
  71. data/app/services/foreman_puppet/puppet_class_importer.rb +355 -0
  72. data/app/views/api/v2/template_combinations/base.json.erb +9 -0
  73. data/app/views/foreman_puppet/api/v2/config_groups/base.json.rabl +3 -0
  74. data/app/views/foreman_puppet/api/v2/config_groups/create.json.rabl +3 -0
  75. data/app/views/foreman_puppet/api/v2/config_groups/index.json.rabl +3 -0
  76. data/app/views/foreman_puppet/api/v2/config_groups/main.json.rabl +8 -0
  77. data/app/views/foreman_puppet/api/v2/config_groups/show.json.rabl +3 -0
  78. data/app/views/foreman_puppet/api/v2/config_groups/update.json.rabl +3 -0
  79. data/app/views/foreman_puppet/api/v2/environments/base.json.rabl +3 -0
  80. data/app/views/foreman_puppet/api/v2/environments/create.json.rabl +3 -0
  81. data/app/views/foreman_puppet/api/v2/environments/index.json.rabl +3 -0
  82. data/app/views/foreman_puppet/api/v2/environments/main.json.rabl +5 -0
  83. data/app/views/foreman_puppet/api/v2/environments/show.json.rabl +15 -0
  84. data/app/views/foreman_puppet/api/v2/environments/update.json.rabl +3 -0
  85. data/app/views/foreman_puppet/api/v2/host_puppet_facets/base.json.rabl +1 -0
  86. data/app/views/foreman_puppet/api/v2/host_puppet_facets/host_single.json.rabl +17 -0
  87. data/app/views/foreman_puppet/api/v2/host_puppet_facets/show.json.rabl +11 -0
  88. data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/base.json.rabl +5 -0
  89. data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/hostgroup_single.json.rabl +16 -0
  90. data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/show.json.rabl +11 -0
  91. data/app/views/foreman_puppet/api/v2/import_puppetclasses/index.json.rabl +3 -0
  92. data/app/views/foreman_puppet/api/v2/import_puppetclasses/show.json.rabl +36 -0
  93. data/app/views/foreman_puppet/api/v2/override_values/create.json.rabl +3 -0
  94. data/app/views/foreman_puppet/api/v2/override_values/index.json.rabl +3 -0
  95. data/app/views/foreman_puppet/api/v2/override_values/show.json.rabl +3 -0
  96. data/app/views/foreman_puppet/api/v2/override_values/update.json.rabl +3 -0
  97. data/app/views/foreman_puppet/api/v2/puppetclasses/base.json.rabl +3 -0
  98. data/app/views/foreman_puppet/api/v2/puppetclasses/create.json.rabl +3 -0
  99. data/app/views/foreman_puppet/api/v2/puppetclasses/index.json.rabl +4 -0
  100. data/app/views/foreman_puppet/api/v2/puppetclasses/list.json.rabl +3 -0
  101. data/app/views/foreman_puppet/api/v2/puppetclasses/main.json.rabl +5 -0
  102. data/app/views/foreman_puppet/api/v2/puppetclasses/show.json.rabl +15 -0
  103. data/app/views/foreman_puppet/api/v2/puppetclasses/update.json.rabl +3 -0
  104. data/app/views/foreman_puppet/api/v2/smart_class_parameters/base.json.rabl +4 -0
  105. data/app/views/foreman_puppet/api/v2/smart_class_parameters/create.json.rabl +3 -0
  106. data/app/views/foreman_puppet/api/v2/smart_class_parameters/destroy.json.rabl +3 -0
  107. data/app/views/foreman_puppet/api/v2/smart_class_parameters/index.json.rabl +3 -0
  108. data/app/views/foreman_puppet/api/v2/smart_class_parameters/main.json.rabl +23 -0
  109. data/app/views/foreman_puppet/api/v2/smart_class_parameters/show.json.rabl +19 -0
  110. data/app/views/foreman_puppet/api/v2/smart_class_parameters/update.json.rabl +3 -0
  111. data/app/views/foreman_puppet/config_groups/_config_group.html.erb +34 -0
  112. data/app/views/foreman_puppet/config_groups/_config_groups_selection.html.erb +36 -0
  113. data/app/views/foreman_puppet/config_groups/_form.html.erb +9 -0
  114. data/app/views/foreman_puppet/config_groups/edit.html.erb +3 -0
  115. data/app/views/foreman_puppet/config_groups/index.html.erb +31 -0
  116. data/app/views/foreman_puppet/config_groups/new.html.erb +3 -0
  117. data/app/views/foreman_puppet/config_groups/welcome.html.erb +12 -0
  118. data/app/views/foreman_puppet/environments/_form.html.erb +20 -0
  119. data/app/views/foreman_puppet/environments/edit.html.erb +8 -0
  120. data/app/views/foreman_puppet/environments/index.html.erb +32 -0
  121. data/app/views/foreman_puppet/environments/new.html.erb +7 -0
  122. data/app/views/foreman_puppet/environments/welcome.html.erb +16 -0
  123. data/app/views/foreman_puppet/layouts/application_react.html.erb +15 -0
  124. data/app/views/foreman_puppet/puppet_smart_proxies/_dashboard.html.erb +9 -0
  125. data/app/views/foreman_puppet/puppet_smart_proxies/_environments.html.erb +30 -0
  126. data/app/views/foreman_puppet/puppetclass_lookup_keys/edit.html.erb +3 -0
  127. data/app/views/foreman_puppet/puppetclass_lookup_keys/index.html.erb +22 -0
  128. data/app/views/foreman_puppet/puppetclass_lookup_keys/welcome.html.erb +9 -0
  129. data/app/views/foreman_puppet/puppetclasses/_class_parameters.html.erb +37 -0
  130. data/app/views/foreman_puppet/puppetclasses/_class_selection.html.erb +70 -0
  131. data/app/views/foreman_puppet/puppetclasses/_classes.html.erb +22 -0
  132. data/app/views/foreman_puppet/puppetclasses/_classes_in_groups.html.erb +5 -0
  133. data/app/views/foreman_puppet/puppetclasses/_classes_parameters.html.erb +16 -0
  134. data/app/views/foreman_puppet/puppetclasses/_form.html.erb +62 -0
  135. data/app/views/foreman_puppet/puppetclasses/_selected_classes.html.erb +4 -0
  136. data/app/views/foreman_puppet/puppetclasses/edit.html.erb +4 -0
  137. data/app/views/foreman_puppet/puppetclasses/index.html.erb +47 -0
  138. data/app/views/hosts/_form_puppet_enc_tab.html.erb +24 -0
  139. data/app/views/hosts/foreman_puppet/_form_main_tab_fields.html.erb +1 -0
  140. data/app/views/hosts/select_multiple_environment.html.erb +8 -0
  141. data/app/views/provisioning_templates/_combination.html.erb +5 -0
  142. data/app/views/provisioning_templates/_combinations.html.erb +6 -0
  143. data/app/views/smart_proxies/plugins/_puppet.html.erb +24 -0
  144. data/config/api_routes.rb +81 -0
  145. data/config/routes.rb +89 -0
  146. data/db/migrate/20101121140000_add_environment_to_template_combinations.foreman_puppet.rb +9 -0
  147. data/db/migrate/20200720123005_migrate_puppet_core_types.foreman_puppet.rb +19 -0
  148. data/db/migrate/20200722171017_create_host_puppet_facet.foreman_puppet.rb +10 -0
  149. data/db/migrate/20200803113531_create_hostgroup_puppet_facet.foreman_puppet.rb +10 -0
  150. data/db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb +22 -0
  151. data/db/migrate/20200803113903_migrate_host_type_in_host_config_groups.foreman_puppet.rb +29 -0
  152. data/db/migrate/20201125113903_migrate_puppetclasses_to_facets.foreman_puppet.rb +47 -0
  153. data/db/migrate_foreman/20090722141107_create_environments.rb +17 -0
  154. data/db/migrate_foreman/20120905095532_create_environment_classes.rb +15 -0
  155. data/db/migrate_foreman/20140407161817_create_config_groups.rb +9 -0
  156. data/db/migrate_foreman/20140407162007_create_config_group_classes.rb +10 -0
  157. data/db/migrate_foreman/20140407162059_create_host_config_groups.rb +11 -0
  158. data/db/migrate_foreman/20161205142618_delete_orphaned_smart_class_parameters.rb +10 -0
  159. data/db/migrate_foreman/20170109115157_fix_lookup_key_auditable_type.rb +15 -0
  160. data/db/migrate_foreman/20180816134832_cast_lookup_key_values.rb +35 -0
  161. data/db/migrate_foreman/20181023112532_add_environment_puppetclass_id.rb +7 -0
  162. data/db/migrate_foreman/20181224174419_add_index_to_environment_class_by_lookup_key_and_puppetclass.rb +6 -0
  163. data/db/seeds.d/111_puppet_proxy_feature.rb +8 -0
  164. data/lib/foreman_puppet.rb +10 -0
  165. data/lib/foreman_puppet/engine.rb +82 -0
  166. data/lib/foreman_puppet/register.rb +218 -0
  167. data/lib/foreman_puppet/version.rb +3 -0
  168. data/lib/tasks/foreman_puppet_tasks.rake +31 -0
  169. data/locale/Makefile +60 -0
  170. data/locale/action_names.rb +5 -0
  171. data/locale/en/foreman_puppet.edit.po +911 -0
  172. data/locale/en/foreman_puppet.po +690 -0
  173. data/locale/en/foreman_puppet.po.time_stamp +0 -0
  174. data/locale/foreman_puppet.pot +1076 -0
  175. data/locale/gemspec.rb +2 -0
  176. data/test/controllers/foreman_puppet/api/v2/config_groups_controller_test.rb +28 -0
  177. data/test/controllers/foreman_puppet/api/v2/environments_controller_test.rb +346 -0
  178. data/test/controllers/foreman_puppet/api/v2/host_classes_controller_test.rb +48 -0
  179. data/test/controllers/foreman_puppet/api/v2/hostgroup_classes_controller_test.rb +41 -0
  180. data/test/controllers/foreman_puppet/api/v2/hostgroups_controller_test.rb +79 -0
  181. data/test/controllers/foreman_puppet/api/v2/hosts_controller_test.rb +101 -0
  182. data/test/controllers/foreman_puppet/api/v2/lookups_common_controller_test.rb +29 -0
  183. data/test/controllers/foreman_puppet/api/v2/override_values_controller_test.rb +169 -0
  184. data/test/controllers/foreman_puppet/api/v2/puppetclasses_controller_test.rb +144 -0
  185. data/test/controllers/foreman_puppet/api/v2/smart_class_parameters_controller_test.rb +557 -0
  186. data/test/controllers/foreman_puppet/api/v2/template_combinations_controller_test.rb +81 -0
  187. data/test/controllers/foreman_puppet/config_groups_controller_test.rb +47 -0
  188. data/test/controllers/foreman_puppet/environments_controller_test.rb +230 -0
  189. data/test/controllers/foreman_puppet/hostgroups_controller_test.rb +72 -0
  190. data/test/controllers/foreman_puppet/hosts_controller_test.rb +346 -0
  191. data/test/controllers/foreman_puppet/puppet_smart_proxies_controller_test.rb +29 -0
  192. data/test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb +59 -0
  193. data/test/controllers/foreman_puppet/puppetclasses_controller_test.rb +235 -0
  194. data/test/controllers/provisioning_templates_controller_test.rb +70 -0
  195. data/test/factories/foreman_puppet_factories.rb +134 -0
  196. data/test/factories/host_puppet_enhancements.rb +61 -0
  197. data/test/factories/proxy_puppet_enhancements.rb +33 -0
  198. data/test/helpers/foreman_puppet/hosts_and_hostgroups_helper_test.rb +65 -0
  199. data/test/helpers/foreman_puppet/puppetclasses_helper_test.rb +33 -0
  200. data/test/integration/foreman_puppet/environment_js_test.rb +27 -0
  201. data/test/integration/foreman_puppet/host_js_test.rb +371 -0
  202. data/test/integration/foreman_puppet/hostgroup_js_test.rb +100 -0
  203. data/test/integration/foreman_puppet/puppetclass_js_test.rb +37 -0
  204. data/test/integration/foreman_puppet/smartclass_parameter_js_test.rb +84 -0
  205. data/test/models/foreman_puppet/config_group_class_test.rb +9 -0
  206. data/test/models/foreman_puppet/config_group_test.rb +8 -0
  207. data/test/models/foreman_puppet/environment_test.rb +92 -0
  208. data/test/models/foreman_puppet/host_config_group_test.rb +39 -0
  209. data/test/models/foreman_puppet/host_puppet_facet_test.rb +116 -0
  210. data/test/models/foreman_puppet/host_test.rb +288 -0
  211. data/test/models/foreman_puppet/hostgroup_puppet_facet_test.rb +200 -0
  212. data/test/models/foreman_puppet/hostgroup_test.rb +14 -0
  213. data/test/models/foreman_puppet/lookup_value_test.rb +69 -0
  214. data/test/models/foreman_puppet/provisioning_template_test.rb +124 -0
  215. data/test/models/foreman_puppet/puppetclass_lookup_key_test.rb +81 -0
  216. data/test/models/foreman_puppet/puppetclass_test.rb +144 -0
  217. data/test/models/foreman_puppet/smart_proxy_test.rb +28 -0
  218. data/test/qraphql/queries/host_puppet_query_test.rb +36 -0
  219. data/test/qraphql/queries/hostgroup_puppet_query_test.rb +36 -0
  220. data/test/services/foreman_puppet/host_info_providers/puppet_info_test.rb +791 -0
  221. data/test/services/foreman_puppet/input_type/puppet_parameter_input_test.rb +14 -0
  222. data/test/test_puppet_helper.rb +30 -0
  223. data/test/unit/foreman_puppet/access_permissions_test.rb +16 -0
  224. data/test/unit/foreman_puppet/puppet_class_importer_test.rb +247 -0
  225. data/test/unit/foreman_puppet/template_rendering_test.rb +20 -0
  226. data/test/unit/foreman_puppet_test.rb +11 -0
  227. data/webpack/__mocks__/foremanReact/common/I18n.js +7 -0
  228. data/webpack/__mocks__/foremanReact/components/Layout/LayoutActions.js +2 -0
  229. data/webpack/__mocks__/foremanReact/readme.md +11 -0
  230. data/webpack/__mocks__/foremanReact/redux/API/APISelectors.js +10 -0
  231. data/webpack/__mocks__/foremanReact/redux/API/index.js +10 -0
  232. data/webpack/__mocks__/foremanReact/redux/actions/toasts.js +8 -0
  233. data/webpack/__mocks__/foremanReact/redux/index.js +1 -0
  234. data/webpack/__mocks__/foremanReact/redux/middlewares/IntervalMiddleware.js +5 -0
  235. data/webpack/fills_index.js +30 -0
  236. data/webpack/index.js +18 -0
  237. data/webpack/src/ForemanPuppet.js +11 -0
  238. data/webpack/src/Router/__snapshots__/routes.test.js.snap +3 -0
  239. data/webpack/src/Router/index.js +14 -0
  240. data/webpack/src/Router/routes.js +3 -0
  241. data/webpack/src/Router/routes.test.js +16 -0
  242. data/webpack/src/foreman_class_edit.js +224 -0
  243. data/webpack/src/foreman_puppet_host_form.js +140 -0
  244. data/webpack/src/foreman_puppet_host_form.test.js +65 -0
  245. data/webpack/src/index.js +1 -0
  246. data/webpack/src/reducers.js +7 -0
  247. metadata +340 -0
data/webpack/index.js ADDED
@@ -0,0 +1,18 @@
1
+ /* eslint import/no-unresolved: [2, { ignore: [foremanReact/*] }] */
2
+ /* eslint-disable import/no-extraneous-dependencies */
3
+ /* eslint-disable import/extensions */
4
+ import componentRegistry from 'foremanReact/components/componentRegistry';
5
+ import { registerReducer } from 'foremanReact/common/MountingService';
6
+ import reducers from './src/reducers';
7
+ import ForemanPuppet from './src/ForemanPuppet';
8
+
9
+ // register reducers
10
+ Object.entries(reducers).forEach(([key, reducer]) =>
11
+ registerReducer(key, reducer)
12
+ );
13
+
14
+ // register components for erb mounting
15
+ componentRegistry.register({
16
+ name: 'ForemanPuppet',
17
+ type: ForemanPuppet,
18
+ });
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { BrowserRouter } from 'react-router-dom';
3
+ import ForemanPuppetRoute from './Router';
4
+
5
+ const ForemanPuppet = () => (
6
+ <BrowserRouter>
7
+ <ForemanPuppetRoute />
8
+ </BrowserRouter>
9
+ );
10
+
11
+ export default ForemanPuppet;
@@ -0,0 +1,3 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`ForemanPuppetRoutes should create routes 1`] = `Object {}`;
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { Switch, Route } from 'react-router-dom';
3
+
4
+ import routes from './routes';
5
+
6
+ const Router = () => (
7
+ <Switch>
8
+ {Object.entries(routes).map(([key, props]) => (
9
+ <Route key={key} {...props} />
10
+ ))}
11
+ </Switch>
12
+ );
13
+
14
+ export default Router;
@@ -0,0 +1,3 @@
1
+ const routes = {};
2
+
3
+ export default routes;
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import { shallow } from '@theforeman/test';
3
+
4
+ import Routes from './routes';
5
+
6
+ describe('ForemanPuppetRoutes', () => {
7
+ it('should create routes', () => {
8
+ Object.entries(Routes).forEach(([key, Route]) => {
9
+ const Component = Route.component;
10
+ const component = shallow(<Component history={{}} some="props" />);
11
+ Route.renderResult = component;
12
+ });
13
+
14
+ expect(Routes).toMatchSnapshot();
15
+ });
16
+ });
@@ -0,0 +1,224 @@
1
+ /* eslint-disable jquery/no-val */
2
+ /* eslint-disable jquery/no-fade */
3
+ /* eslint-disable jquery/no-sizzle */
4
+ /* eslint-disable jquery/no-attr */
5
+ /* eslint-disable jquery/no-trigger */
6
+ /* eslint-disable jquery/no-show */
7
+ /* eslint-disable jquery/no-class */
8
+ /* eslint-disable jquery/no-find */ /**/
9
+ /* eslint-disable jquery/no-parent */
10
+ /* eslint-disable jquery/no-clone */
11
+ /* eslint-disable jquery/no-hide */
12
+ /* eslint-disable jquery/no-each */
13
+ /* eslint-disable jquery/no-in-array */
14
+ /* eslint-disable jquery/no-closest */
15
+ /* eslint-disable jquery/no-data */
16
+
17
+ import $ from 'jquery';
18
+ import { sprintf, translate as __ } from 'foremanReact/common/I18n';
19
+
20
+ export function filterPuppetClasses(item) {
21
+ const term = $(item)
22
+ .val()
23
+ .trim();
24
+ const classElems = $('.available_classes').find(
25
+ '.puppetclass_group, .puppetclass'
26
+ );
27
+ if (term.length > 0) {
28
+ classElems
29
+ .hide()
30
+ .has(`[data-class-name*="${term}"]`)
31
+ .show();
32
+ } else {
33
+ classElems.show();
34
+ }
35
+ }
36
+
37
+ export function addPuppetClass(item) {
38
+ const id = $(item).attr('data-class-id');
39
+ const type = $(item).attr('data-type');
40
+ $(item).tooltip('hide');
41
+ const content = $(item)
42
+ .closest('li')
43
+ .clone();
44
+ content.attr('id', `selected_puppetclass_${id}`);
45
+ content.append(
46
+ `<input id='${type}_puppetclass_ids_' name='${type}[puppetclass_ids][]' type='hidden' value=${id}>`
47
+ );
48
+
49
+ const linkIcon = content.children('a.glyphicon');
50
+ const links = content.find('a');
51
+
52
+ links.attr('onclick', 'tfm.classEditor.removePuppetClass(this)');
53
+ links.attr(
54
+ 'data-original-title',
55
+ sprintf(__('Click to remove %s'), linkIcon.data('class-name'))
56
+ );
57
+ links.tooltip();
58
+ linkIcon.removeClass('glyphicon-plus-sign').addClass('glyphicon-minus-sign');
59
+
60
+ $('#selected_classes').append(content);
61
+
62
+ $(`#selected_puppetclass_${id}`).show('highlight', 5000);
63
+ $(`#puppetclass_${id}`)
64
+ .addClass('selected-marker')
65
+ .hide();
66
+ findElementsForRemoveIcon($(`#puppetclass_${id}`));
67
+
68
+ window.tfm.puppetEnc.hostForm.loadPuppetClassParameters(linkIcon);
69
+ }
70
+
71
+ function addGroupPuppetClass(item) {
72
+ const id = $(item).attr('data-class-id');
73
+ $(item).tooltip('hide');
74
+ const content = $(item)
75
+ .closest('li')
76
+ .clone();
77
+ content.attr('id', `selected_puppetclass_${id}`);
78
+ content.children('span').tooltip();
79
+ content.val('');
80
+
81
+ const linkIcon = content.children('a.glyphicon');
82
+ const links = content.find('a');
83
+ links.attr('onclick', '');
84
+ links.attr('data-original-title', __('belongs to config group'));
85
+ links.tooltip();
86
+ linkIcon.removeClass('glyphicon-plus-sign');
87
+
88
+ $('#selected_classes').append(content);
89
+
90
+ $(`#selected_puppetclass_${id}`).show('highlight', 5000);
91
+ $(`#puppetclass_${id}`)
92
+ .addClass('selected-marker')
93
+ .hide();
94
+ findElementsForRemoveIcon($(`#puppetclass_${id}`));
95
+
96
+ window.tfm.puppetEnc.hostForm.loadPuppetClassParameters(linkIcon);
97
+ }
98
+
99
+ export function removePuppetClass(item) {
100
+ const id = $(item).attr('data-class-id');
101
+ $(`#puppetclass_${id}`)
102
+ .removeClass('selected-marker')
103
+ .show();
104
+ $(`#puppetclass_${id}`)
105
+ .parent()
106
+ .prev()
107
+ .find('i')
108
+ .show();
109
+ $(`#puppetclass_${id}`)
110
+ .closest('.puppetclass_group')
111
+ .show();
112
+ $(`#selected_puppetclass_${id}`)
113
+ .children('a')
114
+ .tooltip('hide');
115
+ $(`#selected_puppetclass_${id}`).remove();
116
+ $(`#puppetclass_${id}_params_loading`).remove();
117
+ $(`[id^="puppetclass_${id}_params\\["]`).remove();
118
+ $('a[href="#puppet_enc_tab"]').removeClass('tab-error');
119
+ if ($('#puppet_enc_tab').find('.form-group.error').length > 0)
120
+ $('a[href="#puppet_enc_tab"]').addClass('tab-error');
121
+
122
+ return false;
123
+ }
124
+
125
+ function _getInheritedIds() {
126
+ return $('#inherited_ids').data('inherited-puppetclass-ids') || [];
127
+ }
128
+
129
+ export function addConfigGroup(item) {
130
+ const id = $(item).attr('data-group-id');
131
+ const type = $(item).attr('data-type');
132
+ const content = $(item)
133
+ .closest('li')
134
+ .clone();
135
+ content.attr('id', `selected_config_group_${id}`);
136
+ content.append(
137
+ `<input id='config_group_ids' name=${type}[config_group_ids][] type='hidden' value=${id}>`
138
+ );
139
+ $(`#selected_config_group_${id}`).show('highlight', 5000);
140
+ $(`#config_group_${id}`)
141
+ .addClass('selected-marker')
142
+ .hide();
143
+ const link = content.children('a.glyphicon');
144
+ const links = content.find('a');
145
+ link.attr('onclick', 'tfm.classEditor.removeConfigGroup(this)');
146
+ link.attr('data-original-title', __('Click to remove config group'));
147
+ links.tooltip();
148
+ link.removeClass('glyphicon-plus-sign').addClass('glyphicon-minus-sign');
149
+ link.text(__(' Remove'));
150
+
151
+ $('#selected_config_groups').append(content);
152
+ $(`#selected_config_group_${id}`).show('highlight', 5000);
153
+ $(`#config_group_${id}`)
154
+ .addClass('selected-marker')
155
+ .hide();
156
+
157
+ const puppetclassIds = $.parseJSON($(item).attr('data-puppetclass-ids'));
158
+ const inheritedIds = _getInheritedIds();
159
+
160
+ $.each(puppetclassIds, (index, puppetclassId) => {
161
+ const pc = $(`li#puppetclass_${puppetclassId}`);
162
+ const pcLink = $(`#puppetclass_${puppetclassId} > a.glyphicon`);
163
+ if (
164
+ pcLink.length > 0 &&
165
+ pc.length > 0 &&
166
+ $.inArray(puppetclassId, inheritedIds) === -1
167
+ ) {
168
+ if ($(`#selected_puppetclass_${puppetclassId}`).length <= 0) {
169
+ addGroupPuppetClass(pcLink);
170
+ }
171
+ }
172
+ });
173
+ }
174
+
175
+ export function removeConfigGroup(item) {
176
+ const id = $(item).attr('data-group-id');
177
+ $(`#config_group_${id}`)
178
+ .removeClass('selected-marker')
179
+ .show();
180
+ $(`#selected_config_group_${id}`)
181
+ .children('a')
182
+ .tooltip('hide');
183
+ $(`#selected_config_group_${id}`).remove();
184
+
185
+ const puppetclassIds = $.parseJSON($(item).attr('data-puppetclass-ids'));
186
+ const inheritedIds = _getInheritedIds();
187
+
188
+ $.each(puppetclassIds, (index, puppetclassId) => {
189
+ const pc = $(`#selected_puppetclass_${puppetclassId}`);
190
+ const pcLink = $(`#puppetclass_${puppetclassId} > a.glyphicon`);
191
+ // do not remove if manually added - having minus icon
192
+ if (
193
+ pcLink.length > 0 &&
194
+ !pcLink.hasClass('glyphicon-minus-sign') &&
195
+ pc.length > 0 &&
196
+ $.inArray(puppetclassId, inheritedIds) === -1
197
+ ) {
198
+ removePuppetClass(pcLink);
199
+ }
200
+ });
201
+ return false;
202
+ }
203
+
204
+ function findElementsForRemoveIcon(element) {
205
+ const clickedElement = element.parent().prev();
206
+ const ulId = `#${element.parent().attr('id')}`;
207
+ removeIconIfEmpty(clickedElement, ulId);
208
+ }
209
+
210
+ export function expandClassList(clickedElement, toggleSelector) {
211
+ $(toggleSelector).fadeToggle();
212
+ $(clickedElement)
213
+ .find('.glyphicon')
214
+ .toggleClass('glyphicon-plus glyphicon-minus');
215
+ removeIconIfEmpty($(clickedElement), toggleSelector);
216
+ }
217
+
218
+ function removeIconIfEmpty(element, ulId) {
219
+ if ($(ulId).children(':visible').length === 0) {
220
+ element.find('.glyphicon').hide();
221
+ } else {
222
+ element.find('.glyphicon').show();
223
+ }
224
+ }
@@ -0,0 +1,140 @@
1
+ /* eslint-disable jquery/no-ajax */
2
+ /* eslint-disable jquery/no-class */
3
+ /* eslint-disable jquery/no-html */
4
+ /* eslint-disable jquery/no-data */
5
+ /* eslint-disable jquery/no-show */
6
+ /* eslint-disable jquery/no-hide */
7
+ /* eslint-disable jquery/no-closest */
8
+
9
+ import $ from 'jquery';
10
+
11
+ import { translate as __ } from 'foremanReact/common/I18n';
12
+ import store from 'foremanReact/redux';
13
+ import * as LayoutActions from 'foremanReact/components/Layout/LayoutActions';
14
+
15
+ export function loadPuppetClassParameters(item) {
16
+ const id = $(item).data('class-id');
17
+ // host_id could be either host.id OR hostgroup.id depending on which form
18
+ const $form = $('form.hostresource-form');
19
+ if ($form.length <= 0) return; // it is not host nor hostgroup form - probably config_group
20
+ const hostId = $form.data('id');
21
+ if ($(`#puppetclass_${id}_params_loading`).length > 0) return; // already loading
22
+ if ($(`[id^="#puppetclass_${id}_params\\["]`).length > 0) return; // already loaded
23
+ const url = $(item).data('url');
24
+ let data = window.serializeForm().replace('method=patch', 'method=post');
25
+ if (url.match('hostgroups')) {
26
+ data += `&hostgroup_id=${hostId}`;
27
+ } else {
28
+ data += `&host_id=${hostId}`;
29
+ }
30
+
31
+ if (!url) return; // no parameters
32
+ const spinner = window.spinner_placeholder(__('Loading parameters...'));
33
+ const placeholder = $(
34
+ `<tr id="puppetclass_${id}_params_loading"><td colspan="5">${spinner}</td></tr>`
35
+ );
36
+ $('#puppet_klasses_parameters_table').append(placeholder);
37
+ $.ajax({
38
+ type: 'post',
39
+ url,
40
+ data,
41
+ success: (result, textstatus, xhr) => {
42
+ const params = $(result);
43
+ placeholder.replaceWith(params);
44
+ params.find('a[rel="popover"]').popover();
45
+ if (params.find('.error').length > 0)
46
+ $('#puppet_enc_tab').addClass('tab-error');
47
+ },
48
+ });
49
+ }
50
+
51
+ export function updatePuppetclasses(element) {
52
+ const hostId = $('form.hostresource-form').data('id');
53
+ const url = $('#puppet_klasses_reload_url').data('url');
54
+ let data = window.serializeForm().replace('method=patch', 'method=post');
55
+
56
+ if (element.value === '') return;
57
+ if (url.match('hostgroups')) {
58
+ data += `&hostgroup_id=${hostId}`;
59
+ } else {
60
+ data += `&host_id=${hostId}`;
61
+ }
62
+
63
+ store.dispatch(LayoutActions.showLoading());
64
+ window.tfm.tools.showSpinner();
65
+ $.ajax({
66
+ type: 'post',
67
+ url,
68
+ data,
69
+ success: request => {
70
+ $('#puppet_enc_tab').html(request);
71
+ window.tfm.tools.activateTooltips();
72
+ checkForUnavailablePuppetclasses();
73
+ },
74
+ complete: () => {
75
+ store.dispatch(LayoutActions.hideLoading());
76
+ // TODO do only the necessary - we know what we are loading here
77
+ window.reloadOnAjaxComplete(element);
78
+ },
79
+ });
80
+ }
81
+
82
+ export function reloadPuppetclassParams() {
83
+ const hostId = $('form.hostresource-form').data('id');
84
+ const url = $('#puppet_klasses_parameters').data('url');
85
+ let data = window.serializeForm().replace('method=patch', 'method=post');
86
+ if (url.match('hostgroups')) {
87
+ data += `&hostgroup_id=${hostId}`;
88
+ } else {
89
+ data += `&host_id=${hostId}`;
90
+ }
91
+ window.load_with_placeholder('puppet_klasses_parameters_table', url, data);
92
+ }
93
+
94
+ export function checkForUnavailablePuppetclasses() {
95
+ const unavailableClasses = $(
96
+ '#puppet_enc_tab #selected_classes .unavailable'
97
+ );
98
+ const puppetEncTab = $('#puppet_enc_tab');
99
+ const tab = puppetEncTab
100
+ .closest('form')
101
+ .find('.nav-tabs a[href="#puppet_enc_tab"]');
102
+ const warningMessage = __(
103
+ 'Some Puppet Classes are unavailable in the selected environment'
104
+ );
105
+ const warning = `<div class="alert alert-warning" id="puppetclasses_unavailable_warning">
106
+ <span class="pficon pficon-warning-triangle-o"></span>
107
+ ${warningMessage}
108
+ </span>`;
109
+
110
+ if (unavailableClasses.size() > 0) {
111
+ if (puppetEncTab.find('#puppetclasses_unavailable_warning').length <= 0) {
112
+ tab.prepend('<span class="pficon pficon-warning-triangle-o"></span> ');
113
+ puppetEncTab.prepend(warning);
114
+ }
115
+ } else {
116
+ puppetEncTab.find('#puppetclasses_unavailable_warning').remove();
117
+ tab.find('.pficon-warning-triangle-o').remove();
118
+ }
119
+ }
120
+
121
+ export function overridePuppetclassParam(item) {
122
+ const remove = $(item).data('tag') === 'remove';
123
+ const row = $(item)
124
+ .closest('tr')
125
+ .toggleClass('overridden');
126
+ const value = row.find('textarea') || row.find('select');
127
+ row
128
+ .find('[type=checkbox]')
129
+ .prop('checked', false)
130
+ .toggle();
131
+ row.find('input, textarea').prop('disabled', remove);
132
+ row.find('input, select').prop('disabled', remove);
133
+ row.find('.send_to_remove').prop('disabled', false);
134
+ row.find('.destroy').val(remove);
135
+ value.val(value.attr('data-inherited-value'));
136
+ $(item)
137
+ .hide()
138
+ .siblings('.btn-override')
139
+ .show();
140
+ }
@@ -0,0 +1,65 @@
1
+ /* eslint-disable jquery/no-size */
2
+
3
+ import $ from 'jquery';
4
+
5
+ import { checkForUnavailablePuppetclasses } from './foreman_puppet_host_form';
6
+
7
+ jest.unmock('jquery');
8
+ jest.unmock('./foreman_puppet_host_form');
9
+
10
+ describe('checkForUnavailablePuppetclasses', () => {
11
+ beforeEach(() => {
12
+ document.body.innerHTML = `<div>
13
+ <ul class="nav-tabs">
14
+ <li><a href="#puppet_enc_tab" data-toggle="tab">Puppet Classes</a></li>
15
+ </ul>
16
+ <div class="tab-content">
17
+ <form>
18
+ <div class="tab-pane active" id="hostgroup">
19
+ <div class="form-group">
20
+ <div>
21
+ <input id="hostgroup_environment_id"/>
22
+ </div>
23
+ <span class="help-block"></span>
24
+ </div>
25
+ </div>
26
+ <div class="tab-pane" id="puppet_enc_tab">
27
+ <div id="selected_classes"></div>
28
+ </div>
29
+ </form>
30
+ </div>
31
+ </div>`;
32
+ });
33
+
34
+ it('adds a warning if an unavailable class is found', () => {
35
+ $('#selected_classes').append(
36
+ '<li class="unavailable">Unavailable Class</li>'
37
+ );
38
+
39
+ checkForUnavailablePuppetclasses();
40
+ expect($('#puppetclasses_unavailable_warning').size()).toBe(1);
41
+ });
42
+
43
+ it('does not add a warning if no unavailable classes are found', () => {
44
+ $('#hostgroup .help-block').empty();
45
+ $('#selected_classes').empty();
46
+
47
+ checkForUnavailablePuppetclasses();
48
+ expect(
49
+ $('#hostgroup .help-block')
50
+ .first()
51
+ .children()
52
+ .size()
53
+ ).toBe(0);
54
+ });
55
+
56
+ it('adds a warning sign to the tab if unavailable classes are found', () => {
57
+ $('#selected_classes').append(
58
+ '<li class="unavailable">Unavailable Class</li>'
59
+ );
60
+ checkForUnavailablePuppetclasses();
61
+ setTimeout(() => {
62
+ expect($('a .pficon').size()).toBe(1);
63
+ }, 100);
64
+ });
65
+ });