Skip to content

Commit

Permalink
Add Risk score missing privileges callout to enablement flyout
Browse files Browse the repository at this point in the history
  • Loading branch information
machadoum committed Nov 12, 2024
1 parent 2466a17 commit 92b9719
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,37 +200,35 @@ const EntityStoreDashboardPanelsComponent = () => {
</>
)}

{(entityStore.status === 'not_installed' || entityStore.status === 'stopped') &&
!isRiskScoreAvailable && (
// TODO: Move modal inside EnableEntityStore component, eliminating the onEnable prop in favour of forwarding the riskScoreEnabled status
<EnableEntityStore
enablements="both"
onEnable={() => setModalState({ visible: true })}
loadingRiskEngine={riskEngineInitializing}
/>
)}
{entityStore.status === 'not_installed' && !isRiskScoreAvailable && (
// TODO: Move modal inside EnableEntityStore component, eliminating the onEnable prop in favour of forwarding the riskScoreEnabled status
<EnableEntityStore
enablements="both"
onEnable={() => setModalState({ visible: true })}
loadingRiskEngine={riskEngineInitializing}
/>
)}

{(entityStore.status === 'not_installed' || entityStore.status === 'stopped') &&
isRiskScoreAvailable && (
<>
<EuiFlexItem>
<EnableEntityStore
enablements="store"
onEnable={() =>
setModalState({
visible: true,
})
}
/>
</EuiFlexItem>
<EuiFlexItem>
<EntityAnalyticsRiskScores riskEntity={RiskScoreEntity.user} />
</EuiFlexItem>
<EuiFlexItem>
<EntityAnalyticsRiskScores riskEntity={RiskScoreEntity.host} />
</EuiFlexItem>
</>
)}
{entityStore.status === 'not_installed' && isRiskScoreAvailable && (
<>
<EuiFlexItem>
<EnableEntityStore
enablements="store"
onEnable={() =>
setModalState({
visible: true,
})
}
/>
</EuiFlexItem>
<EuiFlexItem>
<EntityAnalyticsRiskScores riskEntity={RiskScoreEntity.user} />
</EuiFlexItem>
<EuiFlexItem>
<EntityAnalyticsRiskScores riskEntity={RiskScoreEntity.host} />
</EuiFlexItem>
</>
)}

<EntityStoreEnablementModal
visible={modal.visible}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
} from '../translations';
import { useEntityEnginePrivileges } from '../hooks/use_entity_engine_privileges';
import { MissingPrivilegesCallout } from './missing_privileges_callout';
import { useMissingRiskEnginePrivileges } from '../../../hooks/use_missing_risk_engine_privileges';
import { RiskEnginePrivilegesCallOut } from '../../risk_engine_privileges_callout';

export interface Enablements {
riskScore: boolean;
Expand Down Expand Up @@ -61,7 +63,9 @@ export const EntityStoreEnablementModal: React.FC<EntityStoreEnablementModalProp
riskScore: !!riskScore.checked,
entityStore: !!entityStore.checked,
});
const { data: privileges, isLoading: isLoadingPrivileges } = useEntityEnginePrivileges();
const { data: entityEnginePrivileges, isLoading: isLoadingEntityEnginePrivileges } =
useEntityEnginePrivileges();
const riskEnginePrivileges = useMissingRiskEnginePrivileges();

if (!visible) {
return null;
Expand All @@ -88,15 +92,22 @@ export const EntityStoreEnablementModal: React.FC<EntityStoreEnablementModalProp
/>
}
checked={enablements.riskScore}
disabled={riskScore.disabled || false}
disabled={
riskScore.disabled ||
(!riskEnginePrivileges.isLoading && !riskEnginePrivileges?.hasAllRequiredPrivileges)
}
onChange={() => setEnablements((prev) => ({ ...prev, riskScore: !prev.riskScore }))}
/>
</EuiFlexItem>
{!riskEnginePrivileges.isLoading && !riskEnginePrivileges.hasAllRequiredPrivileges && (
<EuiFlexItem>
<RiskEnginePrivilegesCallOut privileges={riskEnginePrivileges} />
</EuiFlexItem>
)}
<EuiFlexItem>
<EuiText>{ENABLEMENT_DESCRIPTION_RISK_ENGINE_ONLY}</EuiText>
</EuiFlexItem>
<EuiHorizontalRule margin="none" />

<EuiFlexItem>
<EuiFlexGroup justifyContent="flexStart">
<EuiSwitch
Expand All @@ -108,7 +119,8 @@ export const EntityStoreEnablementModal: React.FC<EntityStoreEnablementModalProp
}
checked={enablements.entityStore}
disabled={
entityStore.disabled || (!isLoadingPrivileges && !privileges?.has_all_required)
entityStore.disabled ||
(!isLoadingEntityEnginePrivileges && !entityEnginePrivileges?.has_all_required)
}
onChange={() =>
setEnablements((prev) => ({ ...prev, entityStore: !prev.entityStore }))
Expand All @@ -119,9 +131,9 @@ export const EntityStoreEnablementModal: React.FC<EntityStoreEnablementModalProp
</EuiToolTip>
</EuiFlexGroup>
</EuiFlexItem>
{!privileges || privileges.has_all_required ? null : (
{!entityEnginePrivileges || entityEnginePrivileges.has_all_required ? null : (
<EuiFlexItem>
<MissingPrivilegesCallout privileges={privileges} />
<MissingPrivilegesCallout privileges={entityEnginePrivileges} />
</EuiFlexItem>
)}
<EuiFlexItem>
Expand Down

0 comments on commit 92b9719

Please sign in to comment.