From c2fd6468b4a007c8e58356467bf130e90b4866de Mon Sep 17 00:00:00 2001 From: cyril lopez Date: Wed, 6 Dec 2017 17:05:03 +0100 Subject: [PATCH] Add 404 in settings manager --- .../admin/src/containers/App/index.js | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/strapi-plugin-settings-manager/admin/src/containers/App/index.js b/packages/strapi-plugin-settings-manager/admin/src/containers/App/index.js index 1228c42342..2225d489dd 100755 --- a/packages/strapi-plugin-settings-manager/admin/src/containers/App/index.js +++ b/packages/strapi-plugin-settings-manager/admin/src/containers/App/index.js @@ -13,7 +13,7 @@ import { bindActionCreators, compose } from 'redux'; import 'flag-icon-css/css/flag-icon.css'; import 'react-select/dist/react-select.css'; import { Switch, Route } from 'react-router-dom'; - +import { isEmpty } from 'lodash'; import { pluginId } from 'app'; import injectSaga from 'utils/injectSaga'; @@ -21,7 +21,7 @@ import injectSaga from 'utils/injectSaga'; import HomePage from 'containers/HomePage'; import { menuFetch, environmentsFetch } from './actions'; -import { makeSelectLoading } from './selectors'; +import { makeSelectLoading, makeSelectSections } from './selectors'; import styles from './styles.scss'; import saga from './sagas'; @@ -33,6 +33,26 @@ class App extends React.Component { this.props.environmentsFetch(); } + componentWillUpdate(nextProps) { + if (!isEmpty(nextProps.sections) && nextProps.location.pathname !== '/plugins/settings-manager') { + const allowedPath = nextProps.sections.reduce((acc, current) => { + const slugs = current.items.reduce((acc, current) => { + acc.push(current.slug); + + return acc; + }, []); + return acc.concat(slugs); + }, []); + + const slug = nextProps.location.pathname.split('/')[3]; + const shouldRedirect = allowedPath.filter(el => el === slug).length === 0; + + if (shouldRedirect) { + this.props.history.push('/404'); + } + } + } + render() { return (
@@ -52,8 +72,9 @@ App.contextTypes = { App.propTypes = { environmentsFetch: PropTypes.func.isRequired, - // loading: PropTypes.bool.isRequired, + history: PropTypes.object.isRequired, menuFetch: PropTypes.func.isRequired, + sections: PropTypes.array.isRequired, }; export function mapDispatchToProps(dispatch) { @@ -68,6 +89,7 @@ export function mapDispatchToProps(dispatch) { const mapStateToProps = createStructuredSelector({ loading: makeSelectLoading(), + sections: makeSelectSections(), }); // Wrap the component to inject dispatch and state into it