Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import {
PersistableStateAttachmentPayloadRt,
AttachmentType,
AttachmentRt,
AttachmentsRt,
EventAttachmentPayloadRt,
} from '../../domain/attachment/v1';
import { AttachmentRtV2 } from '../../domain/attachment/v2';

/**
* Files
Expand Down Expand Up @@ -157,7 +157,7 @@ export const BulkGetAttachmentsRequestRt = rt.strict({
});

export const BulkGetAttachmentsResponseRt = rt.strict({
attachments: AttachmentsRt,
attachments: rt.array(AttachmentRtV2),
errors: rt.array(
rt.strict({
error: rt.string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
CaseUserActionBasicRt,
UserActionsRt,
} from '../../domain/user_action/v1';
import type { Attachments } from '../../domain';
import type { BulkGetAttachmentsResponse } from '../attachment/v1';

export type UserActionWithResponse<T> = T & { id: string; version: string } & rt.TypeOf<
typeof CaseUserActionInjectedIdsRt
Expand Down Expand Up @@ -93,5 +93,5 @@ export const UserActionFindResponseRt = rt.strict({
export type UserActionFindResponse = rt.TypeOf<typeof UserActionFindResponseRt>;

export interface UserActionInternalFindResponse extends UserActionFindResponse {
latestAttachments: Attachments;
latestAttachments: BulkGetAttachmentsResponse['attachments'];
}
4 changes: 3 additions & 1 deletion x-pack/platform/plugins/shared/cases/public/api/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ export const convertCaseResolveToCamelCase = (res: CaseResolveResponse): Resolve
};
};

export const convertAttachmentsToCamelCase = (attachments: Attachment[]): AttachmentUI[] => {
export const convertAttachmentsToCamelCase = (
attachments: Array<Attachment | AttachmentRequestV2>
): AttachmentUI[] => {
return attachments.map((attachment) => convertAttachmentToCamelCase(attachment));
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import type { EuiCommentProps } from '@elastic/eui';

import type { SnakeToCamelCase } from '../../../../common/types';
import type { CommentUserAction } from '../../../../common/types/domain';
import type { CommentUserAction, UnifiedAttachment } from '../../../../common/types/domain';
import { UserActionActions, AttachmentType } from '../../../../common/types/domain';
import { type AttachmentTypeRegistry } from '../../../../common/registry';
import type { UserActionBuilder, UserActionBuilderArgs } from '../types';
Expand All @@ -20,6 +20,7 @@ import { createAlertAttachmentUserActionBuilder } from '../../attachments/alert/
import { createActionAttachmentUserActionBuilder } from '../../attachments/host_isolation/actions';
import { createExternalReferenceAttachmentUserActionBuilder } from './external_reference';
import { createPersistableStateAttachmentUserActionBuilder } from './persistable_state';
import { createUnifiedValueAttachmentUserActionBuilder } from './unified_value';
import type { AttachmentType as AttachmentFrameworkAttachmentType } from '../../../client/attachment_framework/types';
import { createEventAttachmentUserActionBuilder } from '../../attachments/event/event';
import { isLegacyAttachmentRequest } from '../../../../common/utils/attachments';
Expand All @@ -31,13 +32,15 @@ interface DeleteLabelTitle {
caseData: UserActionBuilderArgs['caseData'];
externalReferenceAttachmentTypeRegistry: UserActionBuilderArgs['externalReferenceAttachmentTypeRegistry'];
persistableStateAttachmentTypeRegistry: UserActionBuilderArgs['persistableStateAttachmentTypeRegistry'];
unifiedAttachmentTypeRegistry: UserActionBuilderArgs['unifiedAttachmentTypeRegistry'];
}

const getDeleteLabelTitle = ({
userAction,
caseData,
externalReferenceAttachmentTypeRegistry,
persistableStateAttachmentTypeRegistry,
unifiedAttachmentTypeRegistry,
}: DeleteLabelTitle) => {
const { comment } = userAction.payload;
if (isLegacyAttachmentRequest(comment)) {
Expand Down Expand Up @@ -71,6 +74,16 @@ const getDeleteLabelTitle = ({
}),
});
}
} else if (unifiedAttachmentTypeRegistry?.has(comment.type)) {
return getDeleteLabelFromRegistry({
caseData,
registry: unifiedAttachmentTypeRegistry,
getId: () => comment.type,
getAttachmentProps: () => ({
data: (comment as unknown as { data: Record<string, unknown> }).data ?? {},
metadata: (comment as unknown as { metadata?: Record<string, unknown> }).metadata,
}),
});
}

return `${i18n.REMOVED_FIELD} ${i18n.COMMENT.toLowerCase()}`;
Expand Down Expand Up @@ -115,6 +128,7 @@ const getDeleteCommentUserAction = ({
caseData,
externalReferenceAttachmentTypeRegistry,
persistableStateAttachmentTypeRegistry,
unifiedAttachmentTypeRegistry,
handleOutlineComment,
}: {
userAction: SnakeToCamelCase<CommentUserAction>;
Expand All @@ -124,13 +138,15 @@ const getDeleteCommentUserAction = ({
| 'userProfiles'
| 'externalReferenceAttachmentTypeRegistry'
| 'persistableStateAttachmentTypeRegistry'
| 'unifiedAttachmentTypeRegistry'
| 'caseData'
>): EuiCommentProps[] => {
const label = getDeleteLabelTitle({
userAction,
caseData,
externalReferenceAttachmentTypeRegistry,
persistableStateAttachmentTypeRegistry,
unifiedAttachmentTypeRegistry,
});

const commonBuilder = createCommonUpdateUserActionBuilder({
Expand All @@ -151,6 +167,7 @@ const getCreateCommentUserAction = ({
caseData,
externalReferenceAttachmentTypeRegistry,
persistableStateAttachmentTypeRegistry,
unifiedAttachmentTypeRegistry,
attachment,
manageMarkdownEditIds,
selectedOutlineCommentId,
Expand Down Expand Up @@ -250,6 +267,19 @@ const getCreateCommentUserAction = ({
return persistableBuilder.build();

default:
if (unifiedAttachmentTypeRegistry?.has((attachment as unknown as { type: string }).type)) {
const unifiedBuilder = createUnifiedValueAttachmentUserActionBuilder({
userAction,
userProfiles,
attachment: attachment as unknown as SnakeToCamelCase<UnifiedAttachment>,
unifiedAttachmentTypeRegistry,
caseData,
isLoading: loadingCommentIds.includes((attachment as unknown as { id: string }).id),
handleDeleteComment,
});

return unifiedBuilder.build();
}
return [];
}
};
Expand All @@ -261,6 +291,7 @@ export const createCommentUserActionBuilder: UserActionBuilder = ({
userProfiles,
externalReferenceAttachmentTypeRegistry,
persistableStateAttachmentTypeRegistry,
unifiedAttachmentTypeRegistry,
userAction,
manageMarkdownEditIds,
selectedOutlineCommentId,
Expand Down Expand Up @@ -288,6 +319,7 @@ export const createCommentUserActionBuilder: UserActionBuilder = ({
userProfiles,
externalReferenceAttachmentTypeRegistry,
persistableStateAttachmentTypeRegistry,
unifiedAttachmentTypeRegistry,
});
}

Expand All @@ -306,6 +338,7 @@ export const createCommentUserActionBuilder: UserActionBuilder = ({
userAction: attachmentUserAction,
externalReferenceAttachmentTypeRegistry,
persistableStateAttachmentTypeRegistry,
unifiedAttachmentTypeRegistry,
attachment,
manageMarkdownEditIds,
selectedOutlineCommentId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { AttachmentActionType } from '../../../client/attachment_framework/types
import { UserActionTimestamp } from '../timestamp';
import type { AttachmentTypeRegistry } from '../../../../common/registry';
import type { Attachment } from '../../../../common/types/domain';
import type { UnifiedAttachment } from '../../../../common/types/domain/attachment/v2';
import type { UserActionBuilder, UserActionBuilderArgs } from '../types';
import type { SnakeToCamelCase } from '../../../../common/types';
import {
Expand Down Expand Up @@ -76,7 +77,7 @@ const getAttachmentRenderer = memoize((cachingKey: string) => {
});

export const createRegisteredAttachmentUserActionBuilder = <
C extends Attachment,
C extends Attachment | UnifiedAttachment,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
R extends AttachmentTypeRegistry<AttachmentType<any>>
>({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { UserActionBuilder, UserActionBuilderArgs } from '../types';
import type { SnakeToCamelCase } from '../../../../common/types';
import type { UnifiedAttachment } from '../../../../common/types/domain';
import { createRegisteredAttachmentUserActionBuilder } from './registered_attachments';

type BuilderArgs = Pick<
UserActionBuilderArgs,
| 'userAction'
| 'unifiedAttachmentTypeRegistry'
| 'caseData'
| 'handleDeleteComment'
| 'userProfiles'
> & {
attachment: SnakeToCamelCase<UnifiedAttachment>;
isLoading: boolean;
};

export const createUnifiedValueAttachmentUserActionBuilder = ({
userAction,
userProfiles,
attachment,
unifiedAttachmentTypeRegistry,
caseData,
isLoading,
handleDeleteComment,
}: BuilderArgs): ReturnType<UserActionBuilder> => {
return createRegisteredAttachmentUserActionBuilder({
userAction,
userProfiles,
attachment,
registry: unifiedAttachmentTypeRegistry,
caseData,
handleDeleteComment,
isLoading,
getId: () => attachment.type,
getAttachmentViewProps: () => ({
data: (attachment as unknown as { data: Record<string, unknown> }).data ?? {},
metadata: (attachment as unknown as { metadata?: Record<string, unknown> }).metadata,
}),
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { UserActionActions } from '../../../common/types/domain';
import { SECURITY_SOLUTION_OWNER } from '../../../common/constants';
import { ExternalReferenceAttachmentTypeRegistry } from '../../client/attachment_framework/external_reference_registry';
import { PersistableStateAttachmentTypeRegistry } from '../../client/attachment_framework/persistable_state_registry';
import { UnifiedAttachmentTypeRegistry } from '../../client/attachment_framework/unified_attachment_registry';
import { getCaseConnectorsMockResponse } from '../../common/mock/connectors';
import { basicCase, getUserAction } from '../../containers/mock';
import { userProfiles, userProfilesMap } from '../../containers/user_profiles/api.mock';
Expand Down Expand Up @@ -53,13 +54,15 @@ export const getMockBuilderArgs = (): UserActionBuilderArgs => {
const handleOutlineComment = jest.fn();
const externalReferenceAttachmentTypeRegistry = new ExternalReferenceAttachmentTypeRegistry();
const persistableStateAttachmentTypeRegistry = new PersistableStateAttachmentTypeRegistry();
const unifiedAttachmentTypeRegistry = new UnifiedAttachmentTypeRegistry();

return {
userAction,
userProfiles: userProfilesMap,
currentUserProfile: userProfiles[0],
externalReferenceAttachmentTypeRegistry,
persistableStateAttachmentTypeRegistry,
unifiedAttachmentTypeRegistry,
caseData: basicCase,
casesConfiguration: casesConfigurationsMock,
attachments: basicCase.comments,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type { UNSUPPORTED_ACTION_TYPES } from './constants';
import type { OnUpdateFields } from '../case_view/types';
import type { ExternalReferenceAttachmentTypeRegistry } from '../../client/attachment_framework/external_reference_registry';
import type { PersistableStateAttachmentTypeRegistry } from '../../client/attachment_framework/persistable_state_registry';
import type { UnifiedAttachmentTypeRegistry } from '../../client/attachment_framework/unified_attachment_registry';
import type { CurrentUserProfile } from '../types';
import type { UserActivityParams } from '../user_actions_activity_bar/types';

Expand Down Expand Up @@ -56,6 +57,7 @@ export interface UserActionBuilderArgs {
currentUserProfile: CurrentUserProfile;
externalReferenceAttachmentTypeRegistry: ExternalReferenceAttachmentTypeRegistry;
persistableStateAttachmentTypeRegistry: PersistableStateAttachmentTypeRegistry;
unifiedAttachmentTypeRegistry: UnifiedAttachmentTypeRegistry;
caseConnectors: CaseConnectors;
userAction: UserActionUI;
attachments: AttachmentUI[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,11 @@ export const UserActionsList = React.memo(
bottomActions = [],
isExpandable = false,
}: UserActionListProps) => {
const { externalReferenceAttachmentTypeRegistry, persistableStateAttachmentTypeRegistry } =
useCasesContext();
const {
externalReferenceAttachmentTypeRegistry,
persistableStateAttachmentTypeRegistry,
unifiedAttachmentTypeRegistry,
} = useCasesContext();
const { owner } = useCasesContext();
const { commentId } = useCaseViewParams();
const [initLoading, setInitLoading] = useState(true);
Expand Down Expand Up @@ -142,6 +145,7 @@ export const UserActionsList = React.memo(
caseConnectors,
externalReferenceAttachmentTypeRegistry,
persistableStateAttachmentTypeRegistry,
unifiedAttachmentTypeRegistry,
userAction,
userProfiles,
currentUserProfile,
Expand Down Expand Up @@ -170,6 +174,7 @@ export const UserActionsList = React.memo(
caseConnectors,
externalReferenceAttachmentTypeRegistry,
persistableStateAttachmentTypeRegistry,
unifiedAttachmentTypeRegistry,
userProfiles,
currentUserProfile,
attachments,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type { AttachmentSavedObject, SOWithErrors } from '../../common/types';
import { partitionByCaseAssociation } from '../../common/partitioning';
import { decodeOrThrow, decodeWithExcessOrThrow } from '../../common/runtime_types';
import type { AttachmentAttributes } from '../../../common/types/domain';
import { CASE_ATTACHMENT_SAVED_OBJECT } from '../../../common/constants';

type AttachmentSavedObjectWithErrors = Array<SOWithErrors<AttachmentAttributes>>;

Expand Down Expand Up @@ -50,11 +51,21 @@ export async function bulkGet(
const { validAttachments, attachmentsWithErrors, invalidAssociationAttachments } =
partitionAttachments(caseID, attachments);

const [unifiedAttachments, legacyAttachments] = partition(
validAttachments,
(so) => so.type === CASE_ATTACHMENT_SAVED_OBJECT
);

const { authorized: authorizedAttachments, unauthorized: unauthorizedAttachments } =
await authorization.getAndEnsureAuthorizedEntities({
savedObjects: validAttachments,
operation: Operations.bulkGetAttachments,
});
legacyAttachments.length > 0
? await authorization.getAndEnsureAuthorizedEntities({
savedObjects: legacyAttachments,
operation: Operations.bulkGetAttachments,
})
: {
authorized: [] as AttachmentSavedObject[],
unauthorized: [] as AttachmentSavedObject[],
};

const errors = constructErrors({
associationErrors: invalidAssociationAttachments,
Expand All @@ -63,8 +74,15 @@ export async function bulkGet(
caseId: caseID,
});

const flattenedLegacy = flattenCommentSavedObjects(authorizedAttachments);
const flattenedUnified = unifiedAttachments.map((so) => ({
id: so.id,
version: so.version ?? '0',
...so.attributes,
}));

const res = {
attachments: flattenCommentSavedObjects(authorizedAttachments),
attachments: [...flattenedLegacy, ...flattenedUnified],
errors,
};

Expand Down
Loading
Loading