From f415b3b98f4c5c1c60447f9d907b94a5ceacd6a9 Mon Sep 17 00:00:00 2001 From: Yara Tercero Date: Fri, 30 Sep 2022 09:17:56 -0700 Subject: [PATCH] [Security Solution][Exceptions] - Make exceptions read only when displaying deleted rule details (#142258) ### Summary Addresses 141899. --- .../components/all_exception_items_table/index.test.tsx | 6 ++++++ .../components/all_exception_items_table/index.tsx | 7 +++++-- .../detection_engine/rules/all/exceptions/translations.ts | 2 +- .../pages/detection_engine/rules/details/index.tsx | 2 ++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_exceptions/components/all_exception_items_table/index.test.tsx b/x-pack/plugins/security_solution/public/detection_engine/rule_exceptions/components/all_exception_items_table/index.test.tsx index d34cf07aa9146..139d171088ec9 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_exceptions/components/all_exception_items_table/index.test.tsx +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_exceptions/components/all_exception_items_table/index.test.tsx @@ -109,6 +109,7 @@ describe('ExceptionsViewer', () => { ], }} listType={ExceptionListTypeEnum.DETECTION} + isViewReadOnly={false} /> ); @@ -146,6 +147,7 @@ describe('ExceptionsViewer', () => { ], }} listType={ExceptionListTypeEnum.DETECTION} + isViewReadOnly={false} /> ); @@ -183,6 +185,7 @@ describe('ExceptionsViewer', () => { ], }} listType={ExceptionListTypeEnum.ENDPOINT} + isViewReadOnly={false} /> ); @@ -226,6 +229,7 @@ describe('ExceptionsViewer', () => { ], }} listType={ExceptionListTypeEnum.DETECTION} + isViewReadOnly={false} /> ); @@ -268,6 +272,7 @@ describe('ExceptionsViewer', () => { ], }} listType={ExceptionListTypeEnum.DETECTION} + isViewReadOnly={false} /> ); @@ -301,6 +306,7 @@ describe('ExceptionsViewer', () => { ], }} listType={ExceptionListTypeEnum.DETECTION} + isViewReadOnly={false} /> ); diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_exceptions/components/all_exception_items_table/index.tsx b/x-pack/plugins/security_solution/public/detection_engine/rule_exceptions/components/all_exception_items_table/index.tsx index d090f5a3bc590..ffe07bb2c5dfb 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_exceptions/components/all_exception_items_table/index.tsx +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_exceptions/components/all_exception_items_table/index.tsx @@ -75,12 +75,15 @@ export interface GetExceptionItemProps { interface ExceptionsViewerProps { rule: Rule | null; listType: ExceptionListTypeEnum; + /* Used for when displaying exceptions for a rule that has since been deleted, forcing read only view */ + isViewReadOnly: boolean; onRuleChange?: () => void; } const ExceptionsViewerComponent = ({ rule, listType, + isViewReadOnly, onRuleChange, }: ExceptionsViewerProps): JSX.Element => { const { services } = useKibana(); @@ -337,8 +340,8 @@ const ExceptionsViewerComponent = ({ // User privileges checks useEffect((): void => { - setReadOnly(!canUserCRUD || !hasIndexWrite); - }, [setReadOnly, canUserCRUD, hasIndexWrite]); + setReadOnly(isViewReadOnly || !canUserCRUD || !hasIndexWrite); + }, [setReadOnly, isViewReadOnly, canUserCRUD, hasIndexWrite]); useEffect(() => { if (exceptionListsToQuery.length > 0) { diff --git a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/all/exceptions/translations.ts b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/all/exceptions/translations.ts index 8baf21db15c0d..3d817adb2605c 100644 --- a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/all/exceptions/translations.ts +++ b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/all/exceptions/translations.ts @@ -157,7 +157,7 @@ export const referenceErrorMessage = (referenceCount: number) => export const EXCEPTION_LIST_SEARCH_PLACEHOLDER = i18n.translate( 'xpack.securitySolution.detectionEngine.rules.all.exceptions.searchPlaceholder', { - defaultMessage: 'Search by name or list_id', + defaultMessage: 'Search by name or list id', } ); diff --git a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/details/index.tsx b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/details/index.tsx index 5149269c57d9c..0393fcf239f7d 100644 --- a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/details/index.tsx +++ b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/details/index.tsx @@ -871,6 +871,7 @@ const RuleDetailsPageComponent: React.FC = ({ rule={rule} listType={ExceptionListTypeEnum.DETECTION} onRuleChange={refreshRule} + isViewReadOnly={!isExistingRule} data-test-subj="exceptionTab" /> @@ -881,6 +882,7 @@ const RuleDetailsPageComponent: React.FC = ({ rule={rule} listType={ExceptionListTypeEnum.ENDPOINT} onRuleChange={refreshRule} + isViewReadOnly={!isExistingRule} data-test-subj="endpointExceptionsTab" />