Skip to content

Commit

Permalink
[Security Solution][Exceptions] - Make exceptions read only when disp…
Browse files Browse the repository at this point in the history
…laying deleted rule details (#142258)

### Summary

Addresses 141899.
  • Loading branch information
yctercero authored Sep 30, 2022
1 parent 93b97bf commit f415b3b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ describe('ExceptionsViewer', () => {
],
}}
listType={ExceptionListTypeEnum.DETECTION}
isViewReadOnly={false}
/>
</TestProviders>
);
Expand Down Expand Up @@ -146,6 +147,7 @@ describe('ExceptionsViewer', () => {
],
}}
listType={ExceptionListTypeEnum.DETECTION}
isViewReadOnly={false}
/>
</TestProviders>
);
Expand Down Expand Up @@ -183,6 +185,7 @@ describe('ExceptionsViewer', () => {
],
}}
listType={ExceptionListTypeEnum.ENDPOINT}
isViewReadOnly={false}
/>
</TestProviders>
);
Expand Down Expand Up @@ -226,6 +229,7 @@ describe('ExceptionsViewer', () => {
],
}}
listType={ExceptionListTypeEnum.DETECTION}
isViewReadOnly={false}
/>
</TestProviders>
);
Expand Down Expand Up @@ -268,6 +272,7 @@ describe('ExceptionsViewer', () => {
],
}}
listType={ExceptionListTypeEnum.DETECTION}
isViewReadOnly={false}
/>
);

Expand Down Expand Up @@ -301,6 +306,7 @@ describe('ExceptionsViewer', () => {
],
}}
listType={ExceptionListTypeEnum.DETECTION}
isViewReadOnly={false}
/>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
);

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

0 comments on commit f415b3b

Please sign in to comment.