Skip to content

Commit

Permalink
refactor(RHIF-213): Remove the last insights.chrome call (#1886)
Browse files Browse the repository at this point in the history
* refactor: Create RBAC wrapper for CVEs component

Fixes https://issues.redhat.com/browse/RHIF-213.

This removes the last occurrence of direct call to insights.chrome.
Together with this change, CVEs component is refactored to abstract the
RBAC logic from the core component and make it cypress-testable.

* Update snapshots
  • Loading branch information
gkarat authored Mar 23, 2023
1 parent b20b397 commit cd6f142
Show file tree
Hide file tree
Showing 5 changed files with 10,670 additions and 10,644 deletions.
4 changes: 2 additions & 2 deletions src/Components/SmartComponents/CVEs/CVEs.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mount } from '@cypress/react';
import { BrowserRouter as Router } from 'react-router-dom';
import { Provider } from 'react-redux';

import CVEs from './CVEs';
import { CVEs } from './CVEs';
import ReducerRegistry from '../../../Utilities/ReducerRegistry';

import cvesResponse from '../../../../cypress/fixtures/cves.json';
Expand All @@ -23,7 +23,7 @@ const mountComponent = () => {
<IntlProvider locale="en" messages={messages}>
<Provider store={ReducerRegistry.getStore()}>
<Router>
<CVEs />
<CVEs rbac={[[true, true, true, true], false]}/>
</Router>
</Provider>
</IntlProvider>
Expand Down
26 changes: 18 additions & 8 deletions src/Components/SmartComponents/CVEs/CVEs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useMemo, useState, useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { Stack, StackItem } from '@patternfly/react-core';
import PropTypes from 'prop-types';
import { CVES_ALLOWED_PARAMS, PERMISSIONS, SERVICE_NAME } from '../../../Helpers/constants';
import { createCveListByAccount } from '../../../Helpers/VulnerabilityHelper';
import { constructFilterParameters, updateRef, useUrlParams } from '../../../Helpers/MiscHelper';
Expand Down Expand Up @@ -28,18 +29,13 @@ import { NotAuthorized } from '../../PresentationalComponents/EmptyStates/EmptyS

export const CVETableContext = React.createContext({});

export const CVEs = () => {
export const CVEs = ({ rbac }) => {
const dispatch = useDispatch();
const [CveStatusModal, setStatusModal] = useState(() => () => null);
const [CveBusinessRiskModal, setBusinessRiskModal] = useState(() => () => null);
const [isFirstLoad, setFirstLoad] = useState(true);

const [[canEditStatusOrBusinessRisk, canEditPairStatus, canExport, canReadVulnerabilityResults], isRbacLoading] = useRbac([
PERMISSIONS.setCveStatusAndBusinessRisk,
PERMISSIONS.setPairStatus,
PERMISSIONS.basicReporting,
PERMISSIONS.readVulnerabilityResults
]);
const [[canEditStatusOrBusinessRisk, canEditPairStatus, canExport, canReadVulnerabilityResults], isRbacLoading] = rbac;

const cveList = useSelector(
({ CVEsStore }) => CVEsStore.cveList
Expand Down Expand Up @@ -181,7 +177,21 @@ export const CVEs = () => {
} else {
return <ErrorHandler code={cves.errors.status}/>;
}
};

CVEs.propTypes = {
rbac: PropTypes.array.isRequired
};

const CVEsWithRbac = () => {
const rbac = useRbac([
PERMISSIONS.setCveStatusAndBusinessRisk,
PERMISSIONS.setPairStatus,
PERMISSIONS.basicReporting,
PERMISSIONS.readVulnerabilityResults
]);

return <CVEs rbac={rbac} />;
};

export default CVEs;
export default CVEsWithRbac;
Loading

0 comments on commit cd6f142

Please sign in to comment.