[Security Solution][Exceptions] - Make exceptions read only when displaying deleted rule details (#142258) (#142387)

### Summary

Addresses 141899.

(cherry picked from commit f415b3b98f)

Co-authored-by: Yara Tercero <yctercero@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2022-09-30 11:49:29 -06:00 committed by GitHub
parent 09e0fe85a8
commit f5dbe3a8c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 3 deletions

View file

@ -109,6 +109,7 @@ describe('ExceptionsViewer', () => {
],
}}
listType={ExceptionListTypeEnum.DETECTION}
isViewReadOnly={false}
/>
</TestProviders>
);
@ -146,6 +147,7 @@ describe('ExceptionsViewer', () => {
],
}}
listType={ExceptionListTypeEnum.DETECTION}
isViewReadOnly={false}
/>
</TestProviders>
);
@ -183,6 +185,7 @@ describe('ExceptionsViewer', () => {
],
}}
listType={ExceptionListTypeEnum.ENDPOINT}
isViewReadOnly={false}
/>
</TestProviders>
);
@ -226,6 +229,7 @@ describe('ExceptionsViewer', () => {
],
}}
listType={ExceptionListTypeEnum.DETECTION}
isViewReadOnly={false}
/>
</TestProviders>
);
@ -268,6 +272,7 @@ describe('ExceptionsViewer', () => {
],
}}
listType={ExceptionListTypeEnum.DETECTION}
isViewReadOnly={false}
/>
);
@ -301,6 +306,7 @@ describe('ExceptionsViewer', () => {
],
}}
listType={ExceptionListTypeEnum.DETECTION}
isViewReadOnly={false}
/>
);

View file

@ -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) {

View file

@ -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',
}
);

View file

@ -871,6 +871,7 @@ const RuleDetailsPageComponent: React.FC<DetectionEngineComponentProps> = ({
rule={rule}
listType={ExceptionListTypeEnum.DETECTION}
onRuleChange={refreshRule}
isViewReadOnly={!isExistingRule}
data-test-subj="exceptionTab"
/>
</Route>
@ -881,6 +882,7 @@ const RuleDetailsPageComponent: React.FC<DetectionEngineComponentProps> = ({
rule={rule}
listType={ExceptionListTypeEnum.ENDPOINT}
onRuleChange={refreshRule}
isViewReadOnly={!isExistingRule}
data-test-subj="endpointExceptionsTab"
/>
</Route>