From b32b507138dfd7fc93681d1c6a6c3f288ae256a1 Mon Sep 17 00:00:00 2001 From: Seth Muthukaruppan Date: Thu, 18 Apr 2024 00:58:10 +0000 Subject: [PATCH] check if rbac is enabled Signed-off-by: Seth Muthukaruppan --- .../containers/CreateMonitor/CreateMonitor.js | 39 ++++++++++++++++++- .../containers/MonitorRoles/MonitorRoles.js | 22 +++++++++-- .../MonitorSecurity/MonitorSecurity.js | 1 - 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/public/pages/CreateMonitor/containers/CreateMonitor/CreateMonitor.js b/public/pages/CreateMonitor/containers/CreateMonitor/CreateMonitor.js index 2c2abbf4b..915f8894a 100644 --- a/public/pages/CreateMonitor/containers/CreateMonitor/CreateMonitor.js +++ b/public/pages/CreateMonitor/containers/CreateMonitor/CreateMonitor.js @@ -29,6 +29,7 @@ import { RECOMMENDED_DURATION, } from '../../components/QueryPerformance/QueryPerformance'; import MonitorSecurity from '../MonitorSecurity'; +import { FILTER_BY_BACKEND_ROLES_SETTING_PATH } from './utils/constants'; export default class CreateMonitor extends Component { static defaultProps = { @@ -58,16 +59,47 @@ export default class CreateMonitor extends Component { triggerToEdit, createModalOpen: false, formikBag: undefined, + filterByBackendRolesEnabled: false, }; this.onCancel = this.onCancel.bind(this); this.onSubmit = this.onSubmit.bind(this); this.evaluateSubmission = this.evaluateSubmission.bind(this); + this.getSettings = this.getSettings.bind(this); + } + + async getSettings() { + try { + const { httpClient } = this.props; + const response = await httpClient.get('../api/alerting/_settings'); + if (response.ok) { + const { defaults, transient, persistent } = response.resp; + let filterByBackendRolesEnabled = _.get( + // If present, take the 'transient' setting. + transient, + FILTER_BY_BACKEND_ROLES_SETTING_PATH, + // Else take the 'persistent' setting. + _.get( + persistent, + FILTER_BY_BACKEND_ROLES_SETTING_PATH, + // Else take the 'default' setting. + _.get(defaults, FILTER_BY_BACKEND_ROLES_SETTING_PATH, false) + ) + ); + // Boolean settings are returned as strings (e.g., `"true"`, and `"false"`). Constructing boolean value from the string. + if (typeof filterByBackendRolesEnabled === 'string') + filterByBackendRolesEnabled = JSON.parse(filterByBackendRolesEnabled); + this.setState({ filterByBackendRolesEnabled: filterByBackendRolesEnabled }); + } + } catch (e) { + console.log('Error while retrieving settings', e); + } } componentDidMount() { const { httpClient } = this.props; + this.getSettings(); const updatePlugins = async () => { const newPlugins = await getPlugins(httpClient); this.setState({ plugins: newPlugins }); @@ -163,7 +195,7 @@ export default class CreateMonitor extends Component { isDarkMode, notificationService, } = this.props; - const { createModalOpen, initialValues, plugins } = this.state; + const { createModalOpen, initialValues, plugins, filterByBackendRolesEnabled } = this.state; return (
@@ -205,6 +237,11 @@ export default class CreateMonitor extends Component { httpClient={httpClient} errors={errors} /> + + ) : null} + + {isComposite && filterByBackendRolesEnabled ? ( + <> diff --git a/public/pages/CreateMonitor/containers/MonitorRoles/MonitorRoles.js b/public/pages/CreateMonitor/containers/MonitorRoles/MonitorRoles.js index e34c3ff7b..a8d99e1eb 100644 --- a/public/pages/CreateMonitor/containers/MonitorRoles/MonitorRoles.js +++ b/public/pages/CreateMonitor/containers/MonitorRoles/MonitorRoles.js @@ -6,7 +6,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import _ from 'lodash'; -import { EuiHealth, EuiHighlight } from '@elastic/eui'; +import { EuiHealth, EuiHighlight, EuiText, EuiLink } from '@elastic/eui'; import { FormikComboBox } from '../../../../components/FormControls'; import { createReasonableWait } from '../MonitorIndex/utils/helpers'; @@ -93,8 +93,24 @@ class MonitorRoles extends React.Component { name="roles" formRow rowProps={{ - label: 'Backend roles', - helpText: 'You can optionally assign one or more backend roles to the monitor', + label: ( +
+ + Backend roles + - optional + + + Specify role-based access control (RBAC) backend roles.{' '} + + Learn more + + +
+ ), style: { paddingLeft: '10px' }, }} inputProps={{ diff --git a/public/pages/CreateMonitor/containers/MonitorSecurity/MonitorSecurity.js b/public/pages/CreateMonitor/containers/MonitorSecurity/MonitorSecurity.js index 949d71768..97bb0c34e 100644 --- a/public/pages/CreateMonitor/containers/MonitorSecurity/MonitorSecurity.js +++ b/public/pages/CreateMonitor/containers/MonitorSecurity/MonitorSecurity.js @@ -10,7 +10,6 @@ import MonitorRoles from '../MonitorRoles'; import ContentPanel from '../../../../components/ContentPanel'; const propTypes = { - values: PropTypes.object.isRequired, httpClient: PropTypes.object.isRequired, isMinimal: PropTypes.bool, };