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] Validate page and perPage parameters in find APIs #161111

Merged
merged 8 commits into from
Jul 5, 2023

Conversation

adcoelho
Copy link
Contributor

@adcoelho adcoelho commented Jul 3, 2023

Connected to #146945

Summary

Description Limit Done? Documented?
Total number of cases/user actions/comments per page 100 No
Maximum number of cases/user actions/comments returned from the API 10.000 No

Checklist

Delete any items that are not applicable to this PR.

Release Notes

Max value for perPage parameter in find Cases API is now 100.
Max value for perPage parameter in find User Actions API is now 100.
Max value for perPage parameter in find Comments API is now 100.

@adcoelho adcoelho added release_note:breaking Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:Cases Cases feature v8.10.0 labels Jul 3, 2023
@adcoelho adcoelho self-assigned this Jul 3, 2023
@adcoelho adcoelho changed the title [Cases] Validate page and perPage in find APIs [Cases] Validate page and perPage parameters in find APIs Jul 3, 2023
@adcoelho adcoelho marked this pull request as ready for review July 3, 2023 18:46
@adcoelho adcoelho requested review from a team as code owners July 3, 2023 18:46
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

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

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 job. I left some comments.

x-pack/plugins/cases/server/common/validators.ts Outdated Show resolved Hide resolved
x-pack/plugins/cases/common/api/cases/case.ts Outdated Show resolved Hide resolved
adcoelho added 3 commits July 4, 2023 14:36
Update pagination validation for find user actions.
Update pagination validation for find comments.
Added unit and e2e tests.
Updated the documentation.
Remove code validation for paginations.
Tests.
Copy link
Contributor

@lcawl lcawl left a comment

Choose a reason for hiding this comment

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

OAS LGTM, thanks!

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.

Nice 🚀!

`);
});

it(`fails when page * perPage > ${MAX_DOCS_PER_PAGE}`, () => {
Copy link
Member

Choose a reason for hiding this comment

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

I think this test is the same as the previous one. Probably you wanted to set the perPage to MAX_DOCS_PER_PAGE.

x-pack/plugins/cases/common/schema/index.test.ts Outdated Show resolved Hide resolved
`);
});

it('fails when page > maxPerPage', () => {
Copy link
Member

Choose a reason for hiding this comment

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

nit: fails when page -> fails when perPage

Copy link
Contributor Author

@adcoelho adcoelho Jul 5, 2023

Choose a reason for hiding this comment

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

This was actually right, the schema doesMath.max(pageAsNumber, pageAsNumber * perPageAsNumber) > MAX_DOCS_PER_PAGE so here I am testing the first half of the Math.max.

Copy link
Member

Choose a reason for hiding this comment

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

You pass decode({ perPage: 4 }))) so I think it tests the perPage and not the page.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, that is the mistake though :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was looking at the similar named test fails when page > ${MAX_DOCS_PER_PAGE}

Copy link
Member

@cnasikas cnasikas Jul 5, 2023

Choose a reason for hiding this comment

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

ah, that is the mistake though :D

Depends on the angle you are looking at it hahahaha

`);
});

it.skip('fails when page number is negative', () => {
Copy link
Member

Choose a reason for hiding this comment

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

We should unskip the tests, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wrote the tests before the feature so I skipped them. But I didn't implement this validation yet 😅

Maybe I'll delete and do it in a different PR.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I thought it was part of this PR. We can leave them as it is and unskip them when you add the new validation.

const PageTypeRt = rt.union([rt.number, NumberFromString]);
type PageNumberType = rt.TypeOf<typeof PageTypeRt>;

export interface PaginationType {
Copy link
Member

Choose a reason for hiding this comment

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

nit: I found the Type at the end a bit redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I don't export this one we get a typescript error everywhere we use the paginationSchema.

Exported variable '<whatever>' has or is using name 'PaginationType' from external module "/Users/adcoelho/Development/kibana/x-pack/plugins/cases/common/schema/types" but cannot be named.

Copy link
Member

Choose a reason for hiding this comment

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

Exporting is fine. I think that the wording (naming of the type) is a bit confusing.

}

export const PaginationSchemaRt = rt.exact(rt.partial({ page: PageTypeRt, perPage: PageTypeRt }));
export type PartialPaginationType = Partial<PaginationType>;
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 Pagination?

Copy link
Contributor

@js-jankisalvi js-jankisalvi left a comment

Choose a reason for hiding this comment

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

looks good 👍

x-pack/plugins/cases/common/schema/index.test.ts Outdated Show resolved Hide resolved
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
cases 657 658 +1

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 26 27 +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 144.6KB 145.5KB +860.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
enterpriseSearch 14 16 +2
securitySolution 410 414 +4
total +6

Total ESLint disabled count

id before after diff
enterpriseSearch 15 17 +2
securitySolution 489 493 +4
total +6

History

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

cc @adcoelho

@adcoelho adcoelho merged commit f43601d into elastic:main Jul 5, 2023
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Jul 5, 2023
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:breaking Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants