Skip to content

Commit

Permalink
Merge branch '7.7' into backport/7.7/pr-61641
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Mar 31, 2020
2 parents 294c5ce + c4e18a8 commit c3c3940
Show file tree
Hide file tree
Showing 177 changed files with 2,213 additions and 766 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,22 @@ describe('filter manager utilities', () => {
expect(compareFilters([f1], [f2], COMPARE_ALL_OPTIONS)).toBeTruthy();
});

test('should compare alias with alias true', () => {
const f1 = {
$state: { store: FilterStateStore.GLOBAL_STATE },
...buildQueryFilter({ _type: { match: { query: 'apache', type: 'phrase' } } }, 'index', ''),
};
const f2 = {
$state: { store: FilterStateStore.GLOBAL_STATE },
...buildQueryFilter({ _type: { match: { query: 'apache', type: 'phrase' } } }, 'index', ''),
};

f2.meta.alias = 'wassup';
f2.meta.alias = 'dog';

expect(compareFilters([f1], [f2], { alias: true })).toBeFalsy();
});

test('should compare alias with COMPARE_ALL_OPTIONS', () => {
const f1 = {
$state: { store: FilterStateStore.GLOBAL_STATE },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const mapFilter = (

if (comparators.negate) cleaned.negate = filter.meta && Boolean(filter.meta.negate);
if (comparators.disabled) cleaned.disabled = filter.meta && Boolean(filter.meta.disabled);
if (comparators.disabled) cleaned.alias = filter.meta?.alias;
if (comparators.alias) cleaned.alias = filter.meta?.alias;

return cleaned;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const FilterPopoverComponent = ({
numFilters={options.length}
hasActiveFilters={selectedOptions.length > 0}
numActiveFilters={selectedOptions.length}
aria-label={buttonLabel}
>
{buttonLabel}
</EuiFilterButton>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,18 @@ const MySpinner = styled(EuiLoadingSpinner)`
`;

interface Props {
disabled?: boolean;
isLoading: boolean;
title: string | React.ReactNode;
onSubmit: (title: string) => void;
}

const EditableTitleComponent: React.FC<Props> = ({ onSubmit, isLoading, title }) => {
const EditableTitleComponent: React.FC<Props> = ({
disabled = false,
onSubmit,
isLoading,
title,
}) => {
const [editMode, setEditMode] = useState(false);
const [changedTitle, onTitleChange] = useState<string>(typeof title === 'string' ? title : '');

Expand Down Expand Up @@ -104,6 +110,7 @@ const EditableTitleComponent: React.FC<Props> = ({ onSubmit, isLoading, title })
{isLoading && <MySpinner />}
{!isLoading && (
<MyEuiButtonIcon
isDisabled={disabled}
aria-label={i18n.EDIT_TITLE_ARIA(title as string)}
iconType="pencil"
onClick={onClickEditIcon}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion x-pack/legacy/plugins/siem/public/components/link_icon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface LinkProps {
href?: string;
iconSide?: 'left' | 'right';
onClick?: Function;
ariaLabel?: string;
}

const Link = styled(({ iconSide, children, ...rest }) => <EuiLink {...rest}>{children}</EuiLink>)<
Expand Down Expand Up @@ -52,14 +53,25 @@ export interface LinkIconProps extends LinkProps {
}

export const LinkIcon = React.memo<LinkIconProps>(
({ children, color, disabled, href, iconSide = 'left', iconSize = 's', iconType, onClick }) => (
({
children,
color,
disabled,
href,
iconSide = 'left',
iconSize = 's',
iconType,
onClick,
ariaLabel,
}) => (
<Link
className="siemLinkIcon"
color={color}
disabled={disabled}
href={href}
iconSide={iconSide}
onClick={onClick}
aria-label={ariaLabel ?? children}
>
<EuiIcon size={iconSize} type={iconType} />
<span className="siemLinkIcon__label">{children}</span>
Expand Down
13 changes: 8 additions & 5 deletions x-pack/legacy/plugins/siem/public/components/links/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import {
import { FlowTarget, FlowTargetSourceDest } from '../../graphql/types';
import { useUiSetting$ } from '../../lib/kibana';
import { IP_REPUTATION_LINKS_SETTING } from '../../../common/constants';
import * as i18n from '../page/network/ip_overview/translations';
import { isUrlInvalid } from '../../pages/detection_engine/rules/components/step_about_rule/helpers';
import { ExternalLinkIcon } from '../external_link_icon';
import { navTabs } from '../../pages/home/home_navigations';
import { useGetUrlSearch } from '../navigation/use_get_url_search';

import * as i18n from './translations';

export const DEFAULT_NUMBER_OF_LINK = 5;

// Internal Links
Expand Down Expand Up @@ -88,16 +89,18 @@ const IPDetailsLinkComponent: React.FC<{

export const IPDetailsLink = React.memo(IPDetailsLinkComponent);

const CaseDetailsLinkComponent: React.FC<{ children?: React.ReactNode; detailName: string }> = ({
children,
detailName,
}) => {
const CaseDetailsLinkComponent: React.FC<{
children?: React.ReactNode;
detailName: string;
title?: string;
}> = ({ children, detailName, title }) => {
const search = useGetUrlSearch(navTabs.case);

return (
<EuiLink
href={getCaseDetailsUrl({ id: detailName, search })}
data-test-subj="case-details-link"
aria-label={i18n.CASE_DETAILS_LINK_ARIA(title ?? detailName)}
>
{children ? children : detailName}
</EuiLink>
Expand Down
15 changes: 15 additions & 0 deletions x-pack/legacy/plugins/siem/public/components/links/translations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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 { i18n } from '@kbn/i18n';

export * from '../page/network/ip_overview/translations';

export const CASE_DETAILS_LINK_ARIA = (detailName: string) =>
i18n.translate('xpack.siem.case.caseTable.caseDetailsLinkAria', {
values: { detailName },
defaultMessage: 'click to visit case with title {detailName}',
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const useInsertTimeline = <T extends FormData>(form: FormHook<T>, fieldNa
});
const handleOnTimelineChange = useCallback(
(title: string, id: string | null) => {
const builtLink = `${basePath}/app/siem#/timelines?timeline=(id:${id},isOpen:!t)`;
const builtLink = `${basePath}/app/siem#/timelines?timeline=(id:'${id}',isOpen:!t)`;
const currentValue = form.getFormData()[fieldName];
const newValue: string = [
currentValue.slice(0, cursorPosition.start),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const Popover = React.memo<UtilityBarActionProps>(

return (
<EuiPopover
ownFocus
button={
<LinkIcon
color={color}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/siem/public/containers/case/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const getCases = async ({
signal,
}: FetchCasesProps): Promise<AllCases> => {
const query = {
reporters: filterOptions.reporters.map(r => r.username),
reporters: filterOptions.reporters.map(r => r.username ?? '').filter(r => r !== ''),
tags: filterOptions.tags,
...(filterOptions.status !== '' ? { status: filterOptions.status } : {}),
...(filterOptions.search.length > 0 ? { search: filterOptions.search } : {}),
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/siem/public/containers/case/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export enum SortFieldCase {
export interface ElasticUser {
readonly email?: string | null;
readonly fullName?: string | null;
readonly username: string;
readonly username?: string | null;
}

export interface FetchCasesProps extends ApiProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { useCallback, useEffect, useState } from 'react';

import { isEmpty } from 'lodash/fp';
import { User } from '../../../../../../plugins/case/common/api';
import { errorToToaster, useStateToaster } from '../../components/toasters';
import { getReporters } from './api';
Expand Down Expand Up @@ -44,9 +45,12 @@ export const useGetReporters = (): UseGetReporters => {
});
try {
const response = await getReporters(abortCtrl.signal);
const myReporters = response
.map(r => (r.full_name == null || isEmpty(r.full_name) ? r.username ?? '' : r.full_name))
.filter(u => !isEmpty(u));
if (!didCancel) {
setReporterState({
reporters: response.map(r => r.full_name ?? r.username ?? 'N/A'),
reporters: myReporters,
respReporters: response,
isLoading: false,
isError: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ const formatServiceRequestData = (myCase: Case): ServiceConnectorCaseParams => {
createdAt,
createdBy: {
fullName: createdBy.fullName ?? null,
username: createdBy?.username,
username: createdBy?.username ?? '',
},
comments: comments
.filter(c => {
Expand All @@ -168,14 +168,14 @@ const formatServiceRequestData = (myCase: Case): ServiceConnectorCaseParams => {
createdAt: c.createdAt,
createdBy: {
fullName: c.createdBy.fullName ?? null,
username: c.createdBy.username,
username: c.createdBy.username ?? '',
},
updatedAt: c.updatedAt,
updatedBy:
c.updatedBy != null
? {
fullName: c.updatedBy.fullName ?? null,
username: c.updatedBy.username,
username: c.updatedBy.username ?? '',
}
: null,
})),
Expand All @@ -187,7 +187,7 @@ const formatServiceRequestData = (myCase: Case): ServiceConnectorCaseParams => {
updatedBy != null
? {
fullName: updatedBy.fullName ?? null,
username: updatedBy.username,
username: updatedBy.username ?? '',
}
: null,
};
Expand Down
47 changes: 44 additions & 3 deletions x-pack/legacy/plugins/siem/public/lib/kibana/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,24 @@ export const useCurrentUser = (): AuthenticatedElasticUser | null => {
let didCancel = false;
const fetchData = async () => {
try {
const response = await security.authc.getCurrentUser();
if (!didCancel) {
setUser(convertToCamelCase<AuthenticatedUser, AuthenticatedElasticUser>(response));
if (security != null) {
const response = await security.authc.getCurrentUser();
if (!didCancel) {
setUser(convertToCamelCase<AuthenticatedUser, AuthenticatedElasticUser>(response));
}
} else {
setUser({
username: i18n.translate('xpack.siem.getCurrentUser.unknownUser', {
defaultMessage: 'Unknown',
}),
email: '',
fullName: '',
roles: [],
enabled: false,
authenticationRealm: { name: '', type: '' },
lookupRealm: { name: '', type: '' },
authenticationProvider: '',
});
}
} catch (error) {
if (!didCancel) {
Expand All @@ -81,3 +96,29 @@ export const useCurrentUser = (): AuthenticatedElasticUser | null => {
}, []);
return user;
};

export interface UseGetUserSavedObjectPermissions {
crud: boolean;
read: boolean;
}

export const useGetUserSavedObjectPermissions = () => {
const [
savedObjectsPermissions,
setSavedObjectsPermissions,
] = useState<UseGetUserSavedObjectPermissions | null>(null);
const uiCapabilities = useKibana().services.application.capabilities;

useEffect(() => {
const capabilitiesCanUserCRUD: boolean =
typeof uiCapabilities.siem.crud === 'boolean' ? uiCapabilities.siem.crud : false;
const capabilitiesCanUserRead: boolean =
typeof uiCapabilities.siem.show === 'boolean' ? uiCapabilities.siem.show : false;
setSavedObjectsPermissions({
crud: capabilitiesCanUserCRUD,
read: capabilitiesCanUserRead,
});
}, [uiCapabilities]);

return savedObjectsPermissions;
};
36 changes: 27 additions & 9 deletions x-pack/legacy/plugins/siem/public/pages/case/case.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,34 @@
import React from 'react';

import { WrapperPage } from '../../components/wrapper_page';
import { AllCases } from './components/all_cases';
import { useGetUserSavedObjectPermissions } from '../../lib/kibana';
import { SpyRoute } from '../../utils/route/spy_routes';
import { AllCases } from './components/all_cases';

import { getSavedObjectReadOnly, CaseCallOut } from './components/callout';
import { CaseSavedObjectNoPermissions } from './saved_object_no_permissions';

const infoReadSavedObject = getSavedObjectReadOnly();

export const CasesPage = React.memo(() => {
const userPermissions = useGetUserSavedObjectPermissions();

export const CasesPage = React.memo(() => (
<>
<WrapperPage>
<AllCases />
</WrapperPage>
<SpyRoute />
</>
));
return userPermissions == null || userPermissions?.read ? (
<>
<WrapperPage>
{userPermissions != null && !userPermissions?.crud && userPermissions?.read && (
<CaseCallOut
title={infoReadSavedObject.title}
message={infoReadSavedObject.description}
/>
)}
<AllCases userCanCrud={userPermissions?.crud ?? false} />
</WrapperPage>
<SpyRoute />
</>
) : (
<CaseSavedObjectNoPermissions />
);
});

CasesPage.displayName = 'CasesPage';
Loading

0 comments on commit c3c3940

Please sign in to comment.