forked from RedHatInsights/vulnerability-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ESSNTL-5253): Check tab permissions (RedHatInsights#2000)
Fixes https://issues.redhat.com/browse/ESSNTL-5253. Before rendering the application content in tabs on System details view, Inventory should check whether the user have enough viewer permissions for the selected app.
- Loading branch information
Showing
3 changed files
with
83 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { usePermissionsWithContext } from '@redhat-cloud-services/frontend-components-utilities/RBACHook'; | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import AccessDenied from './Utilities/AccessDenied'; | ||
import { | ||
AdvisorTab, | ||
ComplianceTab, | ||
PatchTab, | ||
RosTab, | ||
VulnerabilityTab, | ||
} from './components/SystemDetails'; | ||
import { TAB_REQUIRED_PERMISSIONS } from './constants'; | ||
|
||
const ApplicationTab = ({ appName, title }) => { | ||
const { hasAccess } = usePermissionsWithContext( | ||
TAB_REQUIRED_PERMISSIONS[appName] | ||
); | ||
|
||
const tabs = { | ||
advisor: AdvisorTab, | ||
vulnerability: VulnerabilityTab, | ||
compliance: ComplianceTab, | ||
patch: PatchTab, | ||
ros: RosTab, | ||
}; | ||
|
||
const Tab = tabs[appName]; | ||
|
||
return hasAccess ? ( | ||
<Tab /> | ||
) : ( | ||
<AccessDenied | ||
requiredPermission={TAB_REQUIRED_PERMISSIONS[appName].join(', ')} | ||
description={ | ||
<div> | ||
Contact your organization administrator(s) for more information. | ||
</div> | ||
} | ||
title={`You do not have access to ${title}`} | ||
/> | ||
); | ||
}; | ||
|
||
ApplicationTab.propTypes = { | ||
title: PropTypes.string.isRequired, | ||
appName: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default ApplicationTab; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters