Skip to content

Commit

Permalink
Merge pull request #1207 from swaterkamp/MenuPermissions
Browse files Browse the repository at this point in the history
Menu permissions
  • Loading branch information
bjoernricks authored Mar 13, 2019
2 parents 2b2f043 + a5180bc commit fc014db
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 41 deletions.
105 changes: 65 additions & 40 deletions gsa/src/web/components/bar/menubar.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,25 @@ const MenuBar = ({gmp, capabilities}) => {
'permissions',
].reduce((sum, cur) => sum || capabilities.mayAccess(cur), false);

const mayOpNotesOverrides = ['notes', 'overrides'].reduce(
(sum, cur) => sum || capabilities.mayAccess(cur),
false,
);

const mayOpAlertsSchedulesReportFormatsAgents = [
'alerts',
'schedules',
'report_formats',
'agents',
].reduce((sum, cur) => sum || capabilities.mayAccess(cur), false);

const mayOpScannersFiltersTagsPermissions = [
'scanners',
'filters',
'tags',
'permissions',
].reduce((sum, cur) => sum || capabilities.mayAccess(cur), false);

const may_op_admin =
['users', 'roles', 'groups'].reduce(
(sum, cur) => sum || capabilities.mayAccess(cur),
Expand All @@ -118,23 +137,25 @@ const MenuBar = ({gmp, capabilities}) => {
{capabilities.mayAccess('vulns') && (
<MenuEntry title={_('Vulnerabilities')} to="vulnerabilities" />
)}
<MenuSection>
{capabilities.mayAccess('tickets') && (
{capabilities.mayAccess('tickets') && (
<MenuSection>
<MenuEntry
section
title={_('Remediation Tickets')}
to="tickets"
/>
)}
</MenuSection>
<MenuSection>
{capabilities.mayAccess('notes') && (
<MenuEntry section title={_('Notes')} to="notes" />
)}
{capabilities.mayAccess('overrides') && (
<MenuEntry title={_('Overrides')} to="overrides" />
)}
</MenuSection>
</MenuSection>
)}
{mayOpNotesOverrides && (
<MenuSection>
{capabilities.mayAccess('notes') && (
<MenuEntry section title={_('Notes')} to="notes" />
)}
{capabilities.mayAccess('overrides') && (
<MenuEntry title={_('Overrides')} to="overrides" />
)}
</MenuSection>
)}
</Menu>
)}
{capabilities.mayAccess('assets') && (
Expand Down Expand Up @@ -170,34 +191,38 @@ const MenuBar = ({gmp, capabilities}) => {
{capabilities.mayAccess('configs') && (
<MenuEntry title={_('Scan Configs')} to="scanconfigs" />
)}
<MenuSection>
{capabilities.mayAccess('alerts') && (
<MenuEntry title={_('Alerts')} to="alerts" />
)}
{capabilities.mayAccess('schedules') && (
<MenuEntry title={_('Schedules')} to="schedules" />
)}
{capabilities.mayAccess('report_formats') && (
<MenuEntry title={_('Report Formats')} to="reportformats" />
)}
{capabilities.mayAccess('agents') && (
<MenuEntry title={_('Agents')} to="agents" />
)}
</MenuSection>
<MenuSection>
{capabilities.mayAccess('scanners') && (
<MenuEntry title={_('Scanners')} to="scanners" />
)}
{capabilities.mayAccess('filters') && (
<MenuEntry title={_('Filters')} to="filters" />
)}
{capabilities.mayAccess('tags') && (
<MenuEntry title={_('Tags')} to="tags" />
)}
{capabilities.mayAccess('permissions') && (
<MenuEntry title={_('Permissions')} to="permissions" />
)}
</MenuSection>
{mayOpAlertsSchedulesReportFormatsAgents && (
<MenuSection>
{capabilities.mayAccess('alerts') && (
<MenuEntry title={_('Alerts')} to="alerts" />
)}
{capabilities.mayAccess('schedules') && (
<MenuEntry title={_('Schedules')} to="schedules" />
)}
{capabilities.mayAccess('report_formats') && (
<MenuEntry title={_('Report Formats')} to="reportformats" />
)}
{capabilities.mayAccess('agents') && (
<MenuEntry title={_('Agents')} to="agents" />
)}
</MenuSection>
)}
{mayOpScannersFiltersTagsPermissions && (
<MenuSection>
{capabilities.mayAccess('scanners') && (
<MenuEntry title={_('Scanners')} to="scanners" />
)}
{capabilities.mayAccess('filters') && (
<MenuEntry title={_('Filters')} to="filters" />
)}
{capabilities.mayAccess('tags') && (
<MenuEntry title={_('Tags')} to="tags" />
)}
{capabilities.mayAccess('permissions') && (
<MenuEntry title={_('Permissions')} to="permissions" />
)}
</MenuSection>
)}
</Menu>
)}
<Menu title={_('Extras')}>
Expand Down
14 changes: 13 additions & 1 deletion gsa/src/web/components/menu/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import Theme from 'web/utils/theme.js';

import Link from 'web/components/link/link.js';

import MenuSection from 'web/components/menu/menusection';

const StyledMenu = styled.li`
flex-grow: 1;
flex-shrink: 1;
Expand Down Expand Up @@ -114,13 +116,23 @@ const MenuList = styled.ul`
}
`;

const getFirstMenuEntry = child => {
// return menu entries without the MenuSection
if (child.type === MenuSection) {
return React.Children.toArray(child.props.children).find(chil => !!chil);
}
return child;
};

const Menu = ({children, title, to, ...props}) => {
let link;
children = React.Children.toArray(children).filter(hasValue);

if (isDefined(to)) {
link = <Link to={to}>{title}</Link>;
} else if (isDefined(children) && children.length > 0) {
const [child] = children;
let [child] = children;
child = getFirstMenuEntry(child);
link = React.cloneElement(child, {title});
}

Expand Down

0 comments on commit fc014db

Please sign in to comment.