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] Custom fields in Cases #160236

Closed
8 of 11 tasks
cnasikas opened this issue Jun 22, 2023 · 2 comments · Fixed by #167016
Closed
8 of 11 tasks

[Cases] Custom fields in Cases #160236

cnasikas opened this issue Jun 22, 2023 · 2 comments · Fixed by #167016
Assignees
Labels
Feature:Cases Cases feature Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams)

Comments

@cnasikas
Copy link
Member

cnasikas commented Jun 22, 2023

To aid users to classify and enrich their cases better we will provide the ability to create custom fields. Users will be able to configure their custom fields, add values, view them in the case view page and the cases table, and filter by them.

Schema

enum CustomFieldTypes {
  STRING = 'string',
  URL = 'url',
  LIST = 'list',
  BOOLEAN = 'boolean',
}

interface CustomField {
  key: string;
  label: string;
  defaultValue: string | null;
  required?: boolean;
  group_key?: string;
}

interface StringCustomField extends CustomField {
  type: CustomFieldTypes.TEXT;
  limit: number;
}

interface ListCustomField extends CustomField {
  type: CustomFieldTypes.LIST;
  options: string[];
  singleSelection: boolean;
}

Saved objects

The schema of the custom fields should be ZDT compatible. This means that we can only extend the schema by adding optional fields.

Configuration saved object

In the cases-configure saved object we will persist the configuration of the custom fields. Example:

[ { key: 'my_key', type: 'text', label: 'My test custom field', .... } ]

There is no need to index any of the fields so the mapping of the cases-configure saved object will remain as it is.

Cases saved object

In the cases saved object we will persist the values of the custom fields. Example:

[ { key: 'my_key', value: ['My value'] } ]
[ { key: 'my_key_2', value: ['My value 1', 'My value 2'] } ]

A value can be of multiple data types. It can be a string, an integer, a number, and a boolean. Strings can also have a special meaning like dates or IPs. Also, all values should be indexable so they can be filtered and used in aggregations. For these reasons, the mapping of the custom fields in the cases saved object will be:

{
  "mappings": {
    "properties": {
      "custom_fields": {
        "type": "nested",
        "properties": {
          "key": {
            "type": "keyword"
          },
          "value": {
            "type": "keyword",
            "fields": {
              "number": {
                "type": "long",
                "ignore_malformed": true
              },
              "boolean": {
                "type": "boolean",
                "ignore_malformed": true
              },
              "string": {
                "type": "text"
              },
              "date": {
                "type": "date",
                "ignore_malformed": true
              },
              "ip": {
                "type": "ip",
                "ignore_malformed": true
              }
            }
          }
        }
      }
    }
  }
}

The custom_fields property will be an array of key-value pairs. To allow the custom fields to be indexed in a way that they can be queried independently of each other we need to set the custom_fields property as nested.

In some scenarios, the value may need to be an object. For example in the case of the URL type. We need to persist the text and the link to be able to do <a href="{{my_link}}" >{{my_text}}</a>. At the same time, we want each value of the object to be indexable but avoid dynamic mapping which can lead to a field mapping explosion in the .kibana_alerts_cases index. To mitigate this issue and support objects, the object will be flattened and each attribute of the object will be one entry in the custom fields array. For example the { text: 'My text', link: 'https://example.com' } object will be persisted as

[
   { key: 'url.text', value: ['My text'] }, 
   { key: 'url.link', value: ['https://example.com'] } 
]

The url prefix in the key is the grouping key and can be defined when configuring the URL field type in the cases configuration page. The configuration for the URL would look like:

[ 
  { key: 'text', type: 'text', label: 'Text', group_key: 'url' } 
  { key: 'link', type: 'text', label: 'URL', group_key: 'url' }
]

Desing patter

We should follow the Factory pattern to create and view the custom fields in the server and in the UI, similar to what we do with the user actions. This will allow us to easily add more custom fields in the future.

Tasks

Related issue: #155380

@cnasikas cnasikas added Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:Cases Cases feature labels Jun 22, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops-cases (Feature:Cases)

@cnasikas cnasikas changed the title [Cases] Custom fields [Cases] Custom fields in Cases Jun 22, 2023
adcoelho added a commit that referenced this issue Sep 12, 2023
Connected with #160236

**Merging into a Feature Branch**

## Summary

This PR defines the `customField` in the Cases API and Domain types.

For now, we only allow the custom fields `string`, `boolean`, and
`list`.

This PR does not include the case configuration types.

The default value for the field is `[]`.
js-jankisalvi added a commit that referenced this issue Sep 20, 2023
…toggle field) (#166483)

## Summary

Connected to #160236


### Checklist

Delete any items that are not applicable to this PR.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [x] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))

### For maintainers

- [x] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Christos Nasikas <[email protected]>
js-jankisalvi added a commit that referenced this issue Sep 25, 2023
## Summary

This PR adds the ability to add custom fields in the create case form. 

**Testing**

Verify that you all custom fields from configuration are visible in
create case form
Verify that you can set your custom fields
Verify that it throws an error based on the configuration (required:
true | false)

Connected to #160236

**Create case**


https://github.com/elastic/kibana/assets/117571355/8b560804-ea1f-4313-a382-34a17c0750b7


### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Christos Nasikas <[email protected]>
js-jankisalvi added a commit that referenced this issue Sep 25, 2023
## Summary

Connected to #160236

This PR adds validation in UI to limit maximum number of custom fields
to 5 in configuration cases page


![image](https://github.com/elastic/kibana/assets/117571355/7cbb2dfb-bf13-498c-a4a1-1fddeefa4d46)

### Checklist

Delete any items that are not applicable to this PR.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <[email protected]>
js-jankisalvi added a commit that referenced this issue Sep 28, 2023
## Summary

This PR allows users to edit custom field configuration.


https://github.com/elastic/kibana/assets/117571355/efaf9a32-b0e2-4d72-89e9-2045c544af2b

connected to #160236
### Checklist

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <[email protected]>
adcoelho added a commit that referenced this issue Sep 28, 2023
## Summary

Change max custom fields per Case limit to 10.

Connected to #160236
adcoelho added a commit that referenced this issue Sep 28, 2023
## Summary

In this PR we prevent users from sending PATCH requests to the cases
configuration that change the type of a custom field.

Connected to #160236
jcger added a commit that referenced this issue Sep 29, 2023
### Description
In the prior implementation, users lacking a gold license were unable to
access the configure/settings page since all available options were
exclusively tied to the gold license. However, with this update, the
capability to incorporate custom actions into this page is extended to
basic license holders as well. This PR accomplishes this by hiding
sections that demand gold-level privileges from basic license users.

#### Now with Basic License:
<img width="897" alt="Screenshot 33"
src="https://github.com/elastic/kibana/assets/17549662/d9ec7d96-db77-4833-a7c7-e90617280b14">

#### Before with Basic License:
The Cases page was initially inaccessible due to the disabled Settings
button. However, it remained accessible via the URL, which displayed the
same page as it did for Gold users.
<img width="900" alt="Screenshot"
src="https://github.com/elastic/kibana/assets/17549662/be53227d-0089-4b7e-97a2-5f8033eec621">

### QA
#### Test that Basic License users only see Custom Fields section
1. Go to Cases > Settings
2. You shouldn't see any section but the Custom Fields

#### If you want to test that the callout doesn't show up for Basic
License users:
1. Go to Stack Management > License Management > Start Trial
2. Go to Cases > Settings 
4. Add a new connector in the External incident management system
section
5. Delete that connector in Stack Management > Connectors 
6. Check that in Cases > Settings a waning callout is shown now
7. Go to Stack Management > License Management > Revert to Basic
8. Check that in Cases > Settings the warning callout is not shown 

Connected to #160236
js-jankisalvi added a commit that referenced this issue Sep 29, 2023
## Summary

Connected to #160236

This PR fixes tests for custom field mvp feature

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: Christos Nasikas <[email protected]>
Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: adcoelho <[email protected]>
js-jankisalvi added a commit that referenced this issue Oct 2, 2023
## Summary

This PR implements an MPV for custom fields in Cases. Specifically:

- Users can add, delete, or edit custom fields from the configuration
page
- Users can set custom fields when creating a case
- Users can set custom fields when editing a case
- Only the `Text` custom field type is supported. The `Toggle` is
implemented to test the framework.
- Users with a basic license can enter the configuration page and set
custom fields
- The configuration page header changed to "Settings"
- The "Edit external connection" button changed to "Settings"
- APIs:
    - Users cannot post custom fields with duplicate keys
    - Users cannot change the type of the custom field
    - Users cannot add custom fields that are not configured
    - Required fields should be present
- If some of the custom fields are omitted from the request the backend
will fill them with `null` values
- Limits:
    - Maximum 10 custom fields configured
    - Maximum 50 chars in custom field labels
    - Maximum 160 chars for the value of the `Text` custom field type
    - Users cannot change the type of a custom field
- The key of the custom fields should contain only lowercase letters
(a-z), numbers (0-9), '_', and '-'
    - Required fields needs a value

## Testing
- Cases created before custom fields are working as expected (create
some on `main` before switching to the feature branch)
- Environments without configuration are working as expected (clear ES
data)
- Environments with existing configurations are working as expected
- Try to create cases with custom fields (required & optional) and
delete some of them
- Try to create cases with custom fields (required & optional) and then
configure new custom fields. Existing cases with old custom fields
should work as expected
- User actions are working as expected especially with the combinations
described in the previous two bullets
- Users with a basic license can configure custom fields but cannot
configure connectors
- Users with a gold+ license can configure custom fields and connectors
- Users with read access cannot configure or edit custom fields

Resolves: #160236

PRs:

- #165671
- #166353
- #166439
- #166483
- #166815
- #166940
- #166962
- #166969
- #166975
- #167029
- #167047
- #167105
- #167131
- #167144
- #167166
- #167167
- #167310
- #167386
- #167481
- #167495
- #167398
- #167472

### Checklist

Delete any items that are not applicable to this PR.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### For maintainers

- [x] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

## Release notes
Allow users to configure custom fields in Cases. Supported field types:
Text. Coming soon: Multi-text, List, Number, Toggle, Date, IP, Email,
etc.

---------

Co-authored-by: adcoelho <[email protected]>
Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Christos Nasikas <[email protected]>
Co-authored-by: Julian Gernun <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Cases Cases feature Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants