mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Do not display anomalies tab without mlUserPermission (#45025)
This commit is contained in:
parent
426ebf0caa
commit
c7112d06a0
5 changed files with 164 additions and 86 deletions
|
@ -95,13 +95,14 @@ describe('Tab Navigation', () => {
|
|||
});
|
||||
|
||||
describe('Table Navigation', () => {
|
||||
const mockHasMlUserPermissions = true;
|
||||
const mockProps: TabNavigationProps & RouteSpyState = {
|
||||
pageName: 'hosts',
|
||||
pathName: '/hosts',
|
||||
detailName: undefined,
|
||||
search: '',
|
||||
tabName: HostsTableType.authentications,
|
||||
navTabs: navTabsHostDetails(hostName),
|
||||
navTabs: navTabsHostDetails(hostName, mockHasMlUserPermissions),
|
||||
[CONSTANTS.timerange]: {
|
||||
global: {
|
||||
[CONSTANTS.timerange]: {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
import { EuiHorizontalRule, EuiSpacer } from '@elastic/eui';
|
||||
import React from 'react';
|
||||
import React, { useContext } from 'react';
|
||||
import { compose } from 'redux';
|
||||
import { connect } from 'react-redux';
|
||||
import { StickyContainer } from 'react-sticky';
|
||||
|
@ -35,6 +35,8 @@ import { KpiHostsComponent } from '../../../components/page/hosts';
|
|||
|
||||
import { HostDetailsComponentProps } from './type';
|
||||
import { getFilterQuery, type, makeMapStateToProps } from './utils';
|
||||
import { MlCapabilitiesContext } from '../../../components/ml/permissions/ml_capabilities_provider';
|
||||
import { hasMlUserPermissions } from '../../../components/ml/permissions/has_ml_user_permissions';
|
||||
|
||||
export { HostDetailsBody } from './body';
|
||||
|
||||
|
@ -51,6 +53,7 @@ const HostDetailsComponent = React.memo<HostDetailsComponentProps>(
|
|||
setAbsoluteRangeDatePicker,
|
||||
to,
|
||||
}) => {
|
||||
const capabilities = useContext(MlCapabilitiesContext);
|
||||
return (
|
||||
<>
|
||||
<WithSource sourceId="default">
|
||||
|
@ -142,7 +145,7 @@ const HostDetailsComponent = React.memo<HostDetailsComponentProps>(
|
|||
|
||||
<EuiHorizontalRule />
|
||||
<SiemNavigation
|
||||
navTabs={navTabsHostDetails(detailName)}
|
||||
navTabs={navTabsHostDetails(detailName, hasMlUserPermissions(capabilities))}
|
||||
display="default"
|
||||
showBorder={true}
|
||||
/>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
import { EuiSpacer } from '@elastic/eui';
|
||||
import React from 'react';
|
||||
import React, { useContext } from 'react';
|
||||
import { compose } from 'redux';
|
||||
import { connect } from 'react-redux';
|
||||
import { StickyContainer } from 'react-sticky';
|
||||
|
@ -35,6 +35,8 @@ import {
|
|||
AnomaliesQueryTabBodyProps,
|
||||
HostsComponentsQueryProps,
|
||||
} from './hosts_navigations';
|
||||
import { hasMlUserPermissions } from '../../components/ml/permissions/has_ml_user_permissions';
|
||||
import { MlCapabilitiesContext } from '../../components/ml/permissions/ml_capabilities_provider';
|
||||
|
||||
const KpiHostsComponentManage = manageQuery(KpiHostsComponent);
|
||||
|
||||
|
@ -61,6 +63,7 @@ export type HostsComponentProps = HostsComponentReduxProps &
|
|||
|
||||
const HostsComponent = React.memo<HostsComponentProps>(
|
||||
({ isInitializing, filterQuery, from, setAbsoluteRangeDatePicker, setQuery, to }) => {
|
||||
const capabilities = useContext(MlCapabilitiesContext);
|
||||
return (
|
||||
<>
|
||||
<WithSource sourceId="default">
|
||||
|
@ -107,7 +110,11 @@ const HostsComponent = React.memo<HostsComponentProps>(
|
|||
)}
|
||||
</KpiHostsQuery>
|
||||
<EuiSpacer />
|
||||
<SiemNavigation navTabs={navTabsHosts} display="default" showBorder={true} />
|
||||
<SiemNavigation
|
||||
navTabs={navTabsHosts(hasMlUserPermissions(capabilities))}
|
||||
display="default"
|
||||
showBorder={true}
|
||||
/>
|
||||
<EuiSpacer />
|
||||
</>
|
||||
</StickyContainer>
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { HostsTableType } from '../../store/hosts/model';
|
||||
import { navTabsHosts, navTabsHostDetails } from './hosts_navigations';
|
||||
|
||||
describe('navTabsHosts', () => {
|
||||
test('it should skip anomalies tab if without mlUserPermission', () => {
|
||||
const tabs = navTabsHosts(false);
|
||||
expect(tabs).toHaveProperty(HostsTableType.hosts);
|
||||
expect(tabs).toHaveProperty(HostsTableType.authentications);
|
||||
expect(tabs).toHaveProperty(HostsTableType.uncommonProcesses);
|
||||
expect(tabs).not.toHaveProperty(HostsTableType.anomalies);
|
||||
expect(tabs).toHaveProperty(HostsTableType.events);
|
||||
});
|
||||
|
||||
test('it should display anomalies tab if with mlUserPermission', () => {
|
||||
const tabs = navTabsHosts(true);
|
||||
expect(tabs).toHaveProperty(HostsTableType.hosts);
|
||||
expect(tabs).toHaveProperty(HostsTableType.authentications);
|
||||
expect(tabs).toHaveProperty(HostsTableType.uncommonProcesses);
|
||||
expect(tabs).toHaveProperty(HostsTableType.anomalies);
|
||||
expect(tabs).toHaveProperty(HostsTableType.events);
|
||||
});
|
||||
});
|
||||
|
||||
describe('navTabsHostDetails', () => {
|
||||
const mockHostName = 'mockHostName';
|
||||
test('it should skip anomalies tab if without mlUserPermission', () => {
|
||||
const tabs = navTabsHostDetails(mockHostName, false);
|
||||
expect(tabs).toHaveProperty(HostsTableType.authentications);
|
||||
expect(tabs).toHaveProperty(HostsTableType.uncommonProcesses);
|
||||
expect(tabs).not.toHaveProperty(HostsTableType.anomalies);
|
||||
expect(tabs).toHaveProperty(HostsTableType.events);
|
||||
});
|
||||
|
||||
test('it should display anomalies tab if with mlUserPermission', () => {
|
||||
const tabs = navTabsHostDetails(mockHostName, true);
|
||||
expect(tabs).toHaveProperty(HostsTableType.authentications);
|
||||
expect(tabs).toHaveProperty(HostsTableType.uncommonProcesses);
|
||||
expect(tabs).toHaveProperty(HostsTableType.anomalies);
|
||||
expect(tabs).toHaveProperty(HostsTableType.events);
|
||||
});
|
||||
});
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
import { StaticIndexPattern } from 'ui/index_patterns';
|
||||
import { getOr } from 'lodash/fp';
|
||||
import { getOr, omit } from 'lodash/fp';
|
||||
import React from 'react';
|
||||
import * as i18n from './translations';
|
||||
|
||||
|
@ -30,93 +30,113 @@ const getTabsOnHostDetailsUrl = (hostName: string, tabName: HostsTableType) => {
|
|||
return `#/hosts/${hostName}/${tabName}`;
|
||||
};
|
||||
|
||||
export type KeyHostsNavTab =
|
||||
| HostsTableType.hosts
|
||||
| HostsTableType.authentications
|
||||
| HostsTableType.uncommonProcesses
|
||||
| HostsTableType.anomalies
|
||||
| HostsTableType.events;
|
||||
type KeyHostsNavTabWithoutMlPermission = HostsTableType.hosts &
|
||||
HostsTableType.authentications &
|
||||
HostsTableType.uncommonProcesses &
|
||||
HostsTableType.events;
|
||||
|
||||
type KeyHostsNavTabWithMlPermission = KeyHostsNavTabWithoutMlPermission & HostsTableType.anomalies;
|
||||
|
||||
export type KeyHostsNavTab = KeyHostsNavTabWithoutMlPermission | KeyHostsNavTabWithMlPermission;
|
||||
|
||||
type KeyHostDetailsNavTabWithoutMlPermission = HostsTableType.authentications &
|
||||
HostsTableType.uncommonProcesses &
|
||||
HostsTableType.events;
|
||||
|
||||
type KeyHostDetailsNavTabWithMlPermission = KeyHostsNavTabWithoutMlPermission &
|
||||
HostsTableType.anomalies;
|
||||
|
||||
export type KeyHostDetailsNavTab =
|
||||
| HostsTableType.authentications
|
||||
| HostsTableType.uncommonProcesses
|
||||
| HostsTableType.anomalies
|
||||
| HostsTableType.events;
|
||||
| KeyHostDetailsNavTabWithoutMlPermission
|
||||
| KeyHostDetailsNavTabWithMlPermission;
|
||||
|
||||
export type HostsNavTab = Record<KeyHostsNavTab, NavTab>;
|
||||
|
||||
export const navTabsHosts: HostsNavTab = {
|
||||
[HostsTableType.hosts]: {
|
||||
id: HostsTableType.hosts,
|
||||
name: i18n.NAVIGATION_ALL_HOSTS_TITLE,
|
||||
href: getTabsOnHostsUrl(HostsTableType.hosts),
|
||||
disabled: false,
|
||||
urlKey: 'host',
|
||||
},
|
||||
[HostsTableType.authentications]: {
|
||||
id: HostsTableType.authentications,
|
||||
name: i18n.NAVIGATION_AUTHENTICATIONS_TITLE,
|
||||
href: getTabsOnHostsUrl(HostsTableType.authentications),
|
||||
disabled: false,
|
||||
urlKey: 'host',
|
||||
},
|
||||
[HostsTableType.uncommonProcesses]: {
|
||||
id: HostsTableType.uncommonProcesses,
|
||||
name: i18n.NAVIGATION_UNCOMMON_PROCESSES_TITLE,
|
||||
href: getTabsOnHostsUrl(HostsTableType.uncommonProcesses),
|
||||
disabled: false,
|
||||
urlKey: 'host',
|
||||
},
|
||||
[HostsTableType.anomalies]: {
|
||||
id: HostsTableType.anomalies,
|
||||
name: i18n.NAVIGATION_ANOMALIES_TITLE,
|
||||
href: getTabsOnHostsUrl(HostsTableType.anomalies),
|
||||
disabled: false,
|
||||
urlKey: 'host',
|
||||
},
|
||||
[HostsTableType.events]: {
|
||||
id: HostsTableType.events,
|
||||
name: i18n.NAVIGATION_EVENTS_TITLE,
|
||||
href: getTabsOnHostsUrl(HostsTableType.events),
|
||||
disabled: false,
|
||||
urlKey: 'host',
|
||||
},
|
||||
export const navTabsHosts = (hasMlUserPermissions: boolean): HostsNavTab => {
|
||||
const hostsNavTabs = {
|
||||
[HostsTableType.hosts]: {
|
||||
id: HostsTableType.hosts,
|
||||
name: i18n.NAVIGATION_ALL_HOSTS_TITLE,
|
||||
href: getTabsOnHostsUrl(HostsTableType.hosts),
|
||||
disabled: false,
|
||||
urlKey: 'host',
|
||||
},
|
||||
[HostsTableType.authentications]: {
|
||||
id: HostsTableType.authentications,
|
||||
name: i18n.NAVIGATION_AUTHENTICATIONS_TITLE,
|
||||
href: getTabsOnHostsUrl(HostsTableType.authentications),
|
||||
disabled: false,
|
||||
urlKey: 'host',
|
||||
},
|
||||
[HostsTableType.uncommonProcesses]: {
|
||||
id: HostsTableType.uncommonProcesses,
|
||||
name: i18n.NAVIGATION_UNCOMMON_PROCESSES_TITLE,
|
||||
href: getTabsOnHostsUrl(HostsTableType.uncommonProcesses),
|
||||
disabled: false,
|
||||
urlKey: 'host',
|
||||
},
|
||||
[HostsTableType.anomalies]: {
|
||||
id: HostsTableType.anomalies,
|
||||
name: i18n.NAVIGATION_ANOMALIES_TITLE,
|
||||
href: getTabsOnHostsUrl(HostsTableType.anomalies),
|
||||
disabled: false,
|
||||
urlKey: 'host',
|
||||
},
|
||||
[HostsTableType.events]: {
|
||||
id: HostsTableType.events,
|
||||
name: i18n.NAVIGATION_EVENTS_TITLE,
|
||||
href: getTabsOnHostsUrl(HostsTableType.events),
|
||||
disabled: false,
|
||||
urlKey: 'host',
|
||||
},
|
||||
};
|
||||
|
||||
return hasMlUserPermissions ? hostsNavTabs : omit([HostsTableType.anomalies], hostsNavTabs);
|
||||
};
|
||||
|
||||
export const navTabsHostDetails = (hostName: string): Record<KeyHostDetailsNavTab, NavTab> => ({
|
||||
[HostsTableType.authentications]: {
|
||||
id: HostsTableType.authentications,
|
||||
name: i18n.NAVIGATION_AUTHENTICATIONS_TITLE,
|
||||
href: getTabsOnHostDetailsUrl(hostName, HostsTableType.authentications),
|
||||
disabled: false,
|
||||
urlKey: 'host',
|
||||
isDetailPage: true,
|
||||
},
|
||||
[HostsTableType.uncommonProcesses]: {
|
||||
id: HostsTableType.uncommonProcesses,
|
||||
name: i18n.NAVIGATION_UNCOMMON_PROCESSES_TITLE,
|
||||
href: getTabsOnHostDetailsUrl(hostName, HostsTableType.uncommonProcesses),
|
||||
disabled: false,
|
||||
urlKey: 'host',
|
||||
isDetailPage: true,
|
||||
},
|
||||
[HostsTableType.anomalies]: {
|
||||
id: HostsTableType.anomalies,
|
||||
name: i18n.NAVIGATION_ANOMALIES_TITLE,
|
||||
href: getTabsOnHostDetailsUrl(hostName, HostsTableType.anomalies),
|
||||
disabled: false,
|
||||
urlKey: 'host',
|
||||
isDetailPage: true,
|
||||
},
|
||||
[HostsTableType.events]: {
|
||||
id: HostsTableType.events,
|
||||
name: i18n.NAVIGATION_EVENTS_TITLE,
|
||||
href: getTabsOnHostDetailsUrl(hostName, HostsTableType.events),
|
||||
disabled: false,
|
||||
urlKey: 'host',
|
||||
isDetailPage: true,
|
||||
},
|
||||
});
|
||||
export const navTabsHostDetails = (
|
||||
hostName: string,
|
||||
hasMlUserPermissions: boolean
|
||||
): Record<KeyHostDetailsNavTab, NavTab> => {
|
||||
const hostDetailsNavTabs = {
|
||||
[HostsTableType.authentications]: {
|
||||
id: HostsTableType.authentications,
|
||||
name: i18n.NAVIGATION_AUTHENTICATIONS_TITLE,
|
||||
href: getTabsOnHostDetailsUrl(hostName, HostsTableType.authentications),
|
||||
disabled: false,
|
||||
urlKey: 'host',
|
||||
isDetailPage: true,
|
||||
},
|
||||
[HostsTableType.uncommonProcesses]: {
|
||||
id: HostsTableType.uncommonProcesses,
|
||||
name: i18n.NAVIGATION_UNCOMMON_PROCESSES_TITLE,
|
||||
href: getTabsOnHostDetailsUrl(hostName, HostsTableType.uncommonProcesses),
|
||||
disabled: false,
|
||||
urlKey: 'host',
|
||||
isDetailPage: true,
|
||||
},
|
||||
[HostsTableType.anomalies]: {
|
||||
id: HostsTableType.anomalies,
|
||||
name: i18n.NAVIGATION_ANOMALIES_TITLE,
|
||||
href: getTabsOnHostDetailsUrl(hostName, HostsTableType.anomalies),
|
||||
disabled: false,
|
||||
urlKey: 'host',
|
||||
isDetailPage: true,
|
||||
},
|
||||
[HostsTableType.events]: {
|
||||
id: HostsTableType.events,
|
||||
name: i18n.NAVIGATION_EVENTS_TITLE,
|
||||
href: getTabsOnHostDetailsUrl(hostName, HostsTableType.events),
|
||||
disabled: false,
|
||||
urlKey: 'host',
|
||||
isDetailPage: true,
|
||||
},
|
||||
};
|
||||
|
||||
return hasMlUserPermissions
|
||||
? hostDetailsNavTabs
|
||||
: omit(HostsTableType.anomalies, hostDetailsNavTabs);
|
||||
};
|
||||
|
||||
interface OwnProps {
|
||||
type: hostsModel.HostsType;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue