mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
Fixed an error with missing uids in the cases detail page (#207228)
Fixes #206801 ## Summary When opening the case detail page we retrieve user profile info for the different case user actions. If the uid stored in ES is an empty string for any of these user actions, we get an error that looks like this:  ### Steps to reproduce/test (thanks @jcger ) 1. Create a user with the `system_indices_superuser` role 2. Create a case and assign a user to it 3. Get the ID of the assignment user action from the case above ``` GET .kibana_alerting_cases/_search { "query": { "bool": { "filter": [ { "term": { "type": "cases-user-actions" } }, { "term": { "cases-user-actions.type": "assignees" } }, { "nested": { "path": "references", "query": { "bool": { "filter": [ { "term": { "references.type": "cases" } }, { "term": { "references.id": "<case_id>" } } ] } } } } ] } } } ``` 4. Manually set the `uid` of the assignee to `""` ``` POST .kibana_alerting_cases/_update/<cases-user-actions-id> { "script": { "source": """ ctx._source["cases-user-actions"].payload.assignees[0].uid = ""; """ } } ``` After this PR the popup should **not** appear anymore.
This commit is contained in:
parent
27a26fae4b
commit
d8e5cbf67f
2 changed files with 70 additions and 7 deletions
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* 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 { createUserActionServiceMock } from '../../services/mocks';
|
||||
import { createMockClient } from '../metrics/test_utils/client';
|
||||
import { createCasesClientMockArgs } from '../mocks';
|
||||
import { getUsers } from './users';
|
||||
import { mockCases } from '../../mocks';
|
||||
import type { CaseResolveResponse } from '../../../common/types/api';
|
||||
import { getUserProfiles } from '../cases/utils';
|
||||
|
||||
jest.mock('../cases/utils');
|
||||
|
||||
const getUserProfilesMock = getUserProfiles as jest.Mock;
|
||||
|
||||
describe('getUsers', () => {
|
||||
const casesClient = createMockClient();
|
||||
|
||||
casesClient.cases.resolve.mockResolvedValue({
|
||||
case: mockCases[0].attributes,
|
||||
} as CaseResolveResponse);
|
||||
|
||||
const clientArgs = createCasesClientMockArgs();
|
||||
const userActionService = createUserActionServiceMock();
|
||||
|
||||
userActionService.getUsers.mockResolvedValue({
|
||||
participants: [
|
||||
{
|
||||
id: 'foo',
|
||||
owner: 'bar',
|
||||
user: { email: '', full_name: '', username: '', profile_uid: '' },
|
||||
},
|
||||
{
|
||||
id: 'foo',
|
||||
owner: 'bar',
|
||||
user: { email: '', full_name: '', username: '', profile_uid: 'some_profile_id' },
|
||||
},
|
||||
],
|
||||
assignedAndUnassignedUsers: new Set([]),
|
||||
});
|
||||
getUserProfilesMock.mockResolvedValue(new Map());
|
||||
clientArgs.services.userActionService = userActionService;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('removes empty uids from getUserProfiles call', async () => {
|
||||
await getUsers({ caseId: 'test-case' }, casesClient, clientArgs);
|
||||
|
||||
expect(getUserProfilesMock).toHaveBeenCalledWith(
|
||||
expect.any(Object),
|
||||
new Set(['some_profile_id']),
|
||||
expect.any(String)
|
||||
);
|
||||
});
|
||||
});
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { isString } from 'lodash';
|
||||
import { isEmpty, isString } from 'lodash';
|
||||
import type { UserProfileAvatarData, UserProfileWithAvatar } from '@kbn/user-profile-components';
|
||||
import type { GetCaseUsersResponse } from '../../../common/types/api';
|
||||
import { GetCaseUsersResponseRt } from '../../../common/types/api';
|
||||
|
@ -57,12 +57,14 @@ export const getUsers = async (
|
|||
const reporter = theCase.case.created_by;
|
||||
const reporterProfileIdAsArray = reporter.profile_uid != null ? [reporter.profile_uid] : [];
|
||||
|
||||
const userProfileUids = new Set([
|
||||
...assignedAndUnassignedUsers,
|
||||
...participantsUids,
|
||||
...assigneesUids,
|
||||
...reporterProfileIdAsArray,
|
||||
]);
|
||||
const userProfileUids = new Set(
|
||||
[
|
||||
...assignedAndUnassignedUsers,
|
||||
...participantsUids,
|
||||
...assigneesUids,
|
||||
...reporterProfileIdAsArray,
|
||||
].filter((uid) => !isEmpty(uid))
|
||||
);
|
||||
|
||||
const userProfiles = await getUserProfiles(securityStartPlugin, userProfileUids, 'avatar');
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue