Skip to content

Commit

Permalink
show user lacks of CRUD privileges message when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
maximpn committed Oct 19, 2022
1 parent 8d21efb commit 83b355e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ export const getToolTipContent = (
| boolean
| Readonly<{
[x: string]: boolean;
}>
}>,
canUserCRUD: boolean | null
): string | undefined => {
if (rule == null) {
return undefined;
} else if (isMlRule(rule.type) && !hasMlPermissions) {
return detectionI18n.ML_RULES_DISABLED_MESSAGE;
} else if (!canEditRuleWithActions(rule, hasReadActionsPrivileges)) {
return i18n.EDIT_RULE_SETTINGS_TOOLTIP;
return i18n.LACK_OF_KIBANA_PRIVILEGES;
} else if (canUserCRUD !== null && !canUserCRUD) {
return i18n.LACK_OF_RULE_EDITING_PRIVILEGES;
} else {
return undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export const useBulkActions = ({
disabled:
missingActionPrivileges || containsLoading || (!containsDisabled && !isAllSelected),
onClick: handleEnableAction,
toolTipContent: missingActionPrivileges ? i18n.EDIT_RULE_SETTINGS_TOOLTIP : undefined,
toolTipContent: missingActionPrivileges ? i18n.LACK_OF_KIBANA_PRIVILEGES : undefined,
toolTipPosition: 'right',
icon: undefined,
},
Expand All @@ -342,7 +342,7 @@ export const useBulkActions = ({
'data-test-subj': 'duplicateRuleBulk',
disabled: isEditDisabled,
onClick: handleDuplicateAction,
toolTipContent: missingActionPrivileges ? i18n.EDIT_RULE_SETTINGS_TOOLTIP : undefined,
toolTipContent: missingActionPrivileges ? i18n.LACK_OF_KIBANA_PRIVILEGES : undefined,
toolTipPosition: 'right',
icon: undefined,
},
Expand All @@ -366,7 +366,7 @@ export const useBulkActions = ({
'data-test-subj': 'addRuleActionsBulk',
disabled: !hasActionsPrivileges || isEditDisabled,
onClick: handleBulkEdit(BulkActionEditType.add_rule_actions),
toolTipContent: !hasActionsPrivileges ? i18n.EDIT_RULE_SETTINGS_TOOLTIP : undefined,
toolTipContent: !hasActionsPrivileges ? i18n.LACK_OF_KIBANA_PRIVILEGES : undefined,
toolTipPosition: 'right',
icon: undefined,
},
Expand All @@ -376,7 +376,7 @@ export const useBulkActions = ({
'data-test-subj': 'setScheduleBulk',
disabled: isEditDisabled,
onClick: handleBulkEdit(BulkActionEditType.set_schedule),
toolTipContent: missingActionPrivileges ? i18n.EDIT_RULE_SETTINGS_TOOLTIP : undefined,
toolTipContent: missingActionPrivileges ? i18n.LACK_OF_KIBANA_PRIVILEGES : undefined,
toolTipPosition: 'right',
icon: undefined,
},
Expand All @@ -386,7 +386,7 @@ export const useBulkActions = ({
'data-test-subj': 'applyTimelineTemplateBulk',
disabled: isEditDisabled,
onClick: handleBulkEdit(BulkActionEditType.set_timeline),
toolTipContent: missingActionPrivileges ? i18n.EDIT_RULE_SETTINGS_TOOLTIP : undefined,
toolTipContent: missingActionPrivileges ? i18n.LACK_OF_KIBANA_PRIVILEGES : undefined,
toolTipPosition: 'right',
icon: undefined,
},
Expand All @@ -405,7 +405,7 @@ export const useBulkActions = ({
disabled:
missingActionPrivileges || containsLoading || (!containsEnabled && !isAllSelected),
onClick: handleDisableActions,
toolTipContent: missingActionPrivileges ? i18n.EDIT_RULE_SETTINGS_TOOLTIP : undefined,
toolTipContent: missingActionPrivileges ? i18n.LACK_OF_KIBANA_PRIVILEGES : undefined,
toolTipPosition: 'right',
icon: undefined,
},
Expand Down Expand Up @@ -439,7 +439,7 @@ export const useBulkActions = ({
'data-test-subj': 'addTagsBulkEditRule',
onClick: handleBulkEdit(BulkActionEditType.add_tags),
disabled: isEditDisabled,
toolTipContent: missingActionPrivileges ? i18n.EDIT_RULE_SETTINGS_TOOLTIP : undefined,
toolTipContent: missingActionPrivileges ? i18n.LACK_OF_KIBANA_PRIVILEGES : undefined,
toolTipPosition: 'right',
},
{
Expand All @@ -448,7 +448,7 @@ export const useBulkActions = ({
'data-test-subj': 'deleteTagsBulkEditRule',
onClick: handleBulkEdit(BulkActionEditType.delete_tags),
disabled: isEditDisabled,
toolTipContent: missingActionPrivileges ? i18n.EDIT_RULE_SETTINGS_TOOLTIP : undefined,
toolTipContent: missingActionPrivileges ? i18n.LACK_OF_KIBANA_PRIVILEGES : undefined,
toolTipPosition: 'right',
},
],
Expand All @@ -463,7 +463,7 @@ export const useBulkActions = ({
'data-test-subj': 'addIndexPatternsBulkEditRule',
onClick: handleBulkEdit(BulkActionEditType.add_index_patterns),
disabled: isEditDisabled,
toolTipContent: missingActionPrivileges ? i18n.EDIT_RULE_SETTINGS_TOOLTIP : undefined,
toolTipContent: missingActionPrivileges ? i18n.LACK_OF_KIBANA_PRIVILEGES : undefined,
toolTipPosition: 'right',
},
{
Expand All @@ -472,7 +472,7 @@ export const useBulkActions = ({
'data-test-subj': 'deleteIndexPatternsBulkEditRule',
onClick: handleBulkEdit(BulkActionEditType.delete_index_patterns),
disabled: isEditDisabled,
toolTipContent: missingActionPrivileges ? i18n.EDIT_RULE_SETTINGS_TOOLTIP : undefined,
toolTipContent: missingActionPrivileges ? i18n.LACK_OF_KIBANA_PRIVILEGES : undefined,
toolTipPosition: 'right',
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const getRulesTableActions = ({
'data-test-subj': 'editRuleAction',
description: i18n.EDIT_RULE_SETTINGS,
name: !actionsPrivileges ? (
<EuiToolTip position="left" content={i18n.EDIT_RULE_SETTINGS_TOOLTIP}>
<EuiToolTip position="left" content={i18n.LACK_OF_KIBANA_PRIVILEGES}>
<>{i18n.EDIT_RULE_SETTINGS}</>
</EuiToolTip>
) : (
Expand All @@ -59,7 +59,7 @@ export const getRulesTableActions = ({
description: i18n.DUPLICATE_RULE,
icon: 'copy',
name: !actionsPrivileges ? (
<EuiToolTip position="left" content={i18n.EDIT_RULE_SETTINGS_TOOLTIP}>
<EuiToolTip position="left" content={i18n.LACK_OF_KIBANA_PRIVILEGES}>
<>{i18n.DUPLICATE_RULE}</>
</EuiToolTip>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,12 @@ const RuleDetailsPageComponent: React.FC<DetectionEngineComponentProps> = ({
<EuiFlexItem grow={false}>
<EuiToolTip
position="top"
content={getToolTipContent(rule, hasMlPermissions, hasActionsPrivileges)}
content={getToolTipContent(
rule,
hasMlPermissions,
hasActionsPrivileges,
canUserCRUD
)}
>
<EuiFlexGroup>
<RuleSwitch
Expand Down Expand Up @@ -721,7 +726,8 @@ const RuleDetailsPageComponent: React.FC<DetectionEngineComponentProps> = ({
disabledReason={getToolTipContent(
rule,
hasMlPermissions,
hasActionsPrivileges
hasActionsPrivileges,
canUserCRUD
)}
/>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,20 @@ export const EDIT_RULE_SETTINGS = i18n.translate(
}
);

export const EDIT_RULE_SETTINGS_TOOLTIP = i18n.translate(
'xpack.securitySolution.detectionEngine.rules.allRules.actions.editRuleSettingsToolTip',
export const LACK_OF_KIBANA_PRIVILEGES = i18n.translate(
'xpack.securitySolution.detectionEngine.rules.allRules.actions.lackOfKibanaPrivileges',
{
defaultMessage: 'You do not have Kibana Actions privileges',
}
);

export const LACK_OF_RULE_EDITING_PRIVILEGES = i18n.translate(
'xpack.securitySolution.detectionEngine.rules.allRules.actions.lackOfRuleEditingPrivileges',
{
defaultMessage: 'You do not have rule editing privileges',
}
);

export const DUPLICATE_RULE = i18n.translate(
'xpack.securitySolution.detectionEngine.rules.allRules.actions.duplicateRuleDescription',
{
Expand Down

0 comments on commit 83b355e

Please sign in to comment.