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

[ResponseOps] [Cases] Attach file to case API #198377

Merged
merged 24 commits into from
Nov 14, 2024

Conversation

adcoelho
Copy link
Contributor

@adcoelho adcoelho commented Oct 30, 2024

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.

  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>"'
Screenshot 2024-10-30 at 15 41 26
  1. Confirm the user action was created.
Screenshot 2024-10-30 at 15 48 45
  1. 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.

@adcoelho adcoelho added Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v9.0.0 Feature:Cases Cases feature backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) labels Oct 30, 2024
@adcoelho adcoelho requested a review from lcawl October 30, 2024 14:53
@adcoelho adcoelho self-assigned this Oct 30, 2024
@adcoelho adcoelho requested a review from a team as a code owner October 30, 2024 14:53
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

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

@adcoelho adcoelho added the release_note:feature Makes this part of the condensed release notes label Oct 30, 2024
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 left some comments.

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.

Thanks for addressing the comments. I left some minor comments.

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!!

oas_docs/output/kibana.yaml Show resolved Hide resolved
oas_docs/output/kibana.yaml Show resolved Hide resolved
oas_docs/output/kibana.yaml Show resolved Hide resolved
expect(clientArgs.fileService.delete).toHaveBeenCalledWith({ id });
});

it('calls buildAttachmentRequestFromFileJSON with the correct params', async () => {
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 do you think instead of mocking buildAttachmentRequestFromFileJSONMock to check if the attachmentService was called with the correct args?

Copy link
Contributor Author

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.

Copy link
Member

@cnasikas cnasikas Nov 14, 2024

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.

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 cool, I was wondering why you wrote attachmentService since I don't use that in add_file

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Async chunks

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

id before after diff
cases 491.8KB 491.8KB +1.0B

Page load bundle

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

id before after diff
cases 157.4KB 158.2KB +762.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
@kbn/test-suites-xpack 722 724 +2

Total ESLint disabled count

id before after diff
@kbn/test-suites-xpack 747 749 +2

History

cc @adcoelho

@adcoelho adcoelho merged commit e2702ff into elastic:main Nov 14, 2024
25 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/11842007941

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.x Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 198377

Questions ?

Please refer to the Backport tool documentation

markov00 pushed a commit to markov00/kibana that referenced this pull request Nov 14, 2024
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) 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.17.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants