-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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] Total number of user actions on a case. #161848
Conversation
e85a59a
to
eba58af
Compare
}: BulkCreateBulkUpdateCaseUserActions): Promise<void> { | ||
const builtUserActions = updatedCases.reduce<UserActionEvent[]>((acc, updatedCase) => { | ||
const originalCase = originalCases.find(({ id }) => id === updatedCase.id); | ||
public buildUserActions({ updatedCases, user }: BuildUserActionsDictParams): UserActionsDict { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An UserActionsDict
is a dictionary where the key is the caseId
and the value is an array of all user actions to be created.
This will help us during the validation where we can check for each case independently if they will break the limit.
userActionsDict: UserActionsDict; | ||
userActionService: CaseUserActionService; | ||
}) { | ||
const result = await userActionService.getMultipleCasesUserActionsTotal({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do the aggregation for each case
being updated.
caseIds: Object.keys(userActionsDict), | ||
}); | ||
|
||
result.aggregations?.references.caseUserActions.buckets.forEach( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For each case check if the result of the aggregation + the user actions to be created is bigger than the max allowed value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean once reaching maximum limit user can't delete or update the existing comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job with splitting the logic of the creation of user actions. I did a review only of the code. I will do another pass when the PR is ready for review.
Pinging @elastic/response-ops (Team:ResponseOps) |
Pinging @elastic/response-ops-cases (Feature:Cases) |
Additional tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Complex validation 😅 , great work 👍
@@ -500,13 +504,73 @@ describe('CaseUserActionService', () => { | |||
}); | |||
}); | |||
|
|||
describe('buildUserActions', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great work with tests and mocks 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, it was such a headache 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job 🚀!
There was a problem hiding this comment.
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 where you check updating multiple cases with multiple attributes to update? Some cases should fail and some of them not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make sure I understood
Some cases should fail and some of them not.
but the call is expected to fail right? because some cases in the payload will hit the limit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed some changes, is this what you had in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is what I have in mind, thanks!
@@ -141,4 +164,59 @@ describe('UserActionPersister', () => { | |||
}); | |||
}); | |||
}); | |||
|
|||
describe('buildUserActions', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we test more user action types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which ones?
All tests have different payloads and:
patchCasesRequest
changes status, title, connector, and category.patchAssigneesCasesRequest
,patchRemoveAssigneesCasesRequest
andpatchAddRemoveAssigneesCasesRequest
handle the assignees- and
patchTagsCasesRequest
the tags user actions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I missed that the patchCasesRequest
contains all these changes. It is difficult to verify the tests without having inline snapshots. Thanks!
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: cc @adcoelho |
Connected to elastic#146945 ## Summary | Description | Limit | Done? | Documented? | ------------- | ---- | :---: | ---- | | Total number of user actions and comments combined on a case | 10000 | ✅ | No | ### Checklist Delete any items that are not applicable to this PR. - [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 ### Release Notes Updating a case will now fail if the operation makes it reach more than 10000 user actions.
Connected to #146945
Summary
Checklist
Delete any items that are not applicable to this PR.
Release Notes
Updating a case will now fail if the operation makes it reach more than 10000 user actions.