foreman_rh_cloud 14.0.3 → 14.1.1

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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/insights_cloud/candlepin_proxies_extensions.rb +23 -0
  3. data/app/controllers/concerns/insights_cloud/package_profile_upload_extensions.rb +9 -0
  4. data/app/controllers/foreman_inventory_upload/accounts_controller.rb +1 -1
  5. data/app/controllers/foreman_inventory_upload/api/tasks_controller.rb +2 -2
  6. data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +9 -2
  7. data/app/models/concerns/rh_cloud_host.rb +35 -3
  8. data/app/models/insights_client_report_status.rb +9 -1
  9. data/app/models/inventory_sync/inventory_status.rb +16 -4
  10. data/lib/foreman_inventory_upload/async/create_missing_insights_facets.rb +8 -2
  11. data/lib/foreman_rh_cloud/engine.rb +1 -0
  12. data/lib/foreman_rh_cloud/version.rb +1 -1
  13. data/lib/insights_cloud/async/vmaas_reposcan_sync.rb +23 -8
  14. data/lib/inventory_sync/async/inventory_full_sync.rb +39 -3
  15. data/package.json +1 -1
  16. data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +40 -0
  17. data/test/controllers/insights_cloud/candlepin_proxies_extensions_test.rb +70 -0
  18. data/test/jobs/insights_client_status_aging_test.rb +40 -0
  19. data/test/jobs/inventory_full_sync_test.rb +212 -0
  20. data/test/models/insights_client_report_status_test.rb +109 -0
  21. data/test/models/inventory_sync/inventory_status_test.rb +85 -0
  22. data/test/unit/lib/insights_cloud/async/vmaas_reposcan_sync_test.rb +80 -25
  23. data/test/unit/rh_cloud_host_test.rb +214 -0
  24. data/webpack/CVEsHostDetailsTab/CVEsHostDetailsTab.js +30 -3
  25. data/webpack/CVEsHostDetailsTab/__tests__/CVEsHostDetailsTab.test.js +112 -10
  26. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +8 -2
  27. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap +1 -0
  28. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/integrations.test.js +1 -0
  29. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/Toast.js +43 -17
  30. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/__tests__/Toast.test.js +82 -0
  31. data/webpack/ForemanRhCloudHelpers.js +22 -0
  32. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTable.js +7 -4
  33. data/webpack/InsightsCloudSync/Components/InsightsTable/table.scss +9 -0
  34. data/webpack/InsightsHostDetailsTab/NewHostDetailsTab.js +53 -12
  35. data/webpack/InsightsHostDetailsTab/__tests__/NewHostDetailsTab.test.js +134 -22
  36. metadata +7 -1
@@ -58,6 +58,8 @@ const InsightsTable = ({
58
58
  if (hideHost) setColumns(getColumnsWithoutHostname());
59
59
  }, [hits, selectedIds, hideHost]);
60
60
 
61
+ const hasSelectableRows = rows.some(row => !row.disableCheckbox);
62
+
61
63
  return (
62
64
  <React.Fragment>
63
65
  <SelectAllAlert
@@ -71,10 +73,11 @@ const InsightsTable = ({
71
73
  className="rh-cloud-recommendations-table"
72
74
  ouiaId="rh-cloud-recommendations-table"
73
75
  aria-label="Recommendations Table"
74
- onSelect={(_event, isSelected, rowId) =>
75
- onTableSelect(isSelected, rowId, rows, selectedIds)
76
- }
77
- canSelectAll={rows.length > 0}
76
+ {...(hasSelectableRows && {
77
+ onSelect: (_event, isSelected, rowId) =>
78
+ onTableSelect(isSelected, rowId, rows, selectedIds),
79
+ })}
80
+ canSelectAll={hasSelectableRows}
78
81
  sortBy={{
79
82
  index: getSortColumnIndex(columns, sortBy),
80
83
  direction: sortOrder,
@@ -5,6 +5,15 @@
5
5
  }
6
6
  }
7
7
 
8
+ tbody .pf-v5-c-table__check {
9
+ vertical-align: middle;
10
+ }
11
+
12
+ thead .pf-v5-c-table__check label {
13
+ position: relative;
14
+ top: 2px;
15
+ }
16
+
8
17
  .td-insights-remediate-playbook {
9
18
  svg {
10
19
  margin-right: 5px;
@@ -25,6 +25,11 @@ import { useIopConfig } from '../common/Hooks/ConfigHooks';
25
25
  import { generateRuleUrl } from '../InsightsCloudSync/InsightsCloudSync';
26
26
  import { createProviderOptions } from '../common/ScalprumModule/ScalprumContext';
27
27
  import { useInsightsPermissions } from '../common/Hooks/PermissionsHooks';
28
+ import {
29
+ isNotRhelHost,
30
+ hasNoInsightsFacet,
31
+ useTabRedirect,
32
+ } from '../ForemanRhCloudHelpers';
28
33
 
29
34
  // Hosted Insights advisor
30
35
  const NewHostDetailsTab = ({ hostName, router }) => {
@@ -128,17 +133,32 @@ NewHostDetailsTab.defaultProps = {
128
133
  const scope = 'advisor';
129
134
  const module = './SystemDetailWrapped';
130
135
 
131
- const IopInsightsTab = props => (
132
- <div className="advisor">
133
- <ScalprumComponent
134
- scope={scope}
135
- module={module}
136
- IopRemediationModal={RemediationModal}
137
- generateRuleUrl={generateRuleUrl}
138
- {...props}
139
- />
140
- </div>
141
- );
136
+ const IopInsightsTab = props => {
137
+ // eslint-disable-next-line camelcase
138
+ const systemId = props.response?.subscription_facet_attributes?.uuid;
139
+ return (
140
+ <div className="advisor">
141
+ <ScalprumComponent
142
+ key={systemId || props.hostName}
143
+ scope={scope}
144
+ module={module}
145
+ IopRemediationModal={RemediationModal}
146
+ generateRuleUrl={generateRuleUrl}
147
+ {...props}
148
+ />
149
+ </div>
150
+ );
151
+ };
152
+
153
+ IopInsightsTab.propTypes = {
154
+ hostName: PropTypes.string,
155
+ response: PropTypes.object,
156
+ };
157
+
158
+ IopInsightsTab.defaultProps = {
159
+ hostName: '',
160
+ response: {},
161
+ };
142
162
 
143
163
  const IopInsightsTabWrapped = props => {
144
164
  const permissions = useInsightsPermissions();
@@ -150,7 +170,18 @@ const IopInsightsTabWrapped = props => {
150
170
  };
151
171
 
152
172
  const InsightsTab = props => {
173
+ const { response } = props;
153
174
  const isIop = useIopConfig();
175
+ const isHostDataLoaded = Boolean(response?.id);
176
+ const shouldHideTab = useTabRedirect(
177
+ isHostDataLoaded &&
178
+ (isNotRhelHost({ hostDetails: response }) ||
179
+ hasNoInsightsFacet({ response, hostDetails: response }))
180
+ );
181
+
182
+ if (shouldHideTab) {
183
+ return null;
184
+ }
154
185
 
155
186
  return isIop ? (
156
187
  <IopInsightsTabWrapped {...props} />
@@ -159,6 +190,16 @@ const InsightsTab = props => {
159
190
  );
160
191
  };
161
192
 
162
- InsightsTab.defaultProps = {};
193
+ InsightsTab.propTypes = {
194
+ response: PropTypes.shape({
195
+ id: PropTypes.number,
196
+ operatingsystem_name: PropTypes.string,
197
+ insights_attributes: PropTypes.object,
198
+ }),
199
+ };
200
+
201
+ InsightsTab.defaultProps = {
202
+ response: {},
203
+ };
163
204
 
164
205
  export default InsightsTab;
@@ -2,9 +2,20 @@ import React from 'react';
2
2
  import { render } from '@testing-library/react';
3
3
  import '@testing-library/jest-dom';
4
4
  import { Provider } from 'react-redux';
5
+ import { MemoryRouter } from 'react-router-dom';
5
6
  import configureMockStore from 'redux-mock-store';
6
7
  import thunk from 'redux-thunk';
7
8
  import NewHostDetailsTab from '../NewHostDetailsTab';
9
+ import { OVERVIEW_TAB_PATH } from '../../ForemanRhCloudHelpers';
10
+
11
+ const mockHistoryReplace = jest.fn();
12
+
13
+ jest.mock('react-router-dom', () => ({
14
+ ...jest.requireActual('react-router-dom'),
15
+ useHistory: () => ({
16
+ replace: mockHistoryReplace,
17
+ }),
18
+ }));
8
19
 
9
20
  jest.mock('../../common/Hooks/ConfigHooks', () => ({
10
21
  useIopConfig: jest.fn(() => false),
@@ -14,8 +25,33 @@ jest.mock('foremanReact/common/I18n', () => ({
14
25
  translate: jest.fn(str => str),
15
26
  }));
16
27
 
28
+ jest.mock(
29
+ 'foremanReact/components/SearchBar',
30
+ () => () => <div>SearchBar</div>,
31
+ { virtual: true }
32
+ );
33
+
34
+ jest.mock('../../InsightsCloudSync/Components/InsightsTable', () => () => (
35
+ <div>InsightsTable</div>
36
+ ));
37
+
38
+ jest.mock('../../InsightsCloudSync/Components/RemediationModal', () => () => (
39
+ <div>RemediationModal</div>
40
+ ));
41
+
42
+ jest.mock(
43
+ '../../InsightsCloudSync/Components/InsightsTable/Pagination',
44
+ () => () => <div>Pagination</div>
45
+ );
46
+
17
47
  const mockStore = configureMockStore([thunk]);
18
48
 
49
+ const defaultResponse = {
50
+ id: 1,
51
+ operatingsystem_name: 'Red Hat Enterprise Linux 8',
52
+ insights_attributes: { uuid: 'test-uuid' },
53
+ };
54
+
19
55
  describe('NewHostDetailsTab', () => {
20
56
  let store;
21
57
  let mockRouter;
@@ -68,17 +104,18 @@ describe('NewHostDetailsTab', () => {
68
104
  it('should preserve hash when clearing search params on unmount', () => {
69
105
  const { unmount } = render(
70
106
  <Provider store={store}>
71
- <NewHostDetailsTab
72
- hostName="test-host.example.com"
73
- router={mockRouter}
74
- />
107
+ <MemoryRouter>
108
+ <NewHostDetailsTab
109
+ hostName="test-host.example.com"
110
+ router={mockRouter}
111
+ response={defaultResponse}
112
+ />
113
+ </MemoryRouter>
75
114
  </Provider>
76
115
  );
77
116
 
78
- // Unmount the component to trigger cleanup
79
117
  unmount();
80
118
 
81
- // Verify router.replace was called with both search: null AND the existing hash
82
119
  expect(mockRouter.replace).toHaveBeenCalledWith({
83
120
  search: null,
84
121
  hash: '#/Insights',
@@ -90,16 +127,18 @@ describe('NewHostDetailsTab', () => {
90
127
 
91
128
  const { unmount } = render(
92
129
  <Provider store={store}>
93
- <NewHostDetailsTab
94
- hostName="test-host.example.com"
95
- router={mockRouter}
96
- />
130
+ <MemoryRouter>
131
+ <NewHostDetailsTab
132
+ hostName="test-host.example.com"
133
+ router={mockRouter}
134
+ response={defaultResponse}
135
+ />
136
+ </MemoryRouter>
97
137
  </Provider>
98
138
  );
99
139
 
100
140
  unmount();
101
141
 
102
- // When there's no hash, should only pass search: null
103
142
  expect(mockRouter.replace).toHaveBeenCalledWith({
104
143
  search: null,
105
144
  });
@@ -114,16 +153,18 @@ describe('NewHostDetailsTab', () => {
114
153
 
115
154
  const { unmount } = render(
116
155
  <Provider store={store}>
117
- <NewHostDetailsTab
118
- hostName="test-host.example.com"
119
- router={routerWithoutLocation}
120
- />
156
+ <MemoryRouter>
157
+ <NewHostDetailsTab
158
+ hostName="test-host.example.com"
159
+ router={routerWithoutLocation}
160
+ response={defaultResponse}
161
+ />
162
+ </MemoryRouter>
121
163
  </Provider>
122
164
  );
123
165
 
124
166
  unmount();
125
167
 
126
- // Should still call replace with search: null even if location is undefined
127
168
  expect(routerWithoutLocation.replace).toHaveBeenCalledWith({
128
169
  search: null,
129
170
  });
@@ -132,23 +173,94 @@ describe('NewHostDetailsTab', () => {
132
173
  it('should use the latest hash value at unmount time, not a stale captured value', () => {
133
174
  const { unmount } = render(
134
175
  <Provider store={store}>
135
- <NewHostDetailsTab
136
- hostName="test-host.example.com"
137
- router={mockRouter}
138
- />
176
+ <MemoryRouter>
177
+ <NewHostDetailsTab
178
+ hostName="test-host.example.com"
179
+ router={mockRouter}
180
+ response={defaultResponse}
181
+ />
182
+ </MemoryRouter>
139
183
  </Provider>
140
184
  );
141
185
 
142
- // Change the hash after mount, before unmount
143
186
  mockRouter.location.hash = '#/Overview';
144
187
 
145
188
  unmount();
146
189
 
147
- // Verify router.replace was called with the UPDATED hash, not the initial '#/Insights'
148
190
  expect(mockRouter.replace).toHaveBeenCalledWith({
149
191
  search: null,
150
192
  hash: '#/Overview',
151
193
  });
152
194
  });
153
195
  });
196
+
197
+ describe('tab visibility', () => {
198
+ it('should redirect to Overview when host is not RHEL', () => {
199
+ const nonRhelResponse = {
200
+ id: 2,
201
+ operatingsystem_name: 'Ubuntu 20.04',
202
+ insights_attributes: { uuid: 'test-uuid' },
203
+ };
204
+
205
+ render(
206
+ <Provider store={store}>
207
+ <MemoryRouter>
208
+ <NewHostDetailsTab
209
+ hostName="test-host.example.com"
210
+ response={nonRhelResponse}
211
+ />
212
+ </MemoryRouter>
213
+ </Provider>
214
+ );
215
+
216
+ expect(mockHistoryReplace).toHaveBeenCalledWith(OVERVIEW_TAB_PATH);
217
+ });
218
+
219
+ it('should redirect to Overview when insights facet is missing', () => {
220
+ const responseWithoutInsights = {
221
+ id: 3,
222
+ operatingsystem_name: 'Red Hat Enterprise Linux 8',
223
+ };
224
+
225
+ render(
226
+ <Provider store={store}>
227
+ <MemoryRouter>
228
+ <NewHostDetailsTab
229
+ hostName="test-host.example.com"
230
+ response={responseWithoutInsights}
231
+ />
232
+ </MemoryRouter>
233
+ </Provider>
234
+ );
235
+
236
+ expect(mockHistoryReplace).toHaveBeenCalledWith(OVERVIEW_TAB_PATH);
237
+ });
238
+
239
+ it('should not redirect when host is valid RHEL with insights facet', () => {
240
+ render(
241
+ <Provider store={store}>
242
+ <MemoryRouter>
243
+ <NewHostDetailsTab
244
+ hostName="test-host.example.com"
245
+ response={defaultResponse}
246
+ />
247
+ </MemoryRouter>
248
+ </Provider>
249
+ );
250
+
251
+ expect(mockHistoryReplace).not.toHaveBeenCalled();
252
+ });
253
+
254
+ it('should not redirect when host data is not yet loaded', () => {
255
+ render(
256
+ <Provider store={store}>
257
+ <MemoryRouter>
258
+ <NewHostDetailsTab hostName="test-host.example.com" response={{}} />
259
+ </MemoryRouter>
260
+ </Provider>
261
+ );
262
+
263
+ expect(mockHistoryReplace).not.toHaveBeenCalled();
264
+ });
265
+ });
154
266
  });
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_rh_cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 14.0.3
4
+ version: 14.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Foreman Red Hat Cloud team
@@ -101,6 +101,7 @@ files:
101
101
  - app/controllers/concerns/foreman_rh_cloud/iop_smart_proxy_access.rb
102
102
  - app/controllers/concerns/foreman_rh_cloud/registration_manager_extensions.rb
103
103
  - app/controllers/concerns/insights_cloud/candlepin_cache.rb
104
+ - app/controllers/concerns/insights_cloud/candlepin_proxies_extensions.rb
104
105
  - app/controllers/concerns/insights_cloud/client_authentication.rb
105
106
  - app/controllers/concerns/insights_cloud/package_profile_upload_extensions.rb
106
107
  - app/controllers/concerns/inventory_upload/report_actions.rb
@@ -248,6 +249,7 @@ files:
248
249
  - test/controllers/insights_cloud/api/advisor_engine_controller_test.rb
249
250
  - test/controllers/insights_cloud/api/cloud_request_controller_test.rb
250
251
  - test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb
252
+ - test/controllers/insights_cloud/candlepin_proxies_extensions_test.rb
251
253
  - test/controllers/insights_cloud/ui_requests_controller_test.rb
252
254
  - test/controllers/insights_sync/settings_controller_test.rb
253
255
  - test/controllers/inventory_upload/api/inventory_controller_test.rb
@@ -274,6 +276,7 @@ files:
274
276
  - test/jobs/single_host_report_job_test.rb
275
277
  - test/jobs/upload_report_direct_job_test.rb
276
278
  - test/models/insights_client_report_status_test.rb
279
+ - test/models/inventory_sync/inventory_status_test.rb
277
280
  - test/test_plugin_helper.rb
278
281
  - test/unit/archived_report_generator_test.rb
279
282
  - test/unit/fact_helpers_test.rb
@@ -448,6 +451,7 @@ files:
448
451
  - webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap
449
452
  - webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/integrations.test.js
450
453
  - webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/Toast.js
454
+ - webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/__tests__/Toast.test.js
451
455
  - webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/index.js
452
456
  - webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/ToolbarButtons.js
453
457
  - webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/ToolbarButtons.test.js
@@ -677,6 +681,7 @@ test_files:
677
681
  - test/controllers/insights_cloud/api/advisor_engine_controller_test.rb
678
682
  - test/controllers/insights_cloud/api/cloud_request_controller_test.rb
679
683
  - test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb
684
+ - test/controllers/insights_cloud/candlepin_proxies_extensions_test.rb
680
685
  - test/controllers/insights_cloud/ui_requests_controller_test.rb
681
686
  - test/controllers/insights_sync/settings_controller_test.rb
682
687
  - test/controllers/inventory_upload/api/inventory_controller_test.rb
@@ -703,6 +708,7 @@ test_files:
703
708
  - test/jobs/single_host_report_job_test.rb
704
709
  - test/jobs/upload_report_direct_job_test.rb
705
710
  - test/models/insights_client_report_status_test.rb
711
+ - test/models/inventory_sync/inventory_status_test.rb
706
712
  - test/test_plugin_helper.rb
707
713
  - test/unit/archived_report_generator_test.rb
708
714
  - test/unit/fact_helpers_test.rb