mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-12 13:48:35 +02:00
fix: add permissions for tag-types and project
This commit is contained in:
parent
f669f96d49
commit
3ad447b7d9
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
.supporting {
|
.supporting {
|
||||||
font-size: var(--caption-size);
|
font-size: var(--caption-size);
|
||||||
max-width: 450px;
|
max-width: 800px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
@ -40,7 +40,7 @@
|
|||||||
.inset {
|
.inset {
|
||||||
background-color: rgb(250, 250, 250);
|
background-color: rgb(250, 250, 250);
|
||||||
padding: var(--card-padding);
|
padding: var(--card-padding);
|
||||||
max-width: 450px;
|
max-width: 650px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chip {
|
.chip {
|
||||||
@ -57,7 +57,7 @@
|
|||||||
|
|
||||||
.formContainer {
|
.formContainer {
|
||||||
margin-bottom: 1.5rem;
|
margin-bottom: 1.5rem;
|
||||||
max-width: 350px;
|
max-width: 650px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.formContainer > *, .inset > * {
|
.formContainer > *, .inset > * {
|
||||||
|
@ -7,8 +7,13 @@ import classnames from 'classnames';
|
|||||||
import { FormButtons, styles as commonStyles } from '../common';
|
import { FormButtons, styles as commonStyles } from '../common';
|
||||||
import { trim } from '../common/util';
|
import { trim } from '../common/util';
|
||||||
import PageContent from '../common/PageContent/PageContent';
|
import PageContent from '../common/PageContent/PageContent';
|
||||||
|
import AccessContext from '../../contexts/AccessContext';
|
||||||
|
import ConditionallyRender from '../common/ConditionallyRender';
|
||||||
|
import { CREATE_PROJECT } from '../AccessProvider/permissions';
|
||||||
|
|
||||||
class AddContextComponent extends Component {
|
class AddContextComponent extends Component {
|
||||||
|
static contextType = AccessContext;
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
@ -60,6 +65,7 @@ class AddContextComponent extends Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { project, errors } = this.state;
|
const { project, errors } = this.state;
|
||||||
|
const { hasAccess } = this.context;
|
||||||
const { editMode } = this.props;
|
const { editMode } = this.props;
|
||||||
const submitText = editMode ? 'Update' : 'Create';
|
const submitText = editMode ? 'Update' : 'Create';
|
||||||
|
|
||||||
@ -110,9 +116,12 @@ class AddContextComponent extends Component {
|
|||||||
value={project.description}
|
value={project.description}
|
||||||
onChange={v => this.setValue('description', v.target.value)}
|
onChange={v => this.setValue('description', v.target.value)}
|
||||||
/>
|
/>
|
||||||
|
<ConditionallyRender condition={hasAccess(CREATE_PROJECT)} show={
|
||||||
<div className={styles.formButtons}>
|
<div className={styles.formButtons}>
|
||||||
<FormButtons submitText={submitText} onCancel={this.onCancel} />
|
<FormButtons submitText={submitText} onCancel={this.onCancel} />
|
||||||
</div>
|
</div>
|
||||||
|
} />
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
</PageContent>
|
</PageContent>
|
||||||
);
|
);
|
||||||
|
@ -72,9 +72,6 @@ exports[`it supports editMode 1`] = `
|
|||||||
</span>
|
</span>
|
||||||
Update
|
Update
|
||||||
</span>
|
</span>
|
||||||
<span
|
|
||||||
className="MuiTouchRipple-root"
|
|
||||||
/>
|
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
@ -100,9 +97,6 @@ exports[`it supports editMode 1`] = `
|
|||||||
>
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</span>
|
</span>
|
||||||
<span
|
|
||||||
className="MuiTouchRipple-root"
|
|
||||||
/>
|
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -217,3 +211,48 @@ exports[`renders correctly for creating 1`] = `
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`renders correctly for creating without permissions 1`] = `
|
||||||
|
<div
|
||||||
|
className="MuiPaper-root MuiPaper-elevation1 MuiPaper-rounded"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="makeStyles-headerContainer-1"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="makeStyles-headerTitleContainer-5"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className=""
|
||||||
|
>
|
||||||
|
<h2
|
||||||
|
className="MuiTypography-root makeStyles-headerTitle-6 MuiTypography-h2"
|
||||||
|
>
|
||||||
|
Create Tag type
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="makeStyles-bodyContainer-2"
|
||||||
|
>
|
||||||
|
<section
|
||||||
|
className="contentSpacing tagTypeContainer"
|
||||||
|
>
|
||||||
|
<h6
|
||||||
|
className="MuiTypography-root MuiTypography-subtitle1"
|
||||||
|
>
|
||||||
|
Tag types allows you to group tags together in the management UI
|
||||||
|
</h6>
|
||||||
|
<form
|
||||||
|
className="addTagTypeForm contentSpacing"
|
||||||
|
onSubmit={[Function]}
|
||||||
|
>
|
||||||
|
<span>
|
||||||
|
You do not have permissions to save.
|
||||||
|
</span>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
@ -3,6 +3,9 @@ import { ThemeProvider } from '@material-ui/core';
|
|||||||
import TagTypes from '../form-tag-type-component';
|
import TagTypes from '../form-tag-type-component';
|
||||||
import renderer from 'react-test-renderer';
|
import renderer from 'react-test-renderer';
|
||||||
import theme from '../../../themes/main-theme';
|
import theme from '../../../themes/main-theme';
|
||||||
|
import AccessProvider from '../../AccessProvider/AccessProvider';
|
||||||
|
import { createFakeStore } from '../../../accessStoreFake';
|
||||||
|
import { CREATE_TAG_TYPE, UPDATE_TAG_TYPE } from '../../AccessProvider/permissions';
|
||||||
|
|
||||||
jest.mock('@material-ui/core/TextField');
|
jest.mock('@material-ui/core/TextField');
|
||||||
|
|
||||||
@ -10,6 +13,7 @@ test('renders correctly for creating', () => {
|
|||||||
const tree = renderer
|
const tree = renderer
|
||||||
.create(
|
.create(
|
||||||
<ThemeProvider theme={theme}>
|
<ThemeProvider theme={theme}>
|
||||||
|
<AccessProvider store={createFakeStore([{permission: CREATE_TAG_TYPE}])}>
|
||||||
<TagTypes
|
<TagTypes
|
||||||
history={{}}
|
history={{}}
|
||||||
title="Add tag type"
|
title="Add tag type"
|
||||||
@ -19,6 +23,28 @@ test('renders correctly for creating', () => {
|
|||||||
editMode={false}
|
editMode={false}
|
||||||
submit={jest.fn()}
|
submit={jest.fn()}
|
||||||
/>
|
/>
|
||||||
|
</AccessProvider>
|
||||||
|
</ThemeProvider>
|
||||||
|
)
|
||||||
|
.toJSON();
|
||||||
|
expect(tree).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('renders correctly for creating without permissions', () => {
|
||||||
|
const tree = renderer
|
||||||
|
.create(
|
||||||
|
<ThemeProvider theme={theme}>
|
||||||
|
<AccessProvider store={createFakeStore([])}>
|
||||||
|
<TagTypes
|
||||||
|
history={{}}
|
||||||
|
title="Add tag type"
|
||||||
|
createTagType={jest.fn()}
|
||||||
|
validateName={() => Promise.resolve(true)}
|
||||||
|
tagType={{ name: '', description: '', icon: '' }}
|
||||||
|
editMode={false}
|
||||||
|
submit={jest.fn()}
|
||||||
|
/>
|
||||||
|
</AccessProvider>
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
)
|
)
|
||||||
.toJSON();
|
.toJSON();
|
||||||
@ -29,6 +55,7 @@ test('it supports editMode', () => {
|
|||||||
const tree = renderer
|
const tree = renderer
|
||||||
.create(
|
.create(
|
||||||
<ThemeProvider theme={theme}>
|
<ThemeProvider theme={theme}>
|
||||||
|
<AccessProvider store={createFakeStore([{permission: UPDATE_TAG_TYPE}])}>
|
||||||
<TagTypes
|
<TagTypes
|
||||||
history={{}}
|
history={{}}
|
||||||
title="Add tag type"
|
title="Add tag type"
|
||||||
@ -38,6 +65,7 @@ test('it supports editMode', () => {
|
|||||||
editMode
|
editMode
|
||||||
submit={jest.fn()}
|
submit={jest.fn()}
|
||||||
/>
|
/>
|
||||||
|
</AccessProvider>
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
)
|
)
|
||||||
.toJSON();
|
.toJSON();
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useContext, useState } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
|
|
||||||
@ -8,6 +8,9 @@ import { Typography, TextField } from '@material-ui/core';
|
|||||||
|
|
||||||
import styles from './TagType.module.scss';
|
import styles from './TagType.module.scss';
|
||||||
import commonStyles from '../common/common.module.scss';
|
import commonStyles from '../common/common.module.scss';
|
||||||
|
import AccessContext from '../../contexts/AccessContext';
|
||||||
|
import { CREATE_TAG_TYPE, UPDATE_TAG_TYPE } from '../AccessProvider/permissions';
|
||||||
|
import ConditionallyRender from '../common/ConditionallyRender';
|
||||||
|
|
||||||
const AddTagTypeComponent = ({ tagType, validateName, submit, history, editMode }) => {
|
const AddTagTypeComponent = ({ tagType, validateName, submit, history, editMode }) => {
|
||||||
const [tagTypeName, setTagTypeName] = useState(tagType.name || '');
|
const [tagTypeName, setTagTypeName] = useState(tagType.name || '');
|
||||||
@ -17,6 +20,7 @@ const AddTagTypeComponent = ({ tagType, validateName, submit, history, editMode
|
|||||||
name: undefined,
|
name: undefined,
|
||||||
description: undefined,
|
description: undefined,
|
||||||
});
|
});
|
||||||
|
const { hasAccess } = useContext(AccessContext);
|
||||||
|
|
||||||
const onValidateName = async evt => {
|
const onValidateName = async evt => {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
@ -80,9 +84,11 @@ const AddTagTypeComponent = ({ tagType, validateName, submit, history, editMode
|
|||||||
variant="outlined"
|
variant="outlined"
|
||||||
size="small"
|
size="small"
|
||||||
/>
|
/>
|
||||||
|
<ConditionallyRender condition={hasAccess(editMode ? UPDATE_TAG_TYPE : CREATE_TAG_TYPE)} show={
|
||||||
<div className={styles.formButtons}>
|
<div className={styles.formButtons}>
|
||||||
<FormButtons submitText={submitText} onCancel={onCancel} />
|
<FormButtons submitText={submitText} onCancel={onCancel} />
|
||||||
</div>
|
</div>
|
||||||
|
} elseShow={<span>You do not have permissions to save.</span>} />
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
</PageContent>
|
</PageContent>
|
||||||
|
Loading…
Reference in New Issue
Block a user