diff --git a/x-pack/plugins/cases/public/components/files/file_delete_button_icon.test.tsx b/x-pack/plugins/cases/public/components/files/file_delete_button_icon.test.tsx index 5629ae4fcf6c..aeabb56b977c 100644 --- a/x-pack/plugins/cases/public/components/files/file_delete_button_icon.test.tsx +++ b/x-pack/plugins/cases/public/components/files/file_delete_button_icon.test.tsx @@ -12,7 +12,7 @@ import userEvent from '@testing-library/user-event'; import type { AppMockRenderer } from '../../common/mock'; -import { createAppMockRenderer } from '../../common/mock'; +import { buildCasesPermissions, createAppMockRenderer } from '../../common/mock'; import { basicCaseId, basicFileMock } from '../../containers/mock'; import { useDeleteFileAttachment } from '../../containers/use_delete_file_attachment'; import { FileDeleteButtonIcon } from './file_delete_button_icon'; @@ -73,4 +73,14 @@ describe('FileDeleteButtonIcon', () => { }); }); }); + + it('delete button is disabled if user has no delete permission', async () => { + appMockRender = createAppMockRenderer({ + permissions: buildCasesPermissions({ delete: false }), + }); + + appMockRender.render(); + + expect(await screen.findByTestId('cases-files-delete-button')).toBeDisabled(); + }); }); diff --git a/x-pack/plugins/cases/public/components/files/file_delete_button_icon.tsx b/x-pack/plugins/cases/public/components/files/file_delete_button_icon.tsx index 2e50c76eacaf..86929d5b49e2 100644 --- a/x-pack/plugins/cases/public/components/files/file_delete_button_icon.tsx +++ b/x-pack/plugins/cases/public/components/files/file_delete_button_icon.tsx @@ -12,6 +12,7 @@ import * as i18n from './translations'; import { useDeleteFileAttachment } from '../../containers/use_delete_file_attachment'; import { useDeletePropertyAction } from '../user_actions/property_actions/use_delete_property_action'; import { DeleteAttachmentConfirmationModal } from '../user_actions/delete_attachment_confirmation_modal'; +import { useCasesContext } from '../cases_context/use_cases_context'; interface FileDeleteButtonIconProps { caseId: string; @@ -19,6 +20,7 @@ interface FileDeleteButtonIconProps { } const FileDeleteButtonIconComponent: React.FC = ({ caseId, fileId }) => { + const { permissions } = useCasesContext(); const { isLoading, mutate: deleteFileAttachment } = useDeleteFileAttachment(); const { showDeletionModal, onModalOpen, onConfirm, onCancel } = useDeletePropertyAction({ @@ -31,7 +33,7 @@ const FileDeleteButtonIconComponent: React.FC = ({ ca iconType={'trash'} aria-label={i18n.DELETE_FILE} color={'danger'} - isDisabled={isLoading} + isDisabled={isLoading || !permissions.delete} onClick={onModalOpen} data-test-subj={'cases-files-delete-button'} />