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] Split attachment types for versioned http apis #155440

Conversation

jonathan-buttner
Copy link
Contributor

@jonathan-buttner jonathan-buttner commented Apr 20, 2023

This PR separates the http API io-ts types from the types that are used in the cases service layer to interact with the saved object client. This PR is specifically for the attachments it only affects the types used when interacting with the saved object client and doesn't touch the transformation logic yet.

Issue: #153726

@jonathan-buttner jonathan-buttner added release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:Cases Cases feature v8.8.0 labels Apr 20, 2023
index?: string | string[];
rule?: Record<string, unknown>;
comment?: string;
actions?: Record<string, unknown>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should the child fields of this field be represented as well? It doesn't seem to affect type errors.

Copy link
Member

@cnasikas cnasikas Apr 26, 2023

Choose a reason for hiding this comment

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

I think we should be more explicit on this and define them. Same for the rule.

result = result.concat(
// We need a cast here because to limited attachment type conflicts with the expected result even though they
// should be the same
userActionSavedObject.saved_objects as unknown as Array<SavedObject<AttributesTypeAlerts>>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just calling this out. Do you see a better way around this? I believe we skip transforming this because alerts don't have fields that need to be migrated (the rule.id should have been but we had that bugfix).

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I cannot think of another way of doing it.

@jonathan-buttner jonathan-buttner changed the base branch from main to cases-split-types-feature April 20, 2023 20:02
@jonathan-buttner jonathan-buttner marked this pull request as ready for review April 20, 2023 20:47
@jonathan-buttner jonathan-buttner requested a review from a team as a code owner April 20, 2023 20:47
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

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

type: string;
soType?: string;
};
persistableStateAttachmentState?: Record<string, unknown>;
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 the persistableStateAttachmentTypeId is missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, yeah I was getting confused between that and the externalId 👍 I'll add it back.

@@ -258,7 +259,7 @@ export const isCommentRequestTypeAlert = (
* A type narrowing function for external reference so attachments.
*/
export const isCommentRequestTypeExternalReferenceSO = (
context: Partial<CommentRequest>
context: Partial<AttachmentRequestAttributes>
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we do the same for the other utility functions? Even if we don't get TS errors now it will protects us from mistakes in the future.

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 a little unsure about these functions because most of them are used in the clients and not the service layer. Maybe we should eventually move the isCommentRequestTypeExternalReferenceSO to the service layer since that's where it is used.

Copy link
Member

Choose a reason for hiding this comment

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

Oh ok. If they are used in the client's layer then it is fine. Moving isCommentRequestTypeExternalReferenceSO sounds good to me.

@@ -207,7 +173,7 @@ export class AttachmentService {
);

const attachment =
await this.context.unsecuredSavedObjectsClient.create<AttachmentAttributesWithoutRefs>(
await this.context.unsecuredSavedObjectsClient.create<AttachmentPersistedAttributes>(
Copy link
Member

Choose a reason for hiding this comment

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

What about bulkDelete, update, and bulkUpdate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦‍♂️ don't know why I missed all that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like bulkDelete doesn't take a type. I'll update the others though.

@@ -59,7 +50,7 @@ export class AttachmentGetter {
);

const response =
await this.context.unsecuredSavedObjectsClient.bulkGet<AttachmentAttributesWithoutRefs>(
await this.context.unsecuredSavedObjectsClient.bulkGet<AttachmentPersistedAttributes>(
Copy link
Member

Choose a reason for hiding this comment

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

Same here, I think we should add the new type to all SO methods of the AttachmentGetter class.

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 think the ones I didn't add it to here are intentionally wanting unknown. Let me know if I missed any though.

Copy link
Member

Choose a reason for hiding this comment

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

Can we define the return type of all inject*/extract* functions like the transform functions in the Case service? I think it will help us avoid mistakes in the future. Also, the injectAttachmentSOAttributesFromRefsForPatch accepts a CommentPatchAttributes which I think it should be AttachmentRequestAttributes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we define the return type of all inject*/extract* functions like the transform functions in the Case service? I think it will help us avoid mistakes in the future.

Yep will do!

Also, the injectAttachmentSOAttributesFromRefsForPatch accepts a CommentPatchAttributes which I think it should be AttachmentRequestAttributes

I think that's the field that represents the original patch request not the results from the saved object update. We use that to determine if we are deleting a reference I think. I think it should stay as CommentPatchAttributes.

I did update the saved object response though

image

Copy link
Member

Choose a reason for hiding this comment

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

Ok!

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.

LGTM! I left some comments. I think we should go to all references of CommentRequest, CommentPatchAttributes, and CommentAttributes in the server code and check if it is needed to be replaced with AttachmentRequestAttributes or similar.

@kibana-ci
Copy link
Collaborator

kibana-ci commented Apr 26, 2023

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] Jest Tests #15 / creates new embeddable with incoming embeddable if id does not match existing panel
  • [job] [logs] FTR Configs #27 / Ingest Pipelines Accessibility Create Pipeline Wizard
  • [job] [logs] FTR Configs #27 / Ingest Pipelines Accessibility Create Pipeline Wizard
  • [job] [logs] FTR Configs #23 / Ingest pipelines app Ingest Pipelines create pipeline "after each" hook for "Creates a pipeline"
  • [job] [logs] FTR Configs #23 / Ingest pipelines app Ingest Pipelines create pipeline "after each" hook for "Creates a pipeline"
  • [job] [logs] FTR Configs #23 / Ingest pipelines app Ingest Pipelines create pipeline Creates a pipeline
  • [job] [logs] FTR Configs #23 / Ingest pipelines app Ingest Pipelines create pipeline Creates a pipeline
  • [job] [logs] FTR Configs #23 / Ingest pipelines app Ingest Pipelines Loads the app
  • [job] [logs] FTR Configs #23 / Ingest pipelines app Ingest Pipelines Loads the app

Metrics [docs]

‼️ ERROR: no builds found for mergeBase sha [bf588bf]

History

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

@jonathan-buttner jonathan-buttner merged commit 9f9eb79 into elastic:cases-split-types-feature Apr 26, 2023
@jonathan-buttner jonathan-buttner deleted the cases-split-comments branch April 26, 2023 19:45
jonathan-buttner added a commit that referenced this pull request Apr 28, 2023
This PR separates the persisted SO attributes from the fields received
in the HTTP API requests.

This is to address step 2 in preparing our HTTP routes as versioned.

Issue: #153726

This PR encompasses a few PRs here which have been reviewed individually
by the cases team members:

#155325 - User actions
#155440 - Attachments
#155444 - Configure, Connector
Mappings
#155277 - Cases

The large number of files is because of renaming some types throughout
the frontend code. There shouldn't be many functionality changes, mostly
just type changes.

---------

Co-authored-by: Christos Nasikas <christos.nasikas@elastic.co>
Co-authored-by: Patryk Kopyciński <contact@patrykkopycinski.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.8.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants