Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution] [Detections] Only display actions options if user has "read" privileges #78812

Merged
merged 9 commits into from
Oct 2, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ jest.mock('../../../../common/lib/kibana', () => ({
services: {
application: {
getUrlForApp: jest.fn(),
capabilities: {
siem: {
crud: true,
},
actions: {
read: true,
},
},
},
triggers_actions_ui: {
actionTypeRegistry: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
EuiFlexItem,
EuiButton,
EuiSpacer,
EuiText,
} from '@elastic/eui';
import { findIndex } from 'lodash/fp';
import React, { FC, memo, useCallback, useEffect, useMemo } from 'react';
Expand Down Expand Up @@ -141,37 +142,61 @@ const StepRuleActionsComponent: FC<StepRuleActionsProps> = ({
[isLoading, throttleOptions]
);

return isReadOnlyView ? (
<StepContentWrapper addPadding={addPadding}>
<StepRuleDescription schema={schema} data={initialState} columns="single" />
</StepContentWrapper>
if (isReadOnlyView) {
return (
<StepContentWrapper addPadding={addPadding}>
<StepRuleDescription schema={schema} data={initialState} columns="single" />
</StepContentWrapper>
);
}

const displayActionsOptions =
throttle !== stepActionsDefaultValue.throttle ? (
<>
<EuiSpacer />
<UseField
path="actions"
component={RuleActionsField}
componentProps={{
messageVariables: actionMessageParams,
}}
/>
</>
) : (
<UseField path="actions" component={GhostFormField} />
);

// only display the actions dropdown if the user has "read" privileges for actions
const displayActionsDropDown = application.capabilities.actions.show ? (
<>
<UseField
path="throttle"
component={ThrottleSelectField}
componentProps={throttleFieldComponentProps}
/>
{displayActionsOptions}
<UseField path="kibanaSiemAppUrl" component={GhostFormField} />
<UseField path="enabled" component={GhostFormField} />
</>
) : (
<>
<EuiText>{I18n.NO_ACTIONS_READ_PERMISSIONS}</EuiText>
<UseField
path="throttle"
componentProps={throttleFieldComponentProps}
component={GhostFormField}
/>
<UseField path="actions" component={GhostFormField} />
<UseField path="kibanaSiemAppUrl" component={GhostFormField} />
<UseField path="enabled" component={GhostFormField} />
</>
);

return (
<>
<StepContentWrapper addPadding={!isUpdateView}>
<Form form={form} data-test-subj="stepRuleActions">
<EuiForm>
<UseField
path="throttle"
component={ThrottleSelectField}
componentProps={throttleFieldComponentProps}
/>
{throttle !== stepActionsDefaultValue.throttle ? (
<>
<EuiSpacer />
<UseField
path="actions"
component={RuleActionsField}
componentProps={{
messageVariables: actionMessageParams,
}}
/>
</>
) : (
<UseField path="actions" component={GhostFormField} />
)}
<UseField path="kibanaSiemAppUrl" component={GhostFormField} />
<UseField path="enabled" component={GhostFormField} />
</EuiForm>
<EuiForm>{displayActionsDropDown}</EuiForm>
</Form>
</StepContentWrapper>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ export const NO_CONNECTOR_SELECTED = i18n.translate(
}
);

export const NO_ACTIONS_READ_PERMISSIONS = i18n.translate(
'xpack.securitySolution.detectionEngine.createRule.stepRuleActions.noReadActionsPrivileges',
{
defaultMessage:
'Cannot create rule actions. You do not have "Read" permissions for the "Actions" plugin.',
}
);

export const INVALID_MUSTACHE_TEMPLATE = (paramKey: string) =>
i18n.translate(
'xpack.securitySolution.detectionEngine.createRule.stepRuleActions.invalidMustacheTemplateErrorMessage',
Expand Down