-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
capabilities.ts
48 lines (40 loc) · 1.81 KB
/
capabilities.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { RuleType } from '../../types';
import { InitialRule } from '../sections/rule_form/rule_reducer';
/**
* NOTE: Applications that want to show the alerting UIs will need to add
* check against their features here until we have a better solution. This
* will possibly go away with https://github.com/elastic/kibana/issues/52300.
*/
type Capabilities = Record<string, any>;
export const hasShowActionsCapability = (capabilities: Capabilities) => capabilities?.actions?.show;
export const hasSaveActionsCapability = (capabilities: Capabilities) => capabilities?.actions?.save;
export const hasExecuteActionsCapability = (capabilities: Capabilities, actionTypeId?: string) =>
actionTypeId === '.sentinelone' ? capabilities?.actions?.save : capabilities?.actions?.execute;
export const hasDeleteActionsCapability = (capabilities: Capabilities) =>
capabilities?.actions?.delete;
export function hasAllPrivilege(
ruleConsumer: InitialRule['consumer'],
ruleType?: RuleType
): boolean {
return ruleType?.authorizedConsumers[ruleConsumer]?.all ?? false;
}
export function hasAllPrivilegeWithProducerCheck(
ruleConsumer: InitialRule['consumer'],
ruleType?: RuleType
): boolean {
if (ruleConsumer === ruleType?.producer) {
return true;
}
return hasAllPrivilege(ruleConsumer, ruleType);
}
export function hasReadPrivilege(rule: InitialRule, ruleType?: RuleType): boolean {
return ruleType?.authorizedConsumers[rule.consumer]?.read ?? false;
}
export const hasManageApiKeysCapability = (capabilities: Capabilities) =>
capabilities?.management?.security?.api_keys;