Skip to content

Commit

Permalink
[ResponseOps][Cases] User assignment (#140208)
Browse files Browse the repository at this point in the history
* [ResponseOps][Cases] Assign users on cases sidebar section (#138108)

* Add reusable user profile selector component

* Refactoring services, auth

* Adding suggest api and tests

* Move to package and add examples

* [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix'

* Working integration tests

* Switching suggest api tags

* Adding assignees field

* Adding tests for size and owner

* Add server side example

* CI Fixes

* Adding assignee integration tests

* fix tests

* Addd tests

* Starting user actions changes

* Adding api tag tests

* Addressing feedback

* Using lodash for array comparison logic and tests

* Fixing type error

* Create suggest query

* Adding assignees user action

* [ResponseOps][Cases] Refactoring client args and authentication (#137345)

* Refactoring services, auth

* Fixing type errors

* Adding assignees migration and tests

* Fixing types and added more tests

* Fixing cypress test

* Fixing test

* Add tests

* Add security as dependency and fix types

* Add bulk get profiles query

* Rename folder

* Addressed suggestions from code review

* Fix types

* Adding migration for assignees field and tests

* Adding comments and a few more tests

* Updating comments and spelling

* Revert security solution optional

* PR feedback

* Updated user avatar component

* Reduce size

* Make security required

* Fix tests

* Addressing feedback

* Do not retry suggestions

* Assign users to a case

* Restructure components

* Move assignees to case view

* Show assigned users

* Refactoring bulk get and display name

* Adding tests for user tooltip

* Adding tests

* Hovering and tests

* Fixing errors

* Some pr clean up

* Fixing tests and adding more

* Adding functional tests

* Fixing jest test failure

* Passing in current user profile

* Refactoring assignment with useEffect

* Fixing icon alignment and removal render bug

* Fixing type errors

* Fixing test errors

* Adding bulk get privs and tests

* Fixing popover tests

* Handling unknown users

* Adding tests for unknown users

* Adding wait for popover calls

* Addressing design feedback

* Addressing remaining feedback

* Refactoring css and name prop

* Refactoring popover

* Refactoring search component

* Addressing some feedback

* Adjusting sorting

* Fixing tests

* Fixing type error

* Fixing test error

* Fixing test errors

* Removing display name

Co-authored-by: Thom Heymann <[email protected]>
Co-authored-by: Jonathan Buttner <[email protected]>
Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Thom Heymann <[email protected]>
Co-authored-by: Jonathan Buttner <[email protected]>

* [ResponseOps][Cases] Add assignee user actions (#139392)

* Adding user actions for assignees

* Fixing merge issues

* Fixing test mock errors

* Fixing display name errors and themselves

* Fixing test for time being

* Addressing feedback

* Addressing comma and uniq feedback

* Using core getUserDisplayName

* Fixing import and removing flickering

* Fixing tests

Co-authored-by: Kibana Machine <[email protected]>

* Detect when user is typing

* Use select to tranform data

* [Cases] Assign users when creating a case (#139754)

* Init

* Render users

* Assign yourself

* Add tests

* Fix tests

* PR feedback

* [ResponseOps][Cases] Filter by assignees (#139441)

* Starting the filtering

* Rough draft working for assignees filtering

* Adding integration tests for new route

* Starting to write tests

* Fixing tests

* Cleaning up more tests

* Removing duplicate call for current user

* Fixing type errors and tests

* Adding tests for filtering

* Adding rbac tests

* Fixing translations

* Fixing api integration tests

* Fixing severity tests

* Really fixing arrays equal

* Fixing ml tests and refactoring find assignees

* Fixing cypress tests

* Fixing types

* Fix tests

* Addressing first round of feedback

* Reverting the recent cases changes

* Fixing tests

* Fixing more tests and types

* Allowing multi select

* Fixing attachment framework issue

* Addressing feedback

* Fixing type error

* Fixing tests

* Sort users and improve loading

* Fix ml security dependecies

* Fix permissions when fetching suggestions

* Fixing read permissions and suggest api

* Hiding assignee delete icon

* Hiding the assign yourself text when undefined

* Create page fixes

Co-authored-by: Christos Nasikas <[email protected]>
Co-authored-by: Thom Heymann <[email protected]>
Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Thom Heymann <[email protected]>
  • Loading branch information
5 people authored Sep 12, 2022
1 parent 31f337d commit e5cc558
Show file tree
Hide file tree
Showing 137 changed files with 5,000 additions and 1,184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

import { shallow } from 'enzyme';
import React from 'react';
import { UserProfile } from './user_profile';

import { UserProfilesPopover } from './user_profiles_popover';

const userProfiles = [
const userProfiles: UserProfile[] = [
{
uid: 'u_BOulL4QMPSyV9jg5lQI2JmCkUnokHTazBnet3xVHNv0_0',
enabled: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

import { mount } from 'enzyme';
import React from 'react';
import { UserProfile } from './user_profile';

import { UserProfilesSelectable } from './user_profiles_selectable';

const userProfiles = [
const userProfiles: UserProfile[] = [
{
uid: 'u_BOulL4QMPSyV9jg5lQI2JmCkUnokHTazBnet3xVHNv0_0',
enabled: true,
Expand Down
18 changes: 0 additions & 18 deletions x-pack/plugins/cases/common/api/cases/suggest_user_profiles.ts

This file was deleted.

13 changes: 8 additions & 5 deletions x-pack/plugins/cases/common/api/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@

import * as rt from 'io-ts';

export const UserRT = rt.type({
email: rt.union([rt.undefined, rt.null, rt.string]),
full_name: rt.union([rt.undefined, rt.null, rt.string]),
username: rt.union([rt.undefined, rt.null, rt.string]),
});
export const UserRT = rt.intersection([
rt.type({
email: rt.union([rt.undefined, rt.null, rt.string]),
full_name: rt.union([rt.undefined, rt.null, rt.string]),
username: rt.union([rt.undefined, rt.null, rt.string]),
}),
rt.partial({ profile_uid: rt.string }),
]);

export const UsersRt = rt.array(UserRT);

Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/cases/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,8 @@ export const PUSH_CASES_CAPABILITY = 'push_cases' as const;
*/

export const DEFAULT_USER_SIZE = 10;

/**
* Delays
*/
export const SEARCH_DEBOUNCE_MS = 500;
3 changes: 2 additions & 1 deletion x-pack/plugins/cases/common/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export interface FilterOptions {
severity: CaseSeverityWithAll;
status: CaseStatusWithAllStatus;
tags: string[];
assignees: string[];
reporters: User[];
owner: string[];
}
Expand Down Expand Up @@ -162,7 +163,7 @@ export interface FieldMappings {

export type UpdateKey = keyof Pick<
CasePatchRequest,
'connector' | 'description' | 'status' | 'tags' | 'title' | 'settings' | 'severity'
'connector' | 'description' | 'status' | 'tags' | 'title' | 'settings' | 'severity' | 'assignees'
>;

export interface UpdateByKey {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/cases/public/common/mock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*/

export * from './test_providers';
export * from './permissions';
69 changes: 69 additions & 0 deletions x-pack/plugins/cases/public/common/mock/permissions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { CasesCapabilities, CasesPermissions } from '../../containers/types';

export const allCasesPermissions = () => buildCasesPermissions();
export const noCasesPermissions = () =>
buildCasesPermissions({ read: false, create: false, update: false, delete: false, push: false });
export const readCasesPermissions = () =>
buildCasesPermissions({ read: true, create: false, update: false, delete: false, push: false });
export const noCreateCasesPermissions = () => buildCasesPermissions({ create: false });
export const noUpdateCasesPermissions = () => buildCasesPermissions({ update: false });
export const noPushCasesPermissions = () => buildCasesPermissions({ push: false });
export const noDeleteCasesPermissions = () => buildCasesPermissions({ delete: false });
export const writeCasesPermissions = () => buildCasesPermissions({ read: false });

export const buildCasesPermissions = (overrides: Partial<Omit<CasesPermissions, 'all'>> = {}) => {
const create = overrides.create ?? true;
const read = overrides.read ?? true;
const update = overrides.update ?? true;
const deletePermissions = overrides.delete ?? true;
const push = overrides.push ?? true;
const all = create && read && update && deletePermissions && push;

return {
all,
create,
read,
update,
delete: deletePermissions,
push,
};
};

export const allCasesCapabilities = () => buildCasesCapabilities();
export const noCasesCapabilities = () =>
buildCasesCapabilities({
create_cases: false,
read_cases: false,
update_cases: false,
delete_cases: false,
push_cases: false,
});
export const readCasesCapabilities = () =>
buildCasesCapabilities({
create_cases: false,
update_cases: false,
delete_cases: false,
push_cases: false,
});
export const writeCasesCapabilities = () => {
return buildCasesCapabilities({
read_cases: false,
});
};

export const buildCasesCapabilities = (overrides?: Partial<CasesCapabilities>) => {
return {
create_cases: overrides?.create_cases ?? true,
read_cases: overrides?.read_cases ?? true,
update_cases: overrides?.update_cases ?? true,
delete_cases: overrides?.delete_cases ?? true,
push_cases: overrides?.push_cases ?? true,
};
};
85 changes: 23 additions & 62 deletions x-pack/plugins/cases/public/common/mock/test_providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* 2.0.
*/

/* eslint-disable no-console */

import React from 'react';
import { euiDarkVars } from '@kbn/ui-theme';
import { I18nProvider } from '@kbn/i18n-react';
Expand All @@ -14,7 +16,7 @@ import { render as reactRender, RenderOptions, RenderResult } from '@testing-lib
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { SECURITY_SOLUTION_OWNER } from '../../../common/constants';
import { CasesCapabilities, CasesFeatures, CasesPermissions } from '../../../common/ui/types';
import { CasesFeatures, CasesPermissions } from '../../../common/ui/types';
import { CasesProvider } from '../../components/cases_context';
import {
createKibanaContextProviderMock,
Expand All @@ -25,6 +27,7 @@ import { StartServices } from '../../types';
import { ReleasePhase } from '../../components/types';
import { ExternalReferenceAttachmentTypeRegistry } from '../../client/attachment_framework/external_reference_registry';
import { PersistableStateAttachmentTypeRegistry } from '../../client/attachment_framework/persistable_state_registry';
import { allCasesPermissions } from './permissions';

interface TestProviderProps {
children: React.ReactNode;
Expand Down Expand Up @@ -56,6 +59,11 @@ const TestProvidersComponent: React.FC<TestProviderProps> = ({
retry: false,
},
},
logger: {
log: console.log,
warn: console.warn,
error: () => {},
},
});

return (
Expand Down Expand Up @@ -98,69 +106,17 @@ export const testQueryClient = new QueryClient({
retry: false,
},
},
/**
* React query prints the errors in the console even though
* all tests are passings. We turn them off for testing.
*/
logger: {
log: console.log,
warn: console.warn,
error: () => {},
},
});

export const allCasesPermissions = () => buildCasesPermissions();
export const noCasesPermissions = () =>
buildCasesPermissions({ read: false, create: false, update: false, delete: false, push: false });
export const readCasesPermissions = () =>
buildCasesPermissions({ read: true, create: false, update: false, delete: false, push: false });
export const noCreateCasesPermissions = () => buildCasesPermissions({ create: false });
export const noUpdateCasesPermissions = () => buildCasesPermissions({ update: false });
export const noPushCasesPermissions = () => buildCasesPermissions({ push: false });
export const noDeleteCasesPermissions = () => buildCasesPermissions({ delete: false });
export const writeCasesPermissions = () => buildCasesPermissions({ read: false });

export const buildCasesPermissions = (overrides: Partial<Omit<CasesPermissions, 'all'>> = {}) => {
const create = overrides.create ?? true;
const read = overrides.read ?? true;
const update = overrides.update ?? true;
const deletePermissions = overrides.delete ?? true;
const push = overrides.push ?? true;
const all = create && read && update && deletePermissions && push;

return {
all,
create,
read,
update,
delete: deletePermissions,
push,
};
};

export const allCasesCapabilities = () => buildCasesCapabilities();
export const noCasesCapabilities = () =>
buildCasesCapabilities({
create_cases: false,
read_cases: false,
update_cases: false,
delete_cases: false,
push_cases: false,
});
export const readCasesCapabilities = () =>
buildCasesCapabilities({
create_cases: false,
update_cases: false,
delete_cases: false,
push_cases: false,
});
export const writeCasesCapabilities = () => {
return buildCasesCapabilities({
read_cases: false,
});
};

export const buildCasesCapabilities = (overrides?: Partial<CasesCapabilities>) => {
return {
create_cases: overrides?.create_cases ?? true,
read_cases: overrides?.read_cases ?? true,
update_cases: overrides?.update_cases ?? true,
delete_cases: overrides?.delete_cases ?? true,
push_cases: overrides?.push_cases ?? true,
};
};

export const createAppMockRenderer = ({
features,
owner = [SECURITY_SOLUTION_OWNER],
Expand All @@ -176,6 +132,11 @@ export const createAppMockRenderer = ({
retry: false,
},
},
logger: {
log: console.log,
warn: console.warn,
error: () => {},
},
});

const AppWrapper: React.FC<{ children: React.ReactElement }> = ({ children }) => (
Expand Down
Loading

0 comments on commit e5cc558

Please sign in to comment.