Skip to content

Commit

Permalink
VULN-2103 fix: Refresh exposed systems on CVE status update (#1399)
Browse files Browse the repository at this point in the history
  • Loading branch information
leSamo authored Dec 2, 2021
1 parent d3abf90 commit fbaaaf9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
12 changes: 10 additions & 2 deletions src/Components/SmartComponents/CVEDetailsPage/CVEDetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const CVEPageContext = React.createContext({ isLoading: true });

const CVEDetailsPage = ({ match }) => {
const dispatch = useDispatch();
const inventoryRef = React.createRef();

const [[canEditPairStatus, canEditStatusOrBusinessRisk, canExport, canReadVulnerabilityResults], isRbacLoading] = useRbac([
PERMISSIONS.setPairStatus,
Expand All @@ -48,6 +49,11 @@ const CVEDetailsPage = ({ match }) => {
dispatch(fetchCveDetails(cveName));
}, [dispatch, cveName]);

const refreshInventory = () => (
dispatch(clearInventoryStore()),
inventoryRef.current.onRefreshData(({ page: 1 }))
);

const showBusinessRiskModal = cves => {
setBusinessRisk(
() => () =>
Expand All @@ -60,9 +66,9 @@ const CVEDetailsPage = ({ match }) => {
() => () =>
<CveStatusModal
cves={cves}
updateRef={() => {
updateRef={overwriteSystemsStatus => {
dispatch(fetchCveDetails(cveName));
dispatch(clearInventoryStore());
overwriteSystemsStatus && refreshInventory();
}}
/>
);
Expand Down Expand Up @@ -148,6 +154,8 @@ const CVEDetailsPage = ({ match }) => {
hasSecurityRule={rules?.length > 0}
canEditPairStatus={canEditPairStatus}
canExport={canExport}
inventoryRef={inventoryRef}
refreshInventory={refreshInventory}
/>
) :
<NotAuthorized />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('CVE details:', () => {
const statusModal = wrapper.find('CveStatusModal');
expect(statusModal).toBeTruthy();
act(() => statusModal.props().updateRef());
expect(store.getActions()[5].type).toEqual('CLEAR_INVENTORY_STORE');
expect(store.getActions()[4].type).toEqual('FETCH_CVE_DETAILS');
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/Components/SmartComponents/Modals/CveStatusModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const CveStatusModal = ({ cves, updateRef, intl }) => {
})
]
])
.then(updateRef)
.then(() => updateRef(!checkboxState))
.catch(error => { throw error; }); // propagate error to BaseModal
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ import * as APIHelper from '../../../Helpers/APIHelper';
import ColumnManagementModal from '../Modals/ColumnManagementModal';

const SystemsExposedTable = ({ intl, cveName, cveStatusDetails, filterRuleValues,
hasSecurityRule, canEditPairStatus, canExport }) => {

const inventoryRef = React.createRef();
hasSecurityRule, canEditPairStatus, canExport, inventoryRef, refreshInventory }) => {
const dispatch = useDispatch();
const [StatusModal, setStatusModal] = useState(() => () => null);
const [urlParameters, setUrlParams] = useUrlParams(SYSTEMS_EXPOSED_ALLOWED_PARAMS);
Expand Down Expand Up @@ -84,18 +82,13 @@ const SystemsExposedTable = ({ intl, cveName, cveStatusDetails, filterRuleValues
);
};

const onRefreshInventory = () => (
dispatch(clearInventoryStore()),
inventoryRef.current.onRefreshData(({ page: 1 }))
);

const showStatusModal = (cves, inventories) => {
setStatusModal(
() => () =>
<CvePairStatusModal
cveList={cves}
updateRef={() => {
onRefreshInventory();
refreshInventory();
dispatch(fetchCveDetails(cveName));
}}
inventoryList={inventories}
Expand Down Expand Up @@ -222,7 +215,9 @@ SystemsExposedTable.propTypes = {
filterRuleValues: propTypes.array,
hasSecurityRule: propTypes.bool,
canEditPairStatus: propTypes.bool,
canExport: propTypes.bool
canExport: propTypes.bool,
inventoryRef: propTypes.object,
refreshInventory: propTypes.func
};

export default injectIntl(
Expand Down

0 comments on commit fbaaaf9

Please sign in to comment.