mirror of
https://github.com/strapi/strapi.git
synced 2025-11-25 14:41:15 +00:00
Add permissions to doc plugin
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
6e6c8c05cb
commit
4ce714c32f
@ -372,18 +372,18 @@ const data = {
|
|||||||
fields: null,
|
fields: null,
|
||||||
conditions: [],
|
conditions: [],
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// action: 'plugins::documentation.settings.update',
|
action: 'plugins::documentation.settings.update',
|
||||||
// subject: null,
|
subject: null,
|
||||||
// fields: null,
|
fields: null,
|
||||||
// conditions:[],
|
conditions: [],
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// action: 'plugins::documentation.settings.regenerate',
|
action: 'plugins::documentation.settings.regenerate',
|
||||||
// subject: null,
|
subject: null,
|
||||||
// fields: null,
|
fields: null,
|
||||||
// conditions:[],
|
conditions: [],
|
||||||
// },
|
},
|
||||||
|
|
||||||
// Upload plugin
|
// Upload plugin
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,16 +1,12 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { FormattedMessage } from 'react-intl';
|
import { FormattedMessage } from 'react-intl';
|
||||||
|
import { WithPermissions } from 'strapi-helper-plugin';
|
||||||
|
import pluginPermissions from '../../permissions';
|
||||||
import openWithNewTab from '../../utils/openWithNewTab';
|
import openWithNewTab from '../../utils/openWithNewTab';
|
||||||
import { StyledButton } from './components';
|
import { StyledButton } from './components';
|
||||||
|
|
||||||
const ButtonContainer = ({
|
const ButtonContainer = ({ currentDocVersion, isHeader, onClick, onClickDelete, version }) => {
|
||||||
currentDocVersion,
|
|
||||||
isHeader,
|
|
||||||
onClick,
|
|
||||||
onClickDelete,
|
|
||||||
version,
|
|
||||||
}) => {
|
|
||||||
if (isHeader) {
|
if (isHeader) {
|
||||||
return <div />;
|
return <div />;
|
||||||
}
|
}
|
||||||
@ -23,16 +19,17 @@ const ButtonContainer = ({
|
|||||||
>
|
>
|
||||||
<FormattedMessage id="documentation.components.Row.open" />
|
<FormattedMessage id="documentation.components.Row.open" />
|
||||||
</StyledButton>
|
</StyledButton>
|
||||||
<StyledButton
|
<WithPermissions permissions={pluginPermissions.regenerate}>
|
||||||
type="generateDocumentation"
|
<StyledButton type="generateDocumentation" onClick={() => onClick(version)}>
|
||||||
onClick={() => onClick(version)}
|
|
||||||
>
|
|
||||||
<FormattedMessage id="documentation.components.Row.regenerate" />
|
<FormattedMessage id="documentation.components.Row.regenerate" />
|
||||||
</StyledButton>
|
</StyledButton>
|
||||||
|
</WithPermissions>
|
||||||
|
<WithPermissions permissions={pluginPermissions.update}>
|
||||||
<StyledButton
|
<StyledButton
|
||||||
type={version === currentDocVersion ? '' : 'trash'}
|
type={version === currentDocVersion ? '' : 'trash'}
|
||||||
onClick={() => onClickDelete(version)}
|
onClick={() => onClickDelete(version)}
|
||||||
/>
|
/>
|
||||||
|
</WithPermissions>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Switch, Route } from 'react-router-dom';
|
import { Switch, Route } from 'react-router-dom';
|
||||||
import { NotFound, WithPagePermissions } from 'strapi-helper-plugin';
|
import { NotFound, WithPagePermissions, useUser } from 'strapi-helper-plugin';
|
||||||
// Utils
|
// Utils
|
||||||
import pluginPermissions from '../../permissions';
|
import pluginPermissions from '../../permissions';
|
||||||
import pluginId from '../../pluginId';
|
import pluginId from '../../pluginId';
|
||||||
@ -15,11 +15,17 @@ import pluginId from '../../pluginId';
|
|||||||
import HomePage from '../HomePage';
|
import HomePage from '../HomePage';
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
|
const userPermissions = useUser();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<WithPagePermissions permissions={pluginPermissions.main}>
|
<WithPagePermissions permissions={pluginPermissions.main}>
|
||||||
<div className={pluginId}>
|
<div className={pluginId}>
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route path={`/plugins/${pluginId}`} component={HomePage} exact />
|
<Route
|
||||||
|
path={`/plugins/${pluginId}`}
|
||||||
|
render={props => <HomePage {...props} userPermissions={userPermissions} />}
|
||||||
|
exact
|
||||||
|
/>
|
||||||
<Route component={NotFound} />
|
<Route component={NotFound} />
|
||||||
</Switch>
|
</Switch>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -17,9 +17,11 @@ import {
|
|||||||
LoadingIndicatorPage,
|
LoadingIndicatorPage,
|
||||||
InputsIndex as Input,
|
InputsIndex as Input,
|
||||||
GlobalContext,
|
GlobalContext,
|
||||||
|
hasPermissions,
|
||||||
} from 'strapi-helper-plugin';
|
} from 'strapi-helper-plugin';
|
||||||
|
|
||||||
import pluginId from '../../pluginId';
|
import pluginId from '../../pluginId';
|
||||||
|
import pluginPermissions from '../../permissions';
|
||||||
import getTrad from '../../utils/getTrad';
|
import getTrad from '../../utils/getTrad';
|
||||||
|
|
||||||
import Block from '../../components/Block';
|
import Block from '../../components/Block';
|
||||||
@ -41,10 +43,37 @@ import selectHomePage from './selectors';
|
|||||||
import saga from './saga';
|
import saga from './saga';
|
||||||
|
|
||||||
export class HomePage extends React.Component {
|
export class HomePage extends React.Component {
|
||||||
|
state = { canOpen: false, canUpdate: false };
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.getDocInfos();
|
this.props.getDocInfos();
|
||||||
|
this.getPermissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getPermissions = async () => {
|
||||||
|
const { userPermissions } = this.props;
|
||||||
|
|
||||||
|
const checkPermissions = async permissionName => {
|
||||||
|
const hasPermission = await hasPermissions(
|
||||||
|
userPermissions,
|
||||||
|
pluginPermissions[permissionName]
|
||||||
|
);
|
||||||
|
|
||||||
|
return hasPermission;
|
||||||
|
};
|
||||||
|
|
||||||
|
const generateArrayOfPromises = array =>
|
||||||
|
array.map(permissionName => checkPermissions(permissionName));
|
||||||
|
|
||||||
|
try {
|
||||||
|
const [canOpen, canUpdate] = await Promise.all(generateArrayOfPromises(['open', 'update']));
|
||||||
|
|
||||||
|
this.setState({ canOpen, canUpdate });
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
getRestrictedAccessValue = () => {
|
getRestrictedAccessValue = () => {
|
||||||
const { form } = this.props;
|
const { form } = this.props;
|
||||||
|
|
||||||
@ -52,8 +81,11 @@ export class HomePage extends React.Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
getPluginHeaderActions = () => {
|
getPluginHeaderActions = () => {
|
||||||
return [
|
const { canOpen, canUpdate } = this.state;
|
||||||
{
|
const actions = [];
|
||||||
|
|
||||||
|
if (canOpen) {
|
||||||
|
actions.push({
|
||||||
color: 'none',
|
color: 'none',
|
||||||
label: this.context.formatMessage({
|
label: this.context.formatMessage({
|
||||||
id: getTrad('containers.HomePage.Button.open'),
|
id: getTrad('containers.HomePage.Button.open'),
|
||||||
@ -62,8 +94,11 @@ export class HomePage extends React.Component {
|
|||||||
onClick: this.openCurrentDocumentation,
|
onClick: this.openCurrentDocumentation,
|
||||||
type: 'button',
|
type: 'button',
|
||||||
key: 'button-open',
|
key: 'button-open',
|
||||||
},
|
});
|
||||||
{
|
}
|
||||||
|
|
||||||
|
if (canUpdate) {
|
||||||
|
actions.push({
|
||||||
label: this.context.formatMessage({
|
label: this.context.formatMessage({
|
||||||
id: getTrad('containers.HomePage.Button.update'),
|
id: getTrad('containers.HomePage.Button.update'),
|
||||||
}),
|
}),
|
||||||
@ -71,8 +106,10 @@ export class HomePage extends React.Component {
|
|||||||
onClick: () => {},
|
onClick: () => {},
|
||||||
type: 'submit',
|
type: 'submit',
|
||||||
key: 'button-submit',
|
key: 'button-submit',
|
||||||
},
|
});
|
||||||
];
|
}
|
||||||
|
|
||||||
|
return actions;
|
||||||
};
|
};
|
||||||
|
|
||||||
handleCopy = () => {
|
handleCopy = () => {
|
||||||
@ -142,6 +179,7 @@ export class HomePage extends React.Component {
|
|||||||
onSubmit,
|
onSubmit,
|
||||||
versionToDelete,
|
versionToDelete,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
const { formatMessage } = this.context;
|
const { formatMessage } = this.context;
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
@ -220,6 +258,7 @@ HomePage.defaultProps = {
|
|||||||
onSubmit: () => {},
|
onSubmit: () => {},
|
||||||
onUpdateDoc: () => {},
|
onUpdateDoc: () => {},
|
||||||
prefix: '/documentation',
|
prefix: '/documentation',
|
||||||
|
userPermissions: [],
|
||||||
versionToDelete: '',
|
versionToDelete: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -237,6 +276,7 @@ HomePage.propTypes = {
|
|||||||
onSubmit: PropTypes.func,
|
onSubmit: PropTypes.func,
|
||||||
onUpdateDoc: PropTypes.func,
|
onUpdateDoc: PropTypes.func,
|
||||||
prefix: PropTypes.string,
|
prefix: PropTypes.string,
|
||||||
|
userPermissions: PropTypes.array,
|
||||||
versionToDelete: PropTypes.string,
|
versionToDelete: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -5,9 +5,15 @@ const pluginPermissions = {
|
|||||||
// plugin directly in the browser
|
// plugin directly in the browser
|
||||||
main: [
|
main: [
|
||||||
{ action: 'plugins::documentation.read', subject: null },
|
{ action: 'plugins::documentation.read', subject: null },
|
||||||
{ action: 'plugins::documentation.regenerate', subject: null },
|
{ action: 'plugins::documentation.settings.regenerate', subject: null },
|
||||||
{ action: 'plugins::documentation.update', subject: null },
|
{ action: 'plugins::documentation.settings.update', subject: null },
|
||||||
],
|
],
|
||||||
|
open: [
|
||||||
|
{ action: 'plugins::documentation.read', subject: null },
|
||||||
|
{ action: 'plugins::documentation.settings.regenerate', subject: null },
|
||||||
|
],
|
||||||
|
regenerate: [{ action: 'plugins::documentation.settings.regenerate', subject: null }],
|
||||||
|
update: [{ action: 'plugins::documentation.settings.update', subject: null }],
|
||||||
};
|
};
|
||||||
|
|
||||||
export default pluginPermissions;
|
export default pluginPermissions;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user