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] Create internal API to filter cases by custom fields #170297

Merged
merged 36 commits into from
Nov 15, 2023

Conversation

js-jankisalvi
Copy link
Contributor

@js-jankisalvi js-jankisalvi commented Nov 1, 2023

Summary

Implements #167740

This PR

  • creates a new search_cases internal route with POST
  • allows to filter by customFields (currently only toggle custom fields can be filtered)
  • adds unit and integration tests

example of search cases body:

{ "customFields": { "custom_field_key": [true] } }

Checklist

For maintainers

@js-jankisalvi js-jankisalvi added Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:Cases Cases feature v8.12.0 labels Nov 1, 2023
@js-jankisalvi js-jankisalvi self-assigned this Nov 1, 2023
@js-jankisalvi js-jankisalvi added release_note:skip Skip the PR/issue when compiling release notes release_note:feature Makes this part of the condensed release notes and removed release_note:skip Skip the PR/issue when compiling release notes release_note:feature Makes this part of the condensed release notes labels Nov 8, 2023
@js-jankisalvi js-jankisalvi marked this pull request as ready for review November 8, 2023 16:34
@js-jankisalvi js-jankisalvi requested a review from a team as a code owner November 8, 2023 16:34
@elasticmachine
Copy link
Contributor

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

Copy link
Contributor

@adcoelho adcoelho left a comment

Choose a reason for hiding this comment

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

lgtm!

Also played around a bit in Kibana to check _find's behavior wasn't affected. It was fine 👍

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.

Great work! I really like the abstraction with the mapping 🚀. I left some comments.

x-pack/plugins/cases/server/client/cases/search.ts Outdated Show resolved Hide resolved
x-pack/plugins/cases/server/client/cases/validators.ts Outdated Show resolved Hide resolved
x-pack/plugins/cases/server/client/utils.ts Outdated Show resolved Hide resolved
x-pack/plugins/cases/server/client/utils.ts Outdated Show resolved Hide resolved
x-pack/plugins/cases/server/custom_fields/factory.ts Outdated Show resolved Hide resolved
x-pack/plugins/cases/server/client/cases/validators.ts Outdated Show resolved Hide resolved
@cnasikas cnasikas changed the title [Cases] update find api to support filtering of custom fields [Cases] Create internal API to filter cases by custom fields. Nov 13, 2023
@cnasikas cnasikas changed the title [Cases] Create internal API to filter cases by custom fields. [Cases] Create internal API to filter cases by custom fields Nov 13, 2023
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.

Great work @js-jankisalvi 🚀 ! Thank you for your patience with the review.

Comment on lines 75 to 83
if (!paramArgs.owner || !paramArgs.owner.length) {
throw Boom.badRequest('In order to filter cases by customFields, you must provide owner.');
}

if (isArray(paramArgs.owner) && paramArgs.owner.length > 1) {
throw Boom.badRequest(
'In order to filter cases by customFields, you must provide only one owner.'
);
}
Copy link
Member

Choose a reason for hiding this comment

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

What do you think of combining the two messages?

if (isArray(paramArgs.owner) && paramArgs.owner.length > 1) {
        throw Boom.badRequest(
          'Owner must be provided. Multiple owners are not supported.'
        );
      }

* throw error if request body does not have owner
*/
if (!Object.hasOwn(options, 'owner')) {
throw Boom.badRequest('Search cases must have a valid owner.');
Copy link
Member

Choose a reason for hiding this comment

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

nit: What about Owner is required.

@js-jankisalvi js-jankisalvi enabled auto-merge (squash) November 14, 2023 16:52
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Serverless Security Cypress Tests #4 / Use Value list in exception entry Should use value list in exception entry, and validate deleting value list prompt Should use value list in exception entry, and validate deleting value list prompt

Metrics [docs]

Page load bundle

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

id before after diff
cases 155.4KB 155.5KB +131.0B

History

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

cc @js-jankisalvi

@js-jankisalvi js-jankisalvi merged commit d4b5113 into elastic:main Nov 15, 2023
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Nov 15, 2023
@js-jankisalvi js-jankisalvi deleted the filter-custom-fields-api branch January 24, 2024 11:25
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 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.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Cases] Custom fields: Support filtering in APIs
6 participants