-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[7.x] [Security Solution] [Detections] Disable edit button when user …
…does not have actions privileges w/ rule + actions (#80220) (#81055) * disable edit button only when there is an action present on the rule to be edited, but the user attempting the edit does not have actions privileges * adds tooltip to explain why the edit rule button is disabled * prevent user from editing rules with actions on the all rules table * adds tooltip to appear on all rules table * updates tests for missing params and missing mock of useKibana * disable activate switch on all rules table and rule details page * remove as casting in favor of a boolean type guard to ensure actions.show capabilities are a boolean even though tye are typed as a boolean | Record * disable duplicate rule functionality for rules with actions * fix positioning of tooltips and add tooltip to rule duplicate button in overflow button * update tests * WIP - display bulk actions dropdown options as disabled + add tooltips describing why they are disabled * add eui tool tip as child of of each context menu item * PR feedback and utilize map of rule ids to rules to replace usage of array.finds * update snapshot * fix mocks * fix mocks * update wording with feedback from design team Co-authored-by: Patryk Kopycinski <contact@patrykkopycinski.com> Co-authored-by: Patryk Kopycinski <contact@patrykkopycinski.com>
- Loading branch information
1 parent
61a8146
commit 075efe4
Showing
11 changed files
with
368 additions
and
75 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
x-pack/plugins/security_solution/public/common/utils/privileges/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { Rule } from '../../../detections/containers/detection_engine/rules'; | ||
import * as i18n from '../../../detections/pages/detection_engine/rules/translations'; | ||
import { isMlRule } from '../../../../common/machine_learning/helpers'; | ||
import * as detectionI18n from '../../../detections/pages/detection_engine/translations'; | ||
|
||
export const isBoolean = (obj: unknown): obj is boolean => typeof obj === 'boolean'; | ||
|
||
export const canEditRuleWithActions = ( | ||
rule: Rule | null | undefined, | ||
privileges: | ||
| boolean | ||
| Readonly<{ | ||
[x: string]: boolean; | ||
}> | ||
): boolean => { | ||
if (rule == null) { | ||
return true; | ||
} | ||
if (rule.actions?.length > 0 && isBoolean(privileges)) { | ||
return privileges; | ||
} | ||
return true; | ||
}; | ||
|
||
export const getToolTipContent = ( | ||
rule: Rule | null | undefined, | ||
hasMlPermissions: boolean, | ||
hasReadActionsPrivileges: | ||
| boolean | ||
| Readonly<{ | ||
[x: string]: boolean; | ||
}> | ||
): 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; | ||
} else { | ||
return undefined; | ||
} | ||
}; |
9 changes: 8 additions & 1 deletion
9
...ublic/detections/components/rules/rule_actions_overflow/__snapshots__/index.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.