Skip to content

Commit

Permalink
Revert "fix: Check for inventory perms on all pages (#1545)" (#1552)
Browse files Browse the repository at this point in the history
This reverts commit be95f56.
  • Loading branch information
leSamo authored Feb 14, 2022
1 parent 42edbba commit 916057e
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 150 deletions.
5 changes: 2 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ ReducerRegistry.register({ notifications });
const App = () => {
const { push } = useHistory();
const { pathname } = useLocation();
const [[hasAnyVulnerabilityPermission, hasInventoryReadPermission], isLoading] =
useRbac([PERMISSIONS.accessApplication, PERMISSIONS.readHosts], '');
const [[isUserAuthorized], isLoading] = useRbac([PERMISSIONS.accessApplication]);
const [isReadOnlyBannerVisible, setReadOnlyBannerVisible] = useState(false);

const dispatch = useDispatch();
Expand Down Expand Up @@ -71,7 +70,7 @@ const App = () => {
window.setReadOnlyBannerVisible = setVisible => setReadOnlyBannerVisible(setVisible);

return (
isLoading ? <Spinner centered /> : (hasAnyVulnerabilityPermission && hasInventoryReadPermission) ?
isLoading ? <Spinner centered /> : isUserAuthorized ?
<Fragment>
<NotificationPortal />
{isReadOnlyBannerVisible && <ReadOnlyBanner />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
selectRows,
changeColumnsCveDetail
} from '../../../Store/Actions/Actions';
import { SYSTEMS_EXPOSED_HEADER, SYSTEMS_EXPOSED_ALLOWED_PARAMS } from '../../../Helpers/constants';
import { SYSTEMS_EXPOSED_HEADER, SYSTEMS_EXPOSED_ALLOWED_PARAMS, PERMISSIONS } from '../../../Helpers/constants';
import { TableVariant } from '@patternfly/react-table';
import { InventoryTable } from '@redhat-cloud-services/frontend-components/Inventory';
import ErrorHandler from '../../PresentationalComponents/ErrorHandler/ErrorHandler';
Expand All @@ -29,14 +29,21 @@ import {
} from '@redhat-cloud-services/frontend-components-notifications/redux';
import { EmptyStateNoSystems } from '../../PresentationalComponents/EmptyStates/EmptyStates';
import { SystemsExposedTableToolbar } from './SystemsExposedTableToolbar';
import { useGetEntities } from '../../../Helpers/Hooks';
import { useGetEntities, useRbac } from '../../../Helpers/Hooks';
import * as APIHelper from '../../../Helpers/APIHelper';
import ColumnManagementModal from '../Modals/ColumnManagementModal';
import Spinner from '@redhat-cloud-services/frontend-components/Spinner';

const SystemsExposedTable = ({
intl, cveName, cveStatusDetails, filterRuleValues,
hasSecurityRule, canEditPairStatus, canExport, inventoryRef, refreshInventory
}) => {
const [[
canReadHostsInventory],
isLoadingInventory] = useRbac([
PERMISSIONS.readHosts
], 'inventory');

const dispatch = useDispatch();
const [isAllExpanded, setIsAllExpanded] = useState(false);
const [StatusModal, setStatusModal] = useState(() => () => null);
Expand Down Expand Up @@ -133,88 +140,89 @@ const SystemsExposedTable = ({
</TextContent>
</StackItem>
<StackItem>
{error?.hasError
? <ErrorHandler code={error?.errorCode}/>
: <InventoryTable
disableDefaultColumns
onLoad={({ mergeWithEntities }) => {
ReducerRegistry.register({
...mergeWithEntities(
inventoryEntitiesReducer(SYSTEMS_EXPOSED_HEADER),
{
page: Number(parameters.page || 1),
perPage: 20,
...(parameters.sort && {
sortBy: {
key: parameters.sort.replace(/^-/, ''),
direction: parameters.sort.match(/^-/) ? 'desc' : 'asc'
}
})
}
)
});
}}
tableProps={{
isStickyHeader: true,
canSelectAll: false,
actionResolver: () => canEditPairStatus && totalItems &&
systemExposedTableRowActions(showStatusModal, cveStatusDetails),
variant: TableVariant.compact
}}
paginationProps={{
isDisabled: !totalItems
}}
showTagModal
isFullView
ref={inventoryRef}
autoRefresh
key="inventory"
customFilters={{
vulnerabilityParams: {
...parameters
}
}}
expandable={hasSecurityRule}
columnsCounter={columnCounter}
columns={defaultColumns => mergeColumns(defaultColumns)}
getEntities={getEntities}
hasCheckbox={totalItems !== 0}
showActions={totalItems !== 0}
onExpandClick={(_e, _i, isOpen, { id }) => dispatch(expandRow(id, isOpen))}
hideFilters={{ all: true }}
noSystemsTable={<EmptyStateNoSystems/>}
>
<SystemsExposedTableToolbar
rawData={{ data: items, meta: { totalItems }, isLoaded }}
parameters={parameters}
cveName={cveName}
expandAll={expandAll}
hasSecurityRule={hasSecurityRule}
isAllExpanded={isAllExpanded}
selectedRows={selectedRows}
selectedRowsCount={selectedRowsCount}
selectedRowsRawData={selectedRowsRawData}
cveStatusDetails={cveStatusDetails}
filterRuleValues={filterRuleValues}
methods={{
downloadReport,
apply,
handleSelect,
showStatusModal,
setColumnModalOpen
{isLoadingInventory ? <Spinner centered/> :
error?.hasError && !canReadHostsInventory
? <ErrorHandler code={error?.errorCode}/>
: <InventoryTable
disableDefaultColumns
onLoad={({ mergeWithEntities }) => {
ReducerRegistry.register({
...mergeWithEntities(
inventoryEntitiesReducer(SYSTEMS_EXPOSED_HEADER),
{
page: Number(parameters.page || 1),
perPage: 20,
...(parameters.sort && {
sortBy: {
key: parameters.sort.replace(/^-/, ''),
direction: parameters.sort.match(/^-/) ? 'desc' : 'asc'
}
})
}
)
});
}}
tableProps={{
isStickyHeader: true,
canSelectAll: false,
actionResolver: () => canEditPairStatus && totalItems &&
systemExposedTableRowActions(showStatusModal, cveStatusDetails),
variant: TableVariant.compact
}}
paginationProps={{
isDisabled: !totalItems
}}
showTagModal
isFullView
ref={inventoryRef}
autoRefresh
key="inventory"
customFilters={{
vulnerabilityParams: {
...parameters
}
}}
canEditPairStatus={canEditPairStatus}
canExport={canExport}
expandable={hasSecurityRule}
columnsCounter={columnCounter}
columns={defaultColumns => mergeColumns(defaultColumns)}
getEntities={getEntities}
hasCheckbox={totalItems !== 0}
showActions={totalItems !== 0}
onExpandClick={(_e, _i, isOpen, { id }) => dispatch(expandRow(id, isOpen))}
hideFilters={{ all: true }}
noSystemsTable={<EmptyStateNoSystems/>}
>
{StatusModal && <StatusModal/>}
<ColumnManagementModal
appliedColumns={columns}
applyColumns={newColumns => dispatch(changeColumnsCveDetail(newColumns))}
isModalOpen={isColumnModalOpen}
setModalOpen={setColumnModalOpen}
/>
</SystemsExposedTableToolbar>
</InventoryTable>}
<SystemsExposedTableToolbar
rawData={{ data: items, meta: { totalItems }, isLoaded }}
parameters={parameters}
cveName={cveName}
expandAll={expandAll}
hasSecurityRule={hasSecurityRule}
isAllExpanded={isAllExpanded}
selectedRows={selectedRows}
selectedRowsCount={selectedRowsCount}
selectedRowsRawData={selectedRowsRawData}
cveStatusDetails={cveStatusDetails}
filterRuleValues={filterRuleValues}
methods={{
downloadReport,
apply,
handleSelect,
showStatusModal,
setColumnModalOpen
}}
canEditPairStatus={canEditPairStatus}
canExport={canExport}
>
{StatusModal && <StatusModal/>}
<ColumnManagementModal
appliedColumns={columns}
applyColumns={newColumns => dispatch(changeColumnsCveDetail(newColumns))}
isModalOpen={isColumnModalOpen}
setModalOpen={setColumnModalOpen}
/>
</SystemsExposedTableToolbar>
</InventoryTable>}
</StackItem>
</Stack>
);
Expand Down
Loading

0 comments on commit 916057e

Please sign in to comment.