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 MVP #167016

Merged
merged 50 commits into from
Oct 2, 2023
Merged

Conversation

js-jankisalvi
Copy link
Contributor

@js-jankisalvi js-jankisalvi commented Sep 22, 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 need 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:

Checklist

Delete any items that are not applicable to this PR.

For maintainers

Release notes

Allow users to configure custom fields in Cases. Supported field types: Text and Toggle. Coming soon: List, Number, Date, IP, Email, etc.

adcoelho and others added 14 commits August 21, 2023 14:26
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 `[]`.
## Summary

This was missing in my previous PR #165671
Following up on @js-jankisalvi work I changed the `customFields`
property in `CasesConfigure` to be the most basic possible.

Changes:
- We only accept `TextCustomField` and `ToggleCustomField` in the cases
configuration api.
- The custom field type used in the Cases domain and API types now comes
from the enum in `configure/v1`.
- Cases configuration POST requests now require the `customFields`
property
…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]>
…ic/kibana into cases-custom-fields-feature-branch
## Summary

This PR implements the following validation:

- **Custom field keys should be unique**
  - Where:
- `CaseConfigureService` -
x-pack/plugins/cases/server/services/configure/index.ts
      - `post`
      - `patch` 
  - Tests:
    - x-pack/plugins/cases/server/services/configure/index.test.ts
- **Limit custom fields to 5**
  - Where:
    - `ConfigurationRequestRt` (POST)
    - `ConfigurationPatchRequestRt`
    - `CasePostRequestRt` - done in a previous PR
    - `CasePatchRequestRt` - done in a previous PR
  - Tests:
    - x-pack/plugins/cases/server/client/configure/client.test.ts
    - x-pack/plugins/cases/common/types/api/configure/v1.test.ts
    - x-pack/plugins/cases/server/client/cases/create.test.ts
    - x-pack/plugins/cases/server/client/cases/update.test.ts
@js-jankisalvi js-jankisalvi added Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:Cases Cases feature release_note:feature Makes this part of the condensed release notes v8.11.0 labels Sep 22, 2023
@cnasikas cnasikas changed the title [Cases] Allow users to configure, add and update custom fields [Cases] Custom fields MVP Sep 22, 2023
adcoelho and others added 7 commits September 22, 2023 15:07
## Summary

This PR limits the length of the property value for `text` custom
fields.
## Summary

This PR implements the following validation:

- **Custom Field Keys need to exist in configuration when creating or
updating cases**
  - Where:
    - Cases Client
      - `create`
      - `update` 
  - Tests:
-
x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/patch_cases.ts
-
x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/post_case.ts

---------

Co-authored-by: kibanamachine <[email protected]>
## 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]>
## 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]>
## Summary

This PR checks for missing required custom fields in the create case
API.

(In my next PR I am thinking of moving `casesClient.configure.get({
owner: casePostRequest.owner });` outside of the validation functions.)
).toThrowErrorMatchingInlineSnapshot(`"Missing required custom fields: first_key"`);
});

it('throws if request sends a custom field that is not part of the configuration', () => {
Copy link
Member

Choose a reason for hiding this comment

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

I am wondering if this check exceeds the responsibility of the validation function which is to validate if required fields are present. The validateCustomFieldKeysAgainstConfiguration validates for fields that are not part of the configuration. Though they are not connected in this context and are tested in isolation (test in the create/update routes should ensure that both the validation functions are being called). Wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

you are right, I'll remove it from the validateRequiredCustomFields fn

@cnasikas
Copy link
Member

@elasticmachine merge upstream

@cnasikas cnasikas added the ci:skip-cypress-osquery Skips osquery cypress checks label Oct 1, 2023
@cnasikas
Copy link
Member

cnasikas commented Oct 1, 2023

@elasticmachine merge upstream

@cnasikas
Copy link
Member

cnasikas commented Oct 2, 2023

@elasticmachine merge upstream

@cnasikas
Copy link
Member

cnasikas commented Oct 2, 2023

buildkite test this

@cnasikas
Copy link
Member

cnasikas commented Oct 2, 2023

@elasticmachine merge upstream

@cnasikas
Copy link
Member

cnasikas commented Oct 2, 2023

Blocked by #167745

@cnasikas
Copy link
Member

cnasikas commented Oct 2, 2023

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

kibana-ci commented Oct 2, 2023

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #8 / core plugins rendering service exposes plugin config settings to authenticated users
  • [job] [logs] FTR Configs #8 / core plugins rendering service exposes plugin config settings to authenticated users

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
cases 671 700 +29

Async chunks

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

id before after diff
cases 423.2KB 441.7KB +18.5KB

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
cases 27 28 +1

Page load bundle

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

id before after diff
cases 152.1KB 155.1KB +3.0KB
Unknown metric groups

ESLint disabled line counts

id before after diff
cases 58 56 -2

Total ESLint disabled count

id before after diff
cases 74 72 -2

History

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

cc @adcoelho @cnasikas @js-jankisalvi

Copy link
Member

@cnasikas cnasikas left a comment

Choose a reason for hiding this comment

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

@js-jankisalvi @adcoelho @jcger Great work 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting ci:cloud-deploy Create or update a Cloud deployment ci:project-deploy-security Create a Security Serverless Project ci:skip-cypress-osquery Skips osquery cypress checks Feature:Cases Cases feature release_note:feature Makes this part of the condensed 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.

[Cases] Custom fields in Cases
10 participants