-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[ResponseOps] [Cases] Attach file to case API #198377
Conversation
Pinging @elastic/response-ops (Team:ResponseOps) |
Pinging @elastic/response-ops-cases (Feature:Cases) |
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! I left some comments.
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.
Thanks for addressing the comments. I left some minor comments.
x-pack/test/cases_api_integration/security_and_spaces/tests/common/files/post_file.ts
Outdated
Show resolved
Hide resolved
660c1ce
to
650289f
Compare
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!!
expect(clientArgs.fileService.delete).toHaveBeenCalledWith({ id }); | ||
}); | ||
|
||
it('calls buildAttachmentRequestFromFileJSON with the correct params', async () => { |
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.
nit: What do you think instead of mocking buildAttachmentRequestFromFileJSONMock
to check if the attachmentService
was called with the correct args?
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.
That was my initial idea but we don't call attachmentService directly. We do:
const model = await CaseCommentModel.create(caseId, clientArgs);
const updatedModel = await model.createComment({
createdDate,
commentReq,
id: savedObjectID,
});
```
And I was losing too much time trying to mock this properly so I just wanted to ensure we build the request correctly.
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.
If you follow model.createComment
you will see that it uses the attachment service to create the attachment. No need to mock the model
.
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.
ah cool, I was wondering why you wrote attachmentService
since I don't use that in add_file
💛 Build succeeded, but was flaky
Failed CI StepsMetrics [docs]Async chunks
Page load bundle
Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
cc @adcoelho |
Starting backport for target branches: 8.x |
💔 All backports failed
Manual backportTo create the backport manually run:
Questions ?Please refer to the Backport tool documentation |
Fixes elastic#22832 ## Summary This PR adds the possibility of adding Files/Attachments to Case in Kibana via an API call. ### How to test The new API URL is `https://localhost:5601/api/cases/<CASE_ID>/files`. You can either use postman or curl to test. 1. Start by creating a case. 2. Call the new API ``` curl --location 'https://localhost:5601/api/cases/<CASE_ID>/files' \ --header 'kbn-xsrf: true' \ --header 'Authorization: Basic ZWxhc3RpYzpjaGFuZ2VtZQ==' \ --form 'filename="Notice"' \ --form 'mimeType="text/plain"' \ --form 'file=@"<FULL_PATH_TO_THE_FILE_YOU_WANT_TO_UPLOAD>"' ``` <img width="1090" alt="Screenshot 2024-10-30 at 15 41 26" src="https://github.com/user-attachments/assets/b018f92d-2603-4bf1-ac12-f01452f35303"> 3. Confirm the user action was created. <img width="383" alt="Screenshot 2024-10-30 at 15 48 45" src="https://github.com/user-attachments/assets/04952b8f-e8fb-4f19-a72f-54030f496fe9"> 4. Confirm the file exists in the case and: - it can be downloaded as expected. - it can be previewed as expected(not every MIME type allows this). ### Release Notes Files can now be attached to cases directly via API. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: lcawl <lcawley@elastic.co>
Fixes #22832
Summary
This PR adds the possibility of adding Files/Attachments to Case in Kibana via an API call.
How to test
The new API URL is
https://localhost:5601/api/cases/<CASE_ID>/files
. You can either use postman or curl to test.Release Notes
Files can now be attached to cases directly via API.