Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu permissions #1207

Merged
merged 2 commits into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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