Skip to content

Commit

Permalink
[Cases] RBAC on UI (#99478)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
cnasikas and kibanamachine authored May 14, 2021
1 parent e26de43 commit 2d8601b
Show file tree
Hide file tree
Showing 73 changed files with 610 additions and 434 deletions.
2 changes: 2 additions & 0 deletions x-pack/plugins/cases/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export const MAX_GENERATED_ALERTS_PER_SUB_CASE = 50;
/**
* This must be the same value that the security solution plugin uses to define the case kind when it registers the
* feature for the 7.13 migration only.
*
* This variable is being also used by test files and mocks.
*/
export const SECURITY_SOLUTION_OWNER = 'securitySolution';

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/common/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export interface ElasticUser {

export interface FetchCasesProps extends ApiProps {
queryParams?: QueryParams;
filterOptions?: FilterOptions;
filterOptions?: FilterOptions & { owner: string[] };
}

export interface ApiProps {
Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/cases/public/common/mock/test_providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { I18nProvider } from '@kbn/i18n/react';
import React from 'react';
import { BehaviorSubject } from 'rxjs';
import { ThemeProvider } from 'styled-components';
import { SECURITY_SOLUTION_OWNER } from '../../../common';
import { OwnerProvider } from '../../components/owner_context';
import {
createKibanaContextProviderMock,
createStartServicesMock,
Expand All @@ -29,7 +31,9 @@ const MockKibanaContextProvider = createKibanaContextProviderMock();
const TestProvidersComponent: React.FC<Props> = ({ children }) => (
<I18nProvider>
<MockKibanaContextProvider>
<ThemeProvider theme={() => ({ eui: euiDarkVars, darkMode: true })}>{children}</ThemeProvider>
<ThemeProvider theme={() => ({ eui: euiDarkVars, darkMode: true })}>
<OwnerProvider owner={[SECURITY_SOLUTION_OWNER]}>{children}</OwnerProvider>
</ThemeProvider>
</MockKibanaContextProvider>
</I18nProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { noop } from 'lodash/fp';
import { TestProviders } from '../../common/mock';
import { Router, routeData, mockHistory, mockLocation } from '../__mock__/router';

import { CommentRequest, CommentType } from '../../../common';
import { CommentRequest, CommentType, SECURITY_SOLUTION_OWNER } from '../../../common';
import { usePostComment } from '../../containers/use_post_comment';
import { AddComment, AddCommentRefObject } from '.';
import { CasesTimelineIntegrationProvider } from '../timeline_context';
Expand Down Expand Up @@ -44,7 +44,7 @@ const defaultPostComment = {
const sampleData: CommentRequest = {
comment: 'what a cool comment',
type: CommentType.user,
owner: 'securitySolution',
owner: SECURITY_SOLUTION_OWNER,
};

describe('AddComment ', () => {
Expand Down
7 changes: 4 additions & 3 deletions x-pack/plugins/cases/public/components/add_comment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Form, useForm, UseField, useFormData } from '../../common/shared_import
import * as i18n from './translations';
import { schema, AddCommentFormSchema } from './schema';
import { InsertTimeline } from '../insert_timeline';
import { useOwnerContext } from '../owner_context/use_owner_context';
const MySpinner = styled(EuiLoadingSpinner)`
position: absolute;
top: 50%;
Expand Down Expand Up @@ -47,6 +48,7 @@ export const AddComment = React.memo(
{ caseId, disabled, onCommentPosted, onCommentSaving, showLoading = true, subCaseId },
ref
) => {
const owner = useOwnerContext();
const { isLoading, postComment } = usePostComment();

const { form } = useForm<AddCommentFormSchema>({
Expand Down Expand Up @@ -78,14 +80,13 @@ export const AddComment = React.memo(
}
postComment({
caseId,
// TODO: get plugin name
data: { ...data, type: CommentType.user, owner: 'securitySolution' },
data: { ...data, type: CommentType.user, owner: owner[0] },
updateCase: onCommentPosted,
subCaseId,
});
reset();
}
}, [caseId, onCommentPosted, onCommentSaving, postComment, reset, submit, subCaseId]);
}, [submit, onCommentSaving, postComment, caseId, owner, onCommentPosted, subCaseId, reset]);

return (
<span id="add-comment-permLink">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { CasesTableFilters } from './table_filters';
import { EuiBasicTableOnChange } from './types';

import { CasesTable } from './table';

const ProgressLoader = styled(EuiProgress)`
${({ $isShow }: { $isShow: boolean }) =>
$isShow
Expand Down Expand Up @@ -79,6 +80,7 @@ export const AllCasesGeneric = React.memo<AllCasesGenericProps>(
userCanCrud,
}) => {
const { actionLicense } = useGetActionLicense();

const {
data,
dispatchUpdateCaseProperty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import '../../common/mock/match_media';
import { TestProviders } from '../../common/mock';
import { casesStatus, useGetCasesMockState, collectionCase } from '../../containers/mock';

import { CaseStatuses, CaseType, StatusAll } from '../../../common';
import { CaseStatuses, CaseType, SECURITY_SOLUTION_OWNER, StatusAll } from '../../../common';
import { getEmptyTagValue } from '../empty_value';
import { useDeleteCases } from '../../containers/use_delete_cases';
import { useGetCases } from '../../containers/use_get_cases';
Expand Down Expand Up @@ -53,6 +53,7 @@ describe('AllCasesGeneric', () => {
onClick: jest.fn(),
},
userCanCrud: true,
owner: [SECURITY_SOLUTION_OWNER],
};

const dispatchResetIsDeleted = jest.fn();
Expand Down Expand Up @@ -815,7 +816,7 @@ describe('AllCasesGeneric', () => {
},
},
id: '1',
owner: 'securitySolution',
owner: SECURITY_SOLUTION_OWNER,
status: 'open',
subCaseIds: [],
tags: ['coke', 'pepsi'],
Expand Down
10 changes: 8 additions & 2 deletions x-pack/plugins/cases/public/components/all_cases/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@
*/

import React from 'react';
import { Owner } from '../../types';
import { CaseDetailsHrefSchema, CasesNavigation } from '../links';
import { OwnerProvider } from '../owner_context';
import { AllCasesGeneric } from './all_cases_generic';
export interface AllCasesProps {
export interface AllCasesProps extends Owner {
caseDetailsNavigation: CasesNavigation<CaseDetailsHrefSchema, 'configurable'>; // if not passed, case name is not displayed as a link (Formerly dependant on isSelector)
configureCasesNavigation: CasesNavigation; // if not passed, header with nav is not displayed (Formerly dependant on isSelector)
createCaseNavigation: CasesNavigation;
userCanCrud: boolean;
}

export const AllCases: React.FC<AllCasesProps> = (props) => {
return <AllCasesGeneric {...props} />;
return (
<OwnerProvider owner={props.owner}>
<AllCasesGeneric {...props} />
</OwnerProvider>
);
};

// eslint-disable-next-line import/no-default-export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { mount } from 'enzyme';
import { AllCasesSelectorModal } from '.';
import { TestProviders } from '../../../common/mock';
import { AllCasesGeneric } from '../all_cases_generic';
import { SECURITY_SOLUTION_OWNER } from '../../../../common';

jest.mock('../../../methods');
jest.mock('../all_cases_generic');
Expand All @@ -20,6 +21,7 @@ const defaultProps = {
createCaseNavigation,
onRowClick,
userCanCrud: true,
owner: [SECURITY_SOLUTION_OWNER],
};
const updateCase = jest.fn();

Expand Down Expand Up @@ -59,7 +61,7 @@ describe('AllCasesSelectorModal', () => {
},
index: 'index-id',
alertId: 'alert-id',
owner: 'securitySolution',
owner: SECURITY_SOLUTION_OWNER,
},
disabledStatuses: [],
updateCase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import { Case, CaseStatuses, CommentRequestAlertType, SubCase } from '../../../.
import { CasesNavigation } from '../../links';
import * as i18n from '../../../common/translations';
import { AllCasesGeneric } from '../all_cases_generic';
import { Owner } from '../../../types';
import { OwnerProvider } from '../../owner_context';

export interface AllCasesSelectorModalProps {
export interface AllCasesSelectorModalProps extends Owner {
alertData?: Omit<CommentRequestAlertType, 'type'>;
createCaseNavigation: CasesNavigation;
disabledStatuses?: CaseStatuses[];
Expand All @@ -29,7 +31,7 @@ const Modal = styled(EuiModal)`
`}
`;

export const AllCasesSelectorModal: React.FC<AllCasesSelectorModalProps> = ({
const AllCasesSelectorModalComponent: React.FC<AllCasesSelectorModalProps> = ({
alertData,
createCaseNavigation,
disabledStatuses,
Expand Down Expand Up @@ -65,5 +67,13 @@ export const AllCasesSelectorModal: React.FC<AllCasesSelectorModalProps> = ({
</Modal>
) : null;
};

export const AllCasesSelectorModal: React.FC<AllCasesSelectorModalProps> = React.memo((props) => {
return (
<OwnerProvider owner={props.owner}>
<AllCasesSelectorModalComponent {...props} />
</OwnerProvider>
);
});
// eslint-disable-next-line import/no-default-export
export { AllCasesSelectorModal as default };
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { AssociationType, CommentType } from '../../../common';
import { AssociationType, CommentType, SECURITY_SOLUTION_OWNER } from '../../../common';
import { Comment } from '../../containers/types';

import { getManualAlertIdsWithNoRuleId } from './helpers';
Expand All @@ -28,7 +28,7 @@ const comments: Comment[] = [
updatedAt: null,
updatedBy: null,
version: 'WzQ3LDFc',
owner: 'securitySolution',
owner: SECURITY_SOLUTION_OWNER,
},
{
associationType: AssociationType.case,
Expand All @@ -47,7 +47,7 @@ const comments: Comment[] = [
updatedAt: null,
updatedBy: null,
version: 'WzQ3LDFc',
owner: 'securitySolution',
owner: SECURITY_SOLUTION_OWNER,
},
];

Expand Down
36 changes: 20 additions & 16 deletions x-pack/plugins/cases/public/components/case_view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { Ecs } from '../../../common';
import { CasesTimelineIntegration, CasesTimelineIntegrationProvider } from '../timeline_context';
import { useTimelineContext } from '../timeline_context/use_timeline_context';
import { CasesNavigation } from '../links';
import { OwnerProvider } from '../owner_context';

const gutterTimeline = '70px'; // seems to be a timeline reference from the original file
export interface CaseViewComponentProps {
Expand Down Expand Up @@ -450,6 +451,7 @@ export const CaseComponent = React.memo<CaseComponentProps>(
tags={caseData.tags}
onSubmit={onSubmitTags}
isLoading={isLoading && updateKey === 'tags'}
owner={[caseData.owner]}
/>
<EditConnector
caseFields={caseData.connector.fields}
Expand Down Expand Up @@ -509,22 +511,24 @@ export const CaseView = React.memo(
return (
data && (
<CasesTimelineIntegrationProvider timelineIntegration={timelineIntegration}>
<CaseComponent
allCasesNavigation={allCasesNavigation}
caseData={data}
caseDetailsNavigation={caseDetailsNavigation}
caseId={caseId}
configureCasesNavigation={configureCasesNavigation}
getCaseDetailHrefWithCommentId={getCaseDetailHrefWithCommentId}
fetchCase={fetchCase}
onComponentInitialized={onComponentInitialized}
ruleDetailsNavigation={ruleDetailsNavigation}
showAlertDetails={showAlertDetails}
subCaseId={subCaseId}
updateCase={updateCase}
useFetchAlertData={useFetchAlertData}
userCanCrud={userCanCrud}
/>
<OwnerProvider owner={[data.owner]}>
<CaseComponent
allCasesNavigation={allCasesNavigation}
caseData={data}
caseDetailsNavigation={caseDetailsNavigation}
caseId={caseId}
configureCasesNavigation={configureCasesNavigation}
getCaseDetailHrefWithCommentId={getCaseDetailHrefWithCommentId}
fetchCase={fetchCase}
onComponentInitialized={onComponentInitialized}
ruleDetailsNavigation={ruleDetailsNavigation}
showAlertDetails={showAlertDetails}
subCaseId={subCaseId}
updateCase={updateCase}
useFetchAlertData={useFetchAlertData}
userCanCrud={userCanCrud}
/>
</OwnerProvider>
</CasesTimelineIntegrationProvider>
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import React, { memo, useMemo } from 'react';
import { CasesNavigation, LinkButton } from '../links';

// TODO: Potentially move into links component?

export interface ConfigureCaseButtonProps {
configureCasesNavigation: CasesNavigation;
isDisabled: boolean;
Expand Down
Loading

0 comments on commit 2d8601b

Please sign in to comment.