Skip to content

Commit 9372b2a

Browse files
committed
privilege check
1 parent df20d58 commit 9372b2a

5 files changed

Lines changed: 28 additions & 8 deletions

File tree

x-pack/plugins/transform/public/app/lib/authorization/components/authorization_provider.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ interface Authorization {
2020
capabilities: Capabilities;
2121
}
2222

23-
const initialCapabalities: Capabilities = {
23+
const initialCapabilities: Capabilities = {
2424
canGetTransform: false,
2525
canDeleteTransform: false,
2626
canPreviewTransform: false,
2727
canCreateTransform: false,
2828
canStartStopTransform: false,
29+
canCreateTransformAlerts: false,
30+
canUseTransformAlerts: false,
2931
};
3032

3133
const initialValue: Authorization = {
@@ -35,7 +37,7 @@ const initialValue: Authorization = {
3537
hasAllPrivileges: false,
3638
missingPrivileges: {},
3739
},
38-
capabilities: initialCapabalities,
40+
capabilities: initialCapabilities,
3941
};
4042

4143
export const AuthorizationContext = createContext<Authorization>({ ...initialValue });
@@ -58,7 +60,7 @@ export const AuthorizationProvider = ({ privilegesEndpoint, children }: Props) =
5860
const value = {
5961
isLoading,
6062
privileges: isLoading ? { ...initialValue.privileges } : privilegesData,
61-
capabilities: { ...initialCapabalities },
63+
capabilities: { ...initialCapabilities },
6264
apiError: error ? (error as Error) : null,
6365
};
6466

@@ -85,6 +87,10 @@ export const AuthorizationProvider = ({ privilegesEndpoint, children }: Props) =
8587
hasPrivilege(['cluster', 'cluster:admin/transform/start_task']) &&
8688
hasPrivilege(['cluster', 'cluster:admin/transform/stop']);
8789

90+
value.capabilities.canCreateTransformAlerts = value.capabilities.canCreateTransform;
91+
92+
value.capabilities.canUseTransformAlerts = value.capabilities.canGetTransform;
93+
8894
return (
8995
<AuthorizationContext.Provider value={{ ...value }}>{children}</AuthorizationContext.Provider>
9096
);

x-pack/plugins/transform/public/app/lib/authorization/components/common.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export interface Capabilities {
1616
canPreviewTransform: boolean;
1717
canCreateTransform: boolean;
1818
canStartStopTransform: boolean;
19+
canCreateTransformAlerts: boolean;
20+
canUseTransformAlerts: boolean;
1921
}
2022

2123
export type Privilege = [string, string];
@@ -67,6 +69,14 @@ export function createCapabilityFailureMessage(
6769
defaultMessage: 'You do not have permission to create transforms.',
6870
});
6971
break;
72+
case 'canCreateTransformAlerts':
73+
message = i18n.translate(
74+
'xpack.transform.capability.noPermission.canCreateTransformAlertsTooltip',
75+
{
76+
defaultMessage: 'You do not have permission to create transform alert rules.',
77+
}
78+
);
79+
break;
7080
case 'canStartStopTransform':
7181
message = i18n.translate(
7282
'xpack.transform.capability.noPermission.startOrStopTransformTooltip',

x-pack/plugins/transform/public/app/sections/transform_management/components/action_create_alert/create_alert_rule_action_name.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ export const crateAlertRuleActionNameText = i18n.translate(
2525
export const CreateAlertRuleActionName: FC<CreateAlertRuleActionProps> = ({ disabled }) => {
2626
if (disabled) {
2727
return (
28-
<EuiToolTip position="top" content={createCapabilityFailureMessage('canStartStopTransform')}>
28+
<EuiToolTip
29+
position="top"
30+
content={createCapabilityFailureMessage('canCreateTransformAlerts')}
31+
>
2932
<>{crateAlertRuleActionNameText}</>
3033
</EuiToolTip>
3134
);

x-pack/plugins/transform/public/app/sections/transform_management/components/action_create_alert/use_create_alert_rule_action.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { isContinuousTransform } from '../../../../../../common/types/transform'
1717

1818
export type CreateAlertRuleAction = ReturnType<typeof useCreateAlertRuleAction>;
1919
export const useCreateAlertRuleAction = (forceDisable: boolean) => {
20-
const { canCreateTransform } = useContext(AuthorizationContext).capabilities;
20+
const { canCreateTransformAlerts } = useContext(AuthorizationContext).capabilities;
2121
const { setCreateAlertRule } = useAlertRuleFlyout();
2222

2323
const clickHandler = useCallback(
@@ -30,17 +30,17 @@ export const useCreateAlertRuleAction = (forceDisable: boolean) => {
3030
const action: TransformListAction = useMemo(
3131
() => ({
3232
name: (item: TransformListRow) => (
33-
<CreateAlertRuleActionName disabled={!canCreateTransform} />
33+
<CreateAlertRuleActionName disabled={!canCreateTransformAlerts} />
3434
),
3535
available: (item: TransformListRow) => isContinuousTransform(item.config),
36-
enabled: () => canCreateTransform && !forceDisable,
36+
enabled: () => canCreateTransformAlerts && !forceDisable,
3737
description: crateAlertRuleActionNameText,
3838
type: 'icon',
3939
icon: 'bell',
4040
onClick: clickHandler,
4141
'data-test-subj': 'transformActionCreateAlertRule',
4242
}),
43-
[canCreateTransform, forceDisable, clickHandler]
43+
[canCreateTransformAlerts, forceDisable, clickHandler]
4444
);
4545

4646
return { action };

x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/use_actions.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe('Transform: Transform List Actions', () => {
2727
// in the runtime result here anyway.
2828
expect(actions.map((a: any) => a['data-test-subj'])).toStrictEqual([
2929
'transformActionDiscover',
30+
'transformActionCreateAlertRule',
3031
'transformActionStart',
3132
'transformActionStop',
3233
'transformActionEdit',

0 commit comments

Comments
 (0)