katello 3.7.0.rc1 → 3.7.0.rc2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of katello might be problematic. Click here for more details.

Files changed (189) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/katello/api/v2/content_views_controller.rb +5 -2
  3. data/app/controllers/katello/api/v2/environments_controller.rb +8 -3
  4. data/app/controllers/katello/api/v2/host_tracer_controller.rb +1 -1
  5. data/app/controllers/katello/api/v2/upstream_subscriptions_controller.rb +4 -4
  6. data/app/helpers/katello/hosts_and_hostgroups_helper.rb +5 -22
  7. data/app/lib/actions/katello/host/update_content_overrides.rb +1 -0
  8. data/app/lib/actions/katello/product/content_create.rb +1 -0
  9. data/app/lib/actions/katello/product/repositories_certs_reset.rb +25 -0
  10. data/app/lib/actions/katello/product/update.rb +6 -0
  11. data/app/lib/katello/resources/candlepin/activation_key.rb +8 -4
  12. data/app/lib/katello/resources/candlepin/product.rb +2 -1
  13. data/app/lib/katello/util/cdn_var_substitutor.rb +5 -3
  14. data/app/lib/katello/util/package.rb +21 -13
  15. data/app/lib/katello/util/package_filter.rb +33 -31
  16. data/app/lib/katello/validators/prior_validator.rb +6 -10
  17. data/app/models/katello/concerns/host_managed_extensions.rb +2 -0
  18. data/app/models/katello/concerns/organization_extensions.rb +1 -0
  19. data/app/models/katello/concerns/subscription_facet_host_extensions.rb +10 -6
  20. data/app/models/katello/content.rb +23 -2
  21. data/app/models/katello/content_view_docker_filter.rb +1 -1
  22. data/app/models/katello/content_view_puppet_module.rb +3 -3
  23. data/app/models/katello/content_view_version.rb +4 -0
  24. data/app/models/katello/environment_prior.rb +7 -0
  25. data/app/models/katello/glue/candlepin/candlepin_object.rb +2 -2
  26. data/app/models/katello/glue/candlepin/pool.rb +10 -13
  27. data/app/models/katello/glue/candlepin/product.rb +19 -9
  28. data/app/models/katello/glue/candlepin/repository.rb +16 -0
  29. data/app/models/katello/glue/candlepin/subscription.rb +1 -1
  30. data/app/models/katello/glue/provider.rb +15 -81
  31. data/app/models/katello/host/subscription_facet.rb +1 -1
  32. data/app/models/katello/kt_environment.rb +39 -8
  33. data/app/models/katello/pool.rb +2 -1
  34. data/app/models/katello/rpm.rb +144 -2
  35. data/app/models/katello/upstream_pool.rb +7 -10
  36. data/app/services/katello/candlepin/pool_service.rb +18 -3
  37. data/app/services/katello/ui_notifications/pulp/proxy_disk_space.rb +13 -16
  38. data/app/views/dashboard/_content_views_widget.html.erb +3 -3
  39. data/app/views/dashboard/_errata_widget.html.erb +2 -2
  40. data/app/views/dashboard/_host_collection_widget.html.erb +3 -3
  41. data/app/views/dashboard/_subscription_status_widget.html.erb +2 -2
  42. data/app/views/dashboard/_subscription_widget.html.erb +1 -1
  43. data/app/views/dashboard/_sync_widget.html.erb +3 -3
  44. data/app/views/katello/api/v2/subscriptions/base.json.rabl +1 -1
  45. data/app/views/katello/api/v2/upstream_subscriptions/base.json.rabl +2 -6
  46. data/app/views/katello/layouts/react.html.erb +3 -3
  47. data/config/katello.yaml +89 -0
  48. data/config/routes.rb +3 -0
  49. data/db/migrate/20160302091113_change_environment_prior.rb +9 -0
  50. data/db/migrate/20180410140909_add_organization_id_to_pool.rb +2 -1
  51. data/db/migrate/20180612163403_add_foreign_key_to_hypervisor_id.rb +10 -0
  52. data/db/migrate/20180612164926_add_content_org_id.rb +39 -0
  53. data/db/migrate/20180612165011_remove_content_fields_from_host.rb +7 -0
  54. data/db/migrate/20180626160422_add_upstream_pool_id_to_katello_pool.rb +9 -0
  55. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-hosts/bulk/views/content-hosts-bulk-packages-modal.html +1 -1
  56. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-hosts/views/register.html +1 -1
  57. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/environments/details/environment-content.controller.js +2 -3
  58. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/environments/details/views/environment.html +4 -2
  59. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/environments/environments.controller.js +19 -14
  60. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/environments/new-environment.controller.js +18 -5
  61. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/environments/paths.service.js +51 -0
  62. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/environments/views/new-environment.html +16 -3
  63. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/products/bulk/products-bulk-advanced-sync-modal.controller.js +1 -1
  64. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/products/products.controller.js +2 -2
  65. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/subscriptions/subscriptions.routes.js +3 -3
  66. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/tasks/tasks.module.js +1 -6
  67. data/engines/bastion_katello/app/assets/stylesheets/bastion_katello/bastion_katello.scss +4 -0
  68. data/engines/bastion_katello/lib/bastion_katello/engine.rb +1 -1
  69. data/lib/katello/plugin.rb +2 -11
  70. data/lib/katello/scheduled_jobs.rb +2 -14
  71. data/lib/katello/tasks/clean_backend_objects.rake +2 -0
  72. data/lib/katello/tasks/repository.rake +11 -2
  73. data/lib/katello/tasks/upgrades/3.7/import_pools.rake +12 -0
  74. data/lib/katello/version.rb +1 -1
  75. data/package.json +4 -3
  76. data/webpack/components/PaginationRow/index.js +6 -2
  77. data/webpack/containers/Application/config.js +7 -2
  78. data/webpack/index.js +3 -5
  79. data/webpack/move_to_foreman/common/helpers.js +5 -24
  80. data/webpack/move_to_foreman/components/common/emptyState/index.js +12 -7
  81. data/webpack/move_to_foreman/components/common/table/components/CollapseSubscriptionGroupButton.js +31 -0
  82. data/webpack/move_to_foreman/components/common/table/components/CollapseSubscriptionGroupButton.test.js +16 -0
  83. data/webpack/move_to_foreman/components/common/table/components/Table.js +76 -0
  84. data/webpack/move_to_foreman/components/common/table/components/Table.test.js +31 -0
  85. data/webpack/move_to_foreman/components/common/table/components/TableBody.js +27 -0
  86. data/webpack/move_to_foreman/components/common/table/components/TableBody.test.js +18 -0
  87. data/webpack/move_to_foreman/components/common/table/components/TableBodyMessage.js +18 -0
  88. data/webpack/move_to_foreman/components/common/table/components/TableBodyMessage.test.js +12 -0
  89. data/webpack/move_to_foreman/components/common/table/components/TableFixtures.js +14 -0
  90. data/webpack/move_to_foreman/components/common/table/components/TableSelectionCell.js +39 -0
  91. data/webpack/move_to_foreman/components/common/table/components/TableSelectionCell.test.js +16 -0
  92. data/webpack/move_to_foreman/components/common/table/components/TableSelectionHeaderCell.js +34 -0
  93. data/webpack/move_to_foreman/components/common/table/components/TableSelectionHeaderCell.test.js +14 -0
  94. data/webpack/move_to_foreman/components/common/table/components/__snapshots__/CollapseSubscriptionGroupButton.test.js.snap +19 -0
  95. data/webpack/move_to_foreman/components/common/table/components/__snapshots__/Table.test.js.snap +167 -0
  96. data/webpack/move_to_foreman/components/common/table/components/__snapshots__/TableBody.test.js.snap +28 -0
  97. data/webpack/move_to_foreman/components/common/table/components/__snapshots__/TableBodyMessage.test.js.snap +13 -0
  98. data/webpack/move_to_foreman/components/common/table/components/__snapshots__/TableSelectionCell.test.js.snap +16 -0
  99. data/webpack/move_to_foreman/components/common/table/components/__snapshots__/TableSelectionHeaderCell.test.js.snap +15 -0
  100. data/webpack/move_to_foreman/components/common/table/components/index.js +6 -0
  101. data/webpack/move_to_foreman/components/common/table/formatters/cellFormatter.js +4 -0
  102. data/webpack/move_to_foreman/components/common/table/formatters/collapseableAndSelectionCellFormatter.js +18 -0
  103. data/webpack/move_to_foreman/components/common/table/formatters/ellipsisCellFormatter.js +5 -0
  104. data/webpack/move_to_foreman/components/common/table/formatters/headerFormatter.js +4 -0
  105. data/webpack/move_to_foreman/components/common/table/formatters/index.js +6 -0
  106. data/webpack/move_to_foreman/components/common/table/formatters/selectionCellFormatter.js +17 -0
  107. data/webpack/move_to_foreman/components/common/table/formatters/selectionHeaderCellFormatter.js +10 -0
  108. data/webpack/move_to_foreman/components/common/table/index.js +2 -88
  109. data/webpack/move_to_pf/LoadingState/LoadingState.js +35 -0
  110. data/webpack/move_to_pf/LoadingState/LoadingState.scss +12 -0
  111. data/webpack/move_to_pf/LoadingState/LoadingState.test.js +28 -0
  112. data/webpack/move_to_pf/LoadingState/__snapshots__/LoadingState.test.js.snap +20 -0
  113. data/webpack/move_to_pf/LoadingState/index.js +3 -0
  114. data/webpack/move_to_pf/test-utils/testHelpers.js +71 -0
  115. data/webpack/redux/actions/RedHatRepositories/enabled.js +1 -1
  116. data/webpack/redux/actions/RedHatRepositories/helpers.js +34 -9
  117. data/webpack/redux/actions/RedHatRepositories/sets.js +28 -6
  118. data/webpack/redux/consts.js +1 -0
  119. data/webpack/redux/reducers/RedHatRepositories/sets.fixtures.js +12 -2
  120. data/webpack/redux/reducers/RedHatRepositories/sets.js +34 -27
  121. data/webpack/redux/reducers/RedHatRepositories/sets.test.js +10 -2
  122. data/webpack/redux/reducers/index.js +2 -0
  123. data/webpack/scenes/Organizations/OrganizationActions.js +3 -3
  124. data/webpack/scenes/RedHatRepositories/components/RecommendedRepositorySetsToggler.js +44 -0
  125. data/webpack/scenes/RedHatRepositories/components/RecommendedRepositorySetsToggler.scss +16 -0
  126. data/webpack/scenes/RedHatRepositories/components/RepositorySet.js +8 -2
  127. data/webpack/scenes/RedHatRepositories/components/RepositorySetRepositories.js +5 -3
  128. data/webpack/scenes/RedHatRepositories/components/RepositorySetRepository.js +4 -2
  129. data/webpack/scenes/RedHatRepositories/components/Search.js +1 -1
  130. data/webpack/scenes/RedHatRepositories/components/SearchBar.js +1 -1
  131. data/webpack/scenes/RedHatRepositories/components/__tests__/RecommendedRepositorySetsToggler.test.js +17 -0
  132. data/webpack/scenes/RedHatRepositories/components/__tests__/__snapshots__/RecommendedRepositorySetsToggler.test.js.snap +37 -0
  133. data/webpack/scenes/RedHatRepositories/helpers.js +1 -1
  134. data/webpack/scenes/RedHatRepositories/index.js +17 -7
  135. data/webpack/scenes/RedHatRepositories/index.scss +16 -4
  136. data/webpack/scenes/Subscriptions/Details/SubscriptionAttributes.js +17 -0
  137. data/webpack/scenes/Subscriptions/Details/SubscriptionDetailActions.js +28 -0
  138. data/webpack/scenes/Subscriptions/Details/SubscriptionDetailAssociations.js +47 -0
  139. data/webpack/scenes/Subscriptions/Details/SubscriptionDetailConstants.js +3 -0
  140. data/webpack/scenes/Subscriptions/Details/SubscriptionDetailInfo.js +65 -0
  141. data/webpack/scenes/Subscriptions/Details/SubscriptionDetailProducts.js +20 -0
  142. data/webpack/scenes/Subscriptions/Details/SubscriptionDetailReducer.js +37 -0
  143. data/webpack/scenes/Subscriptions/Details/SubscriptionDetails.js +58 -0
  144. data/webpack/scenes/Subscriptions/Details/__tests__/SubscriptionDetailActions.test.js +47 -0
  145. data/webpack/scenes/Subscriptions/Details/__tests__/SubscriptionDetailAssociations.test.js +16 -0
  146. data/webpack/scenes/Subscriptions/Details/__tests__/SubscriptionDetailInfo.test.js +15 -0
  147. data/webpack/scenes/Subscriptions/Details/__tests__/SubscriptionDetailProducts.test.js +16 -0
  148. data/webpack/scenes/Subscriptions/Details/__tests__/SubscriptionDetailReducer.test.js +39 -0
  149. data/webpack/scenes/Subscriptions/Details/__tests__/SubscriptionDetails.test.js +28 -0
  150. data/webpack/scenes/Subscriptions/Details/__tests__/__snapshots__/SubscriptionDetailAssociations.test.js.snap +53 -0
  151. data/webpack/scenes/Subscriptions/Details/__tests__/__snapshots__/SubscriptionDetailInfo.test.js.snap +185 -0
  152. data/webpack/scenes/Subscriptions/Details/__tests__/__snapshots__/SubscriptionDetailProducts.test.js.snap +77 -0
  153. data/webpack/scenes/Subscriptions/Details/__tests__/__snapshots__/SubscriptionDetails.test.js.snap +432 -0
  154. data/webpack/scenes/Subscriptions/Details/__tests__/subscriptionDetails.fixtures.js +167 -0
  155. data/webpack/scenes/Subscriptions/Details/index.js +19 -0
  156. data/webpack/scenes/Subscriptions/Manifest/ManageManifestModal.js +58 -12
  157. data/webpack/scenes/Subscriptions/Manifest/Manifest.scss +6 -1
  158. data/webpack/scenes/Subscriptions/Manifest/ManifestActions.js +4 -4
  159. data/webpack/scenes/Subscriptions/Manifest/ManifestHistoryTableSchema.js +7 -7
  160. data/webpack/scenes/Subscriptions/Manifest/__tests__/__snapshots__/ManageManifestModal.test.js.snap +6 -9
  161. data/webpack/scenes/Subscriptions/Manifest/index.js +2 -2
  162. data/webpack/scenes/Subscriptions/SubscriptionActions.js +5 -6
  163. data/webpack/scenes/Subscriptions/SubscriptionReducer.js +2 -3
  164. data/webpack/scenes/Subscriptions/SubscriptionValidations.js +1 -1
  165. data/webpack/scenes/Subscriptions/SubscriptionsPage.js +46 -30
  166. data/webpack/scenes/Subscriptions/SubscriptionsPage.scss +38 -0
  167. data/webpack/scenes/Subscriptions/UpstreamSubscriptions/UpstreamSubscriptionsActions.js +3 -3
  168. data/webpack/scenes/Subscriptions/UpstreamSubscriptions/UpstreamSubscriptionsPage.js +7 -6
  169. data/webpack/scenes/Subscriptions/UpstreamSubscriptions/UpstreamSubscriptionsTableSchema.js +17 -14
  170. data/webpack/scenes/Subscriptions/UpstreamSubscriptions/__tests__/__snapshots__/UpstreamSubscriptionsPage.test.js.snap +12 -15
  171. data/webpack/scenes/Subscriptions/UpstreamSubscriptions/__tests__/upstreamSubscriptions.fixtures.js +4 -4
  172. data/webpack/scenes/Subscriptions/__tests__/SubscriptionValidations.test.js +5 -0
  173. data/webpack/scenes/Subscriptions/__tests__/subscriptions.fixtures.js +2 -2
  174. data/webpack/scenes/Subscriptions/{EntitlementsInlineEditFormatter.js → components/SubscriptionsTable/EntitlementsInlineEditFormatter.js} +7 -7
  175. data/webpack/scenes/Subscriptions/{SubscriptionsTable.js → components/SubscriptionsTable/SubscriptionsTable.js} +75 -47
  176. data/webpack/scenes/Subscriptions/components/SubscriptionsTable/SubscriptionsTableHelpers.js +60 -0
  177. data/webpack/scenes/Subscriptions/{SubscriptionsTableSchema.js → components/SubscriptionsTable/SubscriptionsTableSchema.js} +37 -26
  178. data/webpack/scenes/Subscriptions/components/SubscriptionsTable/__tests__/SubscriptionsTable.test.js +56 -0
  179. data/webpack/scenes/Subscriptions/{__tests__ → components/SubscriptionsTable/__tests__}/__snapshots__/SubscriptionsTable.test.js.snap +16 -5
  180. data/webpack/scenes/Subscriptions/components/SubscriptionsTable/index.js +2 -0
  181. data/webpack/scenes/Subscriptions/index.js +2 -2
  182. data/webpack/scenes/Tasks/TaskActions.js +18 -11
  183. data/webpack/scenes/Tasks/__tests__/TaskActions.test.js +92 -9
  184. data/webpack/scenes/Tasks/__tests__/task.fixtures.js +19 -9
  185. data/webpack/services/api/index.js +2 -2
  186. data/webpack/test_setup.js +1 -0
  187. metadata +79 -10
  188. data/webpack/scenes/Subscriptions/Subscriptions.scss +0 -14
  189. data/webpack/scenes/Subscriptions/__tests__/SubscriptionsTable.test.js +0 -47
@@ -0,0 +1,60 @@
1
+ const buildTableRow = (subscription, availableQuantities, updatedQuantity) => {
2
+ if (updatedQuantity[subscription.id]) {
3
+ return {
4
+ ...subscription,
5
+ entitlementsChanged: true,
6
+ quantity: updatedQuantity[subscription.id],
7
+ availableQuantity: availableQuantities[subscription.id],
8
+ };
9
+ }
10
+ return {
11
+ ...subscription,
12
+ availableQuantity: availableQuantities[subscription.id],
13
+ };
14
+ };
15
+
16
+ const buildTableRowsFromGroup = (subscriptionGroup, availableQuantities, updatedQuantity) => {
17
+ const { open, subscriptions } = subscriptionGroup;
18
+
19
+ // build row for each subscription
20
+ if (open) {
21
+ return subscriptions.map(subscription =>
22
+ buildTableRow(subscription, availableQuantities, updatedQuantity));
23
+ }
24
+
25
+ // build row only for the first subscription in the group
26
+ const [firstSubscription] = subscriptions;
27
+ return [buildTableRow(firstSubscription, availableQuantities, updatedQuantity)];
28
+ };
29
+
30
+ export const buildTableRows = (groupdSubscriptions, availableQuantities, updatedQuantity) => {
31
+ const rows = [];
32
+
33
+ Object.values(groupdSubscriptions).forEach(subscriptionGroup =>
34
+ rows.push(...buildTableRowsFromGroup(subscriptionGroup, availableQuantities, updatedQuantity)));
35
+
36
+ return rows;
37
+ };
38
+
39
+ export const groupSubscriptionsByProductId = ({ results: subscriptions }) => {
40
+ const grouped = {};
41
+
42
+ subscriptions.forEach((subscription) => {
43
+ if (grouped[subscription.product_id] === undefined) {
44
+ grouped[subscription.product_id] = {
45
+ open: false,
46
+ subscriptions: [],
47
+ };
48
+ }
49
+
50
+ grouped[subscription.product_id].subscriptions.unshift(subscription);
51
+ });
52
+
53
+ return grouped;
54
+ };
55
+
56
+ export const buildPools = updatedQuantity =>
57
+ Object.entries(updatedQuantity).map(([id, quantity]) => ({
58
+ id,
59
+ quantity,
60
+ }));
@@ -1,10 +1,21 @@
1
+ /* eslint-disable import/prefer-default-export */
1
2
  import React from 'react';
2
3
  import { Icon } from 'patternfly-react';
3
- import helpers, { selectionHeaderCellFormatter, selectionCellFormatter } from '../../move_to_foreman/common/helpers';
4
+ import { Link } from 'react-router-dom';
5
+ import helpers from '../../../../move_to_foreman/common/helpers';
4
6
  import { entitlementsInlineEditFormatter } from './EntitlementsInlineEditFormatter';
5
- import { headerFormat, cellFormat } from '../../move_to_foreman/components/common/table';
7
+ import {
8
+ headerFormatter,
9
+ cellFormatter,
10
+ selectionHeaderCellFormatter,
11
+ collapseableAndSelectionCellFormatter,
12
+ } from '../../../../move_to_foreman/components/common/table';
6
13
 
7
- export const columns = (inlineEditController, selectionController) => [
14
+ export const createSubscriptionsTableSchema = (
15
+ inlineEditController,
16
+ selectionController,
17
+ groupingController,
18
+ ) => [
8
19
  {
9
20
  property: 'select',
10
21
  header: {
@@ -12,23 +23,27 @@ export const columns = (inlineEditController, selectionController) => [
12
23
  formatters: [label => selectionHeaderCellFormatter(selectionController, label)],
13
24
  },
14
25
  cell: {
15
- formatters: [(value, additionalData) =>
16
- selectionCellFormatter(selectionController, value, additionalData)],
26
+ formatters: [
27
+ (value, additionalData) =>
28
+ collapseableAndSelectionCellFormatter(
29
+ groupingController,
30
+ selectionController,
31
+ additionalData,
32
+ ),
33
+ ],
17
34
  },
18
35
  },
19
36
  {
20
37
  property: 'id',
21
38
  header: {
22
39
  label: __('Name'),
23
- formatters: [headerFormat],
40
+ formatters: [headerFormatter],
24
41
  },
25
42
  cell: {
26
43
  formatters: [
27
44
  (value, { rowData }) => (
28
45
  <td>
29
- <a href={helpers.urlBuilder('subscriptions', '', rowData.id)}>
30
- {rowData.name}
31
- </a>
46
+ <Link to={helpers.urlBuilder('subscriptions', '', rowData.id)}>{rowData.name}</Link>
32
47
  </td>
33
48
  ),
34
49
  ],
@@ -38,47 +53,47 @@ export const columns = (inlineEditController, selectionController) => [
38
53
  property: 'product_id',
39
54
  header: {
40
55
  label: __('SKU'),
41
- formatters: [headerFormat],
56
+ formatters: [headerFormatter],
42
57
  },
43
58
  cell: {
44
- formatters: [cellFormat],
59
+ formatters: [cellFormatter],
45
60
  },
46
61
  },
47
62
  {
48
63
  property: 'contract_number',
49
64
  header: {
50
65
  label: __('Contract'),
51
- formatters: [headerFormat],
66
+ formatters: [headerFormatter],
52
67
  },
53
68
  cell: {
54
- formatters: [cellFormat],
69
+ formatters: [cellFormatter],
55
70
  },
56
71
  }, // TODO: use date formatter from tomas' PR
57
72
  {
58
73
  property: 'start_date',
59
74
  header: {
60
75
  label: __('Start Date'),
61
- formatters: [headerFormat],
76
+ formatters: [headerFormatter],
62
77
  },
63
78
  cell: {
64
- formatters: [cellFormat],
79
+ formatters: [cellFormatter],
65
80
  },
66
81
  },
67
82
  {
68
83
  property: 'end_date',
69
84
  header: {
70
85
  label: __('End Date'),
71
- formatters: [headerFormat],
86
+ formatters: [headerFormatter],
72
87
  },
73
88
  cell: {
74
- formatters: [cellFormat],
89
+ formatters: [cellFormatter],
75
90
  },
76
91
  },
77
92
  {
78
93
  property: 'virt_who',
79
94
  header: {
80
95
  label: __('Requires Virt-Who'),
81
- formatters: [headerFormat],
96
+ formatters: [headerFormatter],
82
97
  },
83
98
  cell: {
84
99
  formatters: [
@@ -94,24 +109,20 @@ export const columns = (inlineEditController, selectionController) => [
94
109
  property: 'consumed',
95
110
  header: {
96
111
  label: __('Consumed'),
97
- formatters: [headerFormat],
112
+ formatters: [headerFormatter],
98
113
  },
99
114
  cell: {
100
- formatters: [cellFormat],
115
+ formatters: [cellFormatter],
101
116
  },
102
117
  },
103
118
  {
104
119
  property: 'quantity',
105
120
  header: {
106
121
  label: __('Entitlements'),
107
- formatters: [headerFormat],
122
+ formatters: [headerFormatter],
108
123
  },
109
124
  cell: {
110
- formatters: [
111
- entitlementsInlineEditFormatter(inlineEditController),
112
- ],
125
+ formatters: [entitlementsInlineEditFormatter(inlineEditController)],
113
126
  },
114
127
  },
115
128
  ];
116
-
117
- export default columns;
@@ -0,0 +1,56 @@
1
+ import React from 'react';
2
+ import { render } from 'enzyme';
3
+ import toJson from 'enzyme-to-json';
4
+ import { MemoryRouter } from 'react-router-dom';
5
+ import SubscriptionsTable from '../SubscriptionsTable';
6
+ import { successState, loadingState, emptyState } from '../../../__tests__/subscriptions.fixtures';
7
+ import { loadSubscriptions, updateQuantity } from '../../../SubscriptionActions';
8
+
9
+ describe('subscriptions table', () => {
10
+ it('should render a table', async () => {
11
+ // Wrapping SubscriptionTable in MemoryRouter here since it contains
12
+ // a Link componenent, which can't be used outside a Router
13
+ /* eslint-disable react/jsx-indent */
14
+ const page = render(<MemoryRouter>
15
+ <SubscriptionsTable
16
+ subscriptions={successState}
17
+ loadSubscriptions={loadSubscriptions}
18
+ updateQuantity={updateQuantity}
19
+ subscriptionDeleteModalOpen={false}
20
+ onSubscriptionDeleteModalClose={() => { }}
21
+ onDeleteSubscriptions={() => {}}
22
+ toggleDeleteButton={() => {}}
23
+ />
24
+ </MemoryRouter>);
25
+ expect(toJson(page)).toMatchSnapshot();
26
+ });
27
+ /* eslint-enable react/jsx-indent */
28
+
29
+ it('should render an empty state', async () => {
30
+ const page = render(<MemoryRouter>
31
+ <SubscriptionsTable
32
+ subscriptions={emptyState}
33
+ loadSubscriptions={loadSubscriptions}
34
+ updateQuantity={updateQuantity}
35
+ subscriptionDeleteModalOpen={false}
36
+ onSubscriptionDeleteModalClose={() => {}}
37
+ onDeleteSubscriptions={() => {}}
38
+ toggleDeleteButton={() => {}}
39
+ />
40
+ </MemoryRouter>);
41
+ expect(toJson(page)).toMatchSnapshot();
42
+ });
43
+
44
+ it('should render a loading state', async () => {
45
+ const page = render(<SubscriptionsTable
46
+ subscriptions={loadingState}
47
+ loadSubscriptions={loadSubscriptions}
48
+ updateQuantity={updateQuantity}
49
+ subscriptionDeleteModalOpen={false}
50
+ onSubscriptionDeleteModalClose={() => { }}
51
+ onDeleteSubscriptions={() => {}}
52
+ toggleDeleteButton={() => {}}
53
+ />);
54
+ expect(toJson(page)).toMatchSnapshot();
55
+ });
56
+ });
@@ -2,8 +2,15 @@
2
2
 
3
3
  exports[`subscriptions table should render a loading state 1`] = `
4
4
  <div
5
- class="small-spacer spinner spinner-md"
6
- />
5
+ class="loading-state"
6
+ >
7
+ <div
8
+ class="spinner spinner-lg"
9
+ />
10
+ <p>
11
+ Loading
12
+ </p>
13
+ </div>
7
14
  `;
8
15
 
9
16
  exports[`subscriptions table should render a table 1`] = `
@@ -75,7 +82,9 @@ Array [
75
82
  </tr>
76
83
  </thead>
77
84
  <tbody>
78
- <tr>
85
+ <tr
86
+ class=""
87
+ >
79
88
  <td
80
89
  class="table-view-pf-select"
81
90
  >
@@ -130,7 +139,9 @@ Array [
130
139
  Unlimited
131
140
  </td>
132
141
  </tr>
133
- <tr>
142
+ <tr
143
+ class=""
144
+ >
134
145
  <td
135
146
  class="table-view-pf-select"
136
147
  >
@@ -188,7 +199,7 @@ Array [
188
199
  </tbody>
189
200
  </table>
190
201
  <form
191
- class="content-view-pf-pagination table-view-pf-pagination clearfix "
202
+ class="content-view-pf-pagination table-view-pf-pagination clearfix"
192
203
  >
193
204
  <div
194
205
  class="form-group"
@@ -0,0 +1,2 @@
1
+ export { default as SubscriptionsTable } from './SubscriptionsTable';
2
+ export { default as SubscriptionsTableSchema } from './SubscriptionsTableSchema';
@@ -8,12 +8,12 @@ import * as settingActions from '../../move_to_foreman/Settings/SettingsActions'
8
8
  import reducer from './SubscriptionReducer';
9
9
 
10
10
  import SubscriptionsPage from './SubscriptionsPage';
11
- import './Subscriptions.scss';
12
11
 
12
+ const EMPTY_ARRAY = [];
13
13
  // map state to props
14
14
  const mapStateToProps = state => ({
15
15
  subscriptions: state.katello.subscriptions,
16
- tasks: state.katello.subscriptions.tasks,
16
+ tasks: state.katello.subscriptions.tasks || EMPTY_ARRAY,
17
17
  });
18
18
 
19
19
  // map action dispatchers to props
@@ -52,24 +52,31 @@ export const loadTask = (taskId, extendedParams = {}) => (dispatch) => {
52
52
  }));
53
53
  };
54
54
 
55
+ const isUnauthorized = action =>
56
+ (action.result && action.result.response && action.result.response.status === 401);
57
+
55
58
  export const pollBulkSearch = (extendedParams = {}, interval) => (dispatch) => {
56
- const triggerPolling = () => {
57
- setTimeout(() => dispatch(pollBulkSearch(extendedParams, interval)), interval);
59
+ const triggerPolling = (action) => {
60
+ if (!isUnauthorized(action)) {
61
+ setTimeout(() => dispatch(pollBulkSearch(extendedParams, interval)), interval);
62
+ }
58
63
  };
59
64
 
60
65
  return dispatch(bulkSearch(extendedParams)).then(triggerPolling);
61
66
  };
62
67
 
63
- export const pollTaskUntilDone = (taskId, extendedParams = {}, interval) =>
64
- dispatch => new Promise((resolve) => {
65
- const pollUntilDone = (task) => {
66
- if (task.pending !== false) {
67
- setTimeout(() => dispatch(loadTask(taskId, extendedParams))
68
- .then(({ response }) => pollUntilDone(response)), interval);
68
+ export const pollTaskUntilDone = (taskId, extendedParams = {}, interval) => dispatch => (
69
+ new Promise((resolve, reject) => {
70
+ const pollUntilDone = (action) => {
71
+ if (isUnauthorized(action)) {
72
+ reject(action.result);
73
+ } else if (action.response.pending !== false) {
74
+ setTimeout(() => dispatch(loadTask(taskId, extendedParams)).then(pollUntilDone), interval);
69
75
  } else {
70
- resolve(task);
76
+ resolve(action.response);
71
77
  }
72
78
  };
73
79
 
74
- pollUntilDone({ pending: true });
75
- });
80
+ return dispatch(loadTask(taskId, extendedParams)).then(pollUntilDone);
81
+ })
82
+ );
@@ -6,13 +6,15 @@ import configureMockStore from 'redux-mock-store';
6
6
  import {
7
7
  bulkSearchSuccessResponse,
8
8
  bulkSearchSuccessActions,
9
- bulkSearchFailureActions,
9
+ buildBulkSearchFailureActions,
10
10
  getTaskSuccessResponse,
11
11
  getTaskSuccessActions,
12
- getTaskFailureActions,
12
+ buildTaskFailureActions,
13
+ getTaskPendingResponse,
14
+ getTaskPendingActions,
13
15
  } from './task.fixtures';
14
16
 
15
- import { bulkSearch, loadTask, pollTaskUntilDone } from '../TaskActions';
17
+ import { bulkSearch, loadTask, pollTaskUntilDone, pollBulkSearch } from '../TaskActions';
16
18
 
17
19
  const mockStore = configureMockStore([thunk]);
18
20
  const store = mockStore({ tasks: Immutable({}) });
@@ -24,13 +26,19 @@ beforeEach(() => {
24
26
  });
25
27
 
26
28
  let originalTimeout;
29
+ let setTimeoutSpy;
27
30
 
28
31
  beforeEach(() => {
32
+ setTimeoutSpy = jest.spyOn(window, 'setTimeout');
33
+
29
34
  originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
30
35
  jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
31
36
  });
32
37
 
33
38
  afterEach(() => {
39
+ setTimeoutSpy.mockReset();
40
+ setTimeoutSpy.mockRestore();
41
+
34
42
  jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
35
43
  });
36
44
 
@@ -42,7 +50,7 @@ describe('task actions', () => {
42
50
  mockApi.onPost(url).reply(422);
43
51
 
44
52
  return store.dispatch(bulkSearch())
45
- .then(() => expect(store.getActions()).toEqual(bulkSearchFailureActions));
53
+ .then(() => expect(store.getActions()).toEqual(buildBulkSearchFailureActions()));
46
54
  });
47
55
 
48
56
  it('and ends with success', () => {
@@ -61,7 +69,7 @@ describe('task actions', () => {
61
69
  mockApi.onGet(url).reply(422);
62
70
 
63
71
  return store.dispatch(loadTask(taskId))
64
- .then(() => expect(store.getActions()).toEqual(getTaskFailureActions));
72
+ .then(() => expect(store.getActions()).toEqual(buildTaskFailureActions()));
65
73
  });
66
74
 
67
75
  it('and ends with success', () => {
@@ -70,12 +78,87 @@ describe('task actions', () => {
70
78
  return store.dispatch(loadTask(taskId))
71
79
  .then(() => expect(store.getActions()).toEqual(getTaskSuccessActions));
72
80
  });
81
+ });
73
82
 
74
- it('and can poll', () => {
75
- mockApi.onGet(url).reply(200, getTaskSuccessResponse);
83
+ describe('pollTaskUntilDone', () => {
84
+ const taskId = 'eb1b6271-8a69-4d98-84fc-bea06ddcc166';
85
+ const url = `/foreman_tasks/api/tasks/${taskId}`;
76
86
 
77
- return store.dispatch(pollTaskUntilDone(taskId))
78
- .then(() => expect(store.getActions()).toEqual(getTaskSuccessActions));
87
+ it("doesn't start polling when the task has finished", () => {
88
+ mockApi.onGet(url).replyOnce(200, getTaskSuccessResponse);
89
+
90
+ return store
91
+ .dispatch(pollTaskUntilDone(taskId, {}, 1))
92
+ .then(() => {
93
+ expect(store.getActions()).toEqual(getTaskSuccessActions);
94
+ expect(setTimeoutSpy).toHaveBeenCalledTimes(0);
95
+ });
96
+ });
97
+
98
+ it('polls until a task is done', () => {
99
+ mockApi
100
+ .onGet(url)
101
+ .replyOnce(200, getTaskPendingResponse)
102
+ .onGet(url)
103
+ .replyOnce(200, getTaskPendingResponse)
104
+ .onGet(url)
105
+ .replyOnce(200, getTaskSuccessResponse);
106
+
107
+ const expectedActions = getTaskPendingActions
108
+ .concat(getTaskPendingActions)
109
+ .concat(getTaskSuccessActions);
110
+
111
+ return store
112
+ .dispatch(pollTaskUntilDone(taskId, {}, 1))
113
+ .then(() => {
114
+ expect(store.getActions()).toEqual(expectedActions);
115
+ expect(setTimeoutSpy).toHaveBeenCalledTimes(2);
116
+ });
117
+ });
118
+
119
+ it('stops polling on unauthorized response', () => {
120
+ mockApi
121
+ .onGet(url).replyOnce(200, getTaskPendingResponse)
122
+ .onGet(url).replyOnce(401);
123
+
124
+ const expectedActions = getTaskPendingActions
125
+ .concat(buildTaskFailureActions(401));
126
+
127
+ return store
128
+ .dispatch(pollTaskUntilDone(taskId, {}, 1))
129
+ .catch(() => {
130
+ expect(store.getActions()).toEqual(expectedActions);
131
+ expect(setTimeoutSpy).toHaveBeenCalledTimes(1);
132
+ });
133
+ });
134
+ });
135
+
136
+ describe('pollBulkSearch', () => {
137
+ const url = '/foreman_tasks/api/tasks/bulk_search';
138
+
139
+ it('polls', () => {
140
+ mockApi
141
+ .onPost(url)
142
+ .replyOnce(200, bulkSearchSuccessResponse);
143
+
144
+ return store
145
+ .dispatch(pollBulkSearch({}, 1))
146
+ .then(() => {
147
+ expect(store.getActions()).toEqual(bulkSearchSuccessActions);
148
+ expect(setTimeoutSpy).toHaveBeenCalledTimes(1);
149
+ });
150
+ });
151
+
152
+ it('stops polling on unauthorized response', () => {
153
+ mockApi
154
+ .onPost(url).replyOnce(401);
155
+
156
+ return store
157
+ .dispatch(pollBulkSearch({}, 1))
158
+ .then(() => {
159
+ expect(store.getActions()).toEqual(buildBulkSearchFailureActions(401));
160
+ expect(setTimeoutSpy).toHaveBeenCalledTimes(0);
161
+ });
79
162
  });
80
163
  });
81
164
  });