GUI Tool endpoints: allow edit additional configuration for admin & advanced users only
*/
import React from 'react';
-import {observer} from 'mobx-react';
+import {inject, observer} from 'mobx-react';
+import {computed} from 'mobx';
import PropTypes from 'prop-types';
import {
Button,
@@ -31,6 +32,7 @@ import CodeEditor from '../../special/CodeEditor';
import styles from '../Tools.css';
import '../../../staticStyles/EndpointInput.css';
+@inject('authenticatedUserInfo')
@observer
export default class EndpointInput extends React.Component {
static propTypes = {
@@ -46,6 +48,21 @@ export default class EndpointInput extends React.Component {
validation: {}
};
+ @computed
+ get additionalConfigurationEditable () {
+ const {
+ authenticatedUserInfo
+ } = this.props;
+ if (authenticatedUserInfo.loaded) {
+ const {
+ admin,
+ roles = []
+ } = authenticatedUserInfo.value;
+ return admin || !!roles.find(o => /^ROLE_ADVANCED_USER$/i.test(o.name));
+ }
+ return false;
+ }
+
validatePort = (port) => {
if (!port) {
return 'Port is required';
@@ -460,7 +477,7 @@ export default class EndpointInput extends React.Component {
</Row>
<Row type="flex" className={styles.endpointCodeEditorContainer}>
<CodeEditor
- readOnly={this.props.disabled}
+ readOnly={this.props.disabled || !this.additionalConfigurationEditable}
ref={this.initializeEditor}
placeholder="Add any additional nginx configuration here"
lineNumbers={false}
