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

[Cases] RBAC on UI #99478

Merged
merged 18 commits into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from 13 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
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
1 change: 1 addition & 0 deletions x-pack/plugins/cases/common/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export interface FilterOptions {
status: CaseStatusWithAllStatus;
tags: string[];
reporters: User[];
owner: string[];
onlyCollectionType?: boolean;
}

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,8 @@ import { CasesTableFilters } from './table_filters';
import { EuiBasicTableOnChange } from './types';

import { CasesTable } from './table';
import { useOwnerContext } from '../owner_context/use_owner_context';

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

const {
data,
dispatchUpdateCaseProperty,
Expand All @@ -90,7 +94,7 @@ export const AllCasesGeneric = React.memo<AllCasesGenericProps>(
setFilters,
setQueryParams,
setSelectedCases,
} = useGetCases();
} = useGetCases({ initialFilterOptions: { owner } });
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonathan-buttner @michaelolo24 Do you think is best for the useGetCases hook to use useOwnerContext instead of passing it as an argument?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you'll never call useGetCases without the context owner, then I say include it in the actual useGetCases call rather than passing it in, but if for some reason the owner can change from call to call, then pass it. There may be reasons I'm not thinking of, but that's how I work it out in my head


// Post Comment to Case
const { postComment, isLoading: isCommentUpdating } = usePostComment();
Expand Down Expand Up @@ -286,6 +290,7 @@ export const AllCasesGeneric = React.memo<AllCasesGenericProps>(
reporters: filterOptions.reporters,
tags: filterOptions.tags,
status: filterOptions.status,
owner: filterOptions.owner,
}}
setFilterRefetch={setFilterRefetch}
disabledStatuses={disabledStatuses}
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 @@ -815,7 +815,7 @@ describe('AllCasesGeneric', () => {
},
},
id: '1',
owner: 'securitySolution',
owner: SECURITY_SOLUTION_OWNER,
status: 'open',
subCaseIds: [],
tags: ['coke', 'pepsi'],
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 @@ -47,6 +47,7 @@ const defaultInitial = {
reporters: [],
status: StatusAll,
tags: [],
owner: [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of the same thing here. I figure when you're in a solution, everything listed here, but the owner will actually be modifiable by the user. You can just skip passing it through here and call it directly in the useGetTags and useGetReporters calls

};

const CasesTableFiltersComponent = ({
Expand All @@ -63,8 +64,8 @@ const CasesTableFiltersComponent = ({
);
const [search, setSearch] = useState(initial.search);
const [selectedTags, setSelectedTags] = useState(initial.tags);
const { tags, fetchTags } = useGetTags();
const { reporters, respReporters, fetchReporters } = useGetReporters();
const { tags, fetchTags } = useGetTags(initial.owner);
const { reporters, respReporters, fetchReporters } = useGetReporters(initial.owner);

const refetch = useCallback(() => {
fetchTags();
Expand Down
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