Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
126 changes: 126 additions & 0 deletions x-pack/plugins/cases/server/client/configure/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,132 @@ describe('client', () => {
'Failed to get patch configure in route: Error: The following custom fields have the wrong type in the request: "text label"'
);
});

it('removes deleted custom field from template correctly', async () => {
clientArgs.services.caseConfigureService.get.mockResolvedValue({
// @ts-ignore: these are all the attributes needed for the test
attributes: {
connector: {
id: 'none',
name: 'none',
type: ConnectorTypes.none,
fields: null,
},
customFields: [
{
key: 'custom_field_key_1',
label: 'text label',
type: CustomFieldTypes.TEXT,
required: false,
},
],
templates: [
{
key: 'template_1',
name: 'template 1',
description: 'this is test description',
caseFields: {
customFields: [
{
key: 'custom_field_key_1',
type: CustomFieldTypes.TEXT,
value: 'custom field value 1',
},
],
},
},
],
closure_type: 'close-by-user',
owner: 'cases',
},
id: 'test-id',
version: 'test-version',
});

await update(
'test-id',
{
version: 'test-version',
customFields: [],
templates: [
{
key: 'template_1',
name: 'template 1',
description: 'this is test description',
caseFields: {
customFields: [
{
key: 'custom_field_key_1',
type: CustomFieldTypes.TEXT,
value: 'updated value',
},
],
},
},
],
},
clientArgs,
casesClientInternal
);

expect(clientArgs.services.caseConfigureService.patch).toHaveBeenCalledWith({
configurationId: 'test-id',
originalConfiguration: {
attributes: {
closure_type: 'close-by-user',
connector: {
fields: null,
id: 'none',
name: 'none',
type: '.none',
},
customFields: [
{
key: 'custom_field_key_1',
label: 'text label',
required: false,
type: 'text',
},
],
owner: 'cases',
templates: [
{
caseFields: {
customFields: [
{
key: 'custom_field_key_1',
type: 'text',
value: 'custom field value 1',
},
],
},
description: 'this is test description',
key: 'template_1',
name: 'template 1',
},
],
},
id: 'test-id',
version: 'test-version',
},
unsecuredSavedObjectsClient: expect.anything(),
updatedAttributes: {
customFields: [],
templates: [
{
caseFields: {
customFields: [],
},
description: 'this is test description',
key: 'template_1',
name: 'template 1',
},
],
updated_at: expect.anything(),
updated_by: expect.anything(),
},
});
});
});

describe('assignees', () => {
Expand Down
9 changes: 7 additions & 2 deletions x-pack/plugins/cases/server/client/configure/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import type { CasesClientArgs } from '../types';
import { getMappings } from './get_mappings';

import { Operations } from '../../authorization';
import { combineAuthorizedAndOwnerFilter } from '../utils';
import { combineAuthorizedAndOwnerFilter, removeCustomFieldFromTemplates } from '../utils';
import type { MappingsArgs, CreateMappingsArgs, UpdateMappingsArgs } from './types';
import { createMappings } from './create_mappings';
import { updateMappings } from './update_mappings';
Expand Down Expand Up @@ -326,6 +326,11 @@ export async function update(
customFields: configuration.attributes.customFields,
});

const updatedTemplates = removeCustomFieldFromTemplates({
templates,
customFields: request.customFields,
});

await authorization.ensureAuthorized({
operation: Operations.updateConfiguration,
entities: [{ owner: configuration.attributes.owner, id: configuration.id }],
Expand Down Expand Up @@ -381,7 +386,7 @@ export async function update(
configurationId: configuration.id,
updatedAttributes: {
...queryWithoutVersionAndConnector,
...(templates && { templates }),
...(updatedTemplates && { templates: updatedTemplates }),
...(connector != null && { connector }),
updated_at: updateDate,
updated_by: user,
Expand Down
Loading