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 schema changes #167310

Conversation

cnasikas
Copy link
Member

@cnasikas cnasikas commented Sep 26, 2023

Summary

This PR:

  • Removes the field attribute from the schema of Cases
  • Changes the schema of the toggle from value: boolean[] to value: boolean
  • Allows cases to be created or updated with missing optional fields
  • Fills out missing custom fields with null values when creating or updating a case
  • Validate the key to contain only lowercase letters (a-z), numbers (0-9), '_', and '-'

Because the schema of the SO changed you need to start with a clean ES state.

Connected to #160236

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@cnasikas cnasikas added release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:Cases Cases feature v8.11.0 labels Sep 26, 2023
@cnasikas cnasikas self-assigned this Sep 26, 2023
@cnasikas cnasikas changed the base branch from main to cases-custom-fields-feature-branch September 26, 2023 16:26
@cnasikas cnasikas marked this pull request as ready for review September 27, 2023 14:24
@cnasikas cnasikas requested a review from a team as a code owner September 27, 2023 14:24
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

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

@kibana-ci
Copy link
Collaborator

kibana-ci commented Sep 28, 2023

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #25 / Cases Configure Closure options change closure option successfully
  • [job] [logs] FTR Configs #25 / Cases Configure Closure options change closure option successfully
  • [job] [logs] Cases Cypress Tests on Security Solution / Cases connector incident fields Correct incident fields show when connector is changed Correct incident fields show when connector is changed
  • [job] [logs] Cases Cypress Tests on Security Solution / Cases connector incident fields Correct incident fields show when connector is changed Correct incident fields show when connector is changed
  • [job] [logs] Serverless Security Explore Cypress Tests #1 / Cases connectors Configures a new connector Configures a new connector
  • [job] [logs] Cases Cypress Tests on Security Solution / Cases connectors Configures a new connector Configures a new connector
  • [job] [logs] Serverless Security Explore Cypress Tests #1 / Cases connectors Configures a new connector Configures a new connector
  • [job] [logs] Cases Cypress Tests on Security Solution / Cases connectors Configures a new connector Configures a new connector
  • [job] [logs] FTR Configs #65 / cases security and spaces enabled: basic Common import and export cases exports a case with its associated user actions and comments
  • [job] [logs] FTR Configs #65 / cases security and spaces enabled: basic Common import and export cases exports a case with its associated user actions and comments
  • [job] [logs] FTR Configs #4 / cases security and spaces enabled: trial Common import and export cases exports a case with its associated user actions and comments
  • [job] [logs] FTR Configs #4 / cases security and spaces enabled: trial Common import and export cases exports a case with its associated user actions and comments
  • [job] [logs] Jest Integration Tests #6 / checking migration metadata changes on all registered SO types detecting migration related changes in registered types
  • [job] [logs] Jest Integration Tests #2 / fleet usage telemetry should fetch usage telemetry
  • [job] [logs] FTR Configs #64 / serverless common UI Index Management Index Templates "before all" hook for "renders the index templates tab"
  • [job] [logs] FTR Configs #19 / Serverless observability API Cases get_case should return a case
  • [job] [logs] FTR Configs #19 / Serverless observability API Cases get_case should return a case
  • [job] [logs] FTR Configs #69 / Serverless security API Cases get_case should return a case
  • [job] [logs] FTR Configs #69 / Serverless security API Cases get_case should return a case

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
cases 444.8KB 444.7KB -102.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
cases 154.7KB 155.0KB +349.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @cnasikas

@cnasikas cnasikas mentioned this pull request Sep 28, 2023
11 tasks
key: limitedStringSchema({ fieldName: 'key', min: 1, max: MAX_CUSTOM_FIELD_KEY_LENGTH }),
key: regexStringRt({
codec: limitedStringSchema({ fieldName: 'key', min: 1, max: MAX_CUSTOM_FIELD_KEY_LENGTH }),
pattern: '^[a-z0-9_-]+$',
Copy link
Contributor

Choose a reason for hiding this comment

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

We could also have ^[a-z0-9_-]{1,MAX_CUSTOM_FIELD_KEY_LENGTH}$.

We don't do it so we can have more specific error messages?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was not aware of that! Let me try that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably have to escape the $ at the end though

[CustomFieldTypes.TEXT]: configureTextCustomFieldFactory,
[CustomFieldTypes.TOGGLE]: configureToggleCustomFieldFactory,
} as const);
} as const) as CustomFieldBuilderMap;
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the difference?

Copy link
Member Author

Choose a reason for hiding this comment

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

I made the types to accept template literals so we do not have to cast inside the View/Configure/Edit components. Without this cast, TS complains. I fought a lot of hours without success. I preferred to have this cast here and not have to cast in the components each time we add a new custom field type.

@cnasikas cnasikas mentioned this pull request Sep 28, 2023
4 tasks
@@ -153,3 +153,26 @@ export const limitedNumberSchema = ({ fieldName, min, max }: LimitedSchemaType)
}),
rt.identity
);

export interface RegexStringSchemaType {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: does this need to be exported? ctrl + f doesn't show other occurrences.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope!

}),
fieldName: 'value',
min: 0,
max: MAX_CUSTOM_FIELD_TEXT_VALUE_ITEMS,
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add a test for this?

});

it('returns missing keys', () => {
it('returns all custom fields if they are more than the configuration', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

At the point in which this function is called the validation is already done so this should never happen. Shouldn't we throw an error?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but the tests are for fillMissingCustomFields which is tested in isolation. There is no connection without validation in these tests. We need to test that the fillMissingCustomFields is working as expected in all scenarios because it may be used in a different context in the future.

/**
* Returns a list of required custom fields missing from the request
*/
export const validateRequiredCustomFields = ({
Copy link
Contributor

Choose a reason for hiding this comment

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

Wasn't this one already in my PR?

Copy link
Member Author

@cnasikas cnasikas Sep 28, 2023

Choose a reason for hiding this comment

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

No, I removed it because the requirements were different at that time. We changed our minds though and added again in this PR 🙂.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, I was really confused and went to check my old commits to see if I dreamt of this code 😆

Copy link
Member Author

Choose a reason for hiding this comment

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

😆 Check my latest commit in your PR.

},
],
}),
400
);
});

it('400s when trying to create case with a missing custom field', async () => {
it('400s when trying to create case with a required custom field', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: with a missing required custom field?

@cnasikas cnasikas merged commit 3d90a5a into elastic:cases-custom-fields-feature-branch Sep 28, 2023
@cnasikas cnasikas deleted the custom_fields_new_schema branch September 28, 2023 09:40
js-jankisalvi added a commit that referenced this pull request 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 release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.11.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants