Skip to content

Commit

Permalink
[Security Solution] Fix Incorrect Enable Button Behavior in Entity St…
Browse files Browse the repository at this point in the history
…ore Modal (elastic#212078)

## Summary

Ensure Enable Button Considers Disabled State of Risk Score & Entity
Store. Previously only used the checked state of the toggle.

### Reproduce the Issue
Steps, as [per bug
ticket:](elastic#209242 (comment))

1. Kibana version 8.16.0 or above should exist
2. Navigate to the Dashboards tab under Security
3. Select Entity Analytics dashboard
4. Click on the enable button and enable risk score
5. Disable the options for Entity store
6. Then again select the enable button for Entity store
7. Disable the enable button
8. Observe the Enable button is still enabled

### After Issue Solved

Same steps as above, but should show the warning and disable the button.

#### Videos

Videos show when either riskScore or entityStore is enabled, and the
other is unchecked, the warning should show and the button should be
disabled.


https://github.com/user-attachments/assets/236f9e69-f810-4116-9948-38fd27d4d945



https://github.com/user-attachments/assets/2971e845-5d46-4eac-997a-79b3b17922c0

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
CAWilson94 and kibanamachine authored Feb 24, 2025
1 parent a51e96e commit ba9210c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,24 @@ describe('EntityStoreEnablementModal', () => {
expect(enableButton).toBeDisabled();
});

it('should show proceed warning when riskScore is enabled but entityStore is disabled and unchecked', () => {
renderComponent({
...defaultProps,
riskScore: { disabled: false, checked: false }, // Enabled & Checked
entityStore: { disabled: true, checked: false }, // Disabled & Unchecked
});
expect(screen.getByText('Please enable at least one option to proceed.')).toBeInTheDocument();
});

it('should show proceed warning when entityStore is enabled but riskScore is disabled and unchecked', () => {
renderComponent({
...defaultProps,
entityStore: { disabled: false, checked: false }, // Enabled & Checked
riskScore: { disabled: true, checked: false }, // Disabled & Unchecked
});
expect(screen.getByText('Please enable at least one option to proceed.')).toBeInTheDocument();
});

it('should not show entity engine missing privileges warning when no missing privileges', () => {
renderComponent();
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ interface EntityStoreEnablementModalProps {
};
}

const shouldAllowEnablement = (
riskScoreEnabled: boolean,
entityStoreEnabled: boolean,
enablements: Enablements
) => {
if (riskScoreEnabled) {
return enablements.entityStore;
}
if (entityStoreEnabled) {
return enablements.riskScore;
}
return enablements.riskScore || enablements.entityStore;
};

export const EntityStoreEnablementModal: React.FC<EntityStoreEnablementModalProps> = ({
visible,
toggle,
Expand All @@ -69,7 +83,12 @@ export const EntityStoreEnablementModal: React.FC<EntityStoreEnablementModalProp
const { data: entityEnginePrivileges, isLoading: isLoadingEntityEnginePrivileges } =
useEntityEnginePrivileges();
const riskEnginePrivileges = useMissingRiskEnginePrivileges();
const enablementOptions = enablements.riskScore || enablements.entityStore;

const enablementOptions = shouldAllowEnablement(
!!riskScore.disabled,
!!entityStore.disabled,
enablements
);
const { AdditionalChargesMessage } = useContractComponents();

if (!visible) {
Expand Down

0 comments on commit ba9210c

Please sign in to comment.