Fix conflict

This commit is contained in:
Jim Laurie 2017-12-01 16:08:27 +01:00
commit fab65fdd0b
7 changed files with 45 additions and 16 deletions

View File

@ -36,6 +36,7 @@ import LanguageProvider from 'containers/LanguageProvider';
import App from 'containers/App'; import App from 'containers/App';
import { showNotification } from 'containers/NotificationProvider/actions'; import { showNotification } from 'containers/NotificationProvider/actions';
import { pluginLoaded, updatePlugin } from 'containers/App/actions'; import { pluginLoaded, updatePlugin } from 'containers/App/actions';
import auth from 'utils/auth';
import configureStore from './store'; import configureStore from './store';
import { translationMessages, languages } from './i18n'; import { translationMessages, languages } from './i18n';
@ -120,6 +121,9 @@ if (window.location.port !== '4000') {
}); });
} }
// const isPluginAllowedToRegister = (plugin) => true;
const isPluginAllowedToRegister = (plugin) => plugin.id === 'users-permissions' || plugin.id === 'email' || auth.getToken();
/** /**
* Public Strapi object exposed to the `window` object * Public Strapi object exposed to the `window` object
*/ */
@ -134,10 +138,11 @@ const registerPlugin = (plugin) => {
merge(translationMessages, plugin.translationMessages); merge(translationMessages, plugin.translationMessages);
plugin.leftMenuSections = plugin.leftMenuSections || []; plugin.leftMenuSections = plugin.leftMenuSections || [];
const shouldAllowRegister = isPluginAllowedToRegister(plugin);
switch (true) { switch (true) {
// Execute bootstrap function and check if plugin can be rendered // Execute bootstrap function and check if plugin can be rendered
case isFunction(plugin.bootstrap) && isFunction(plugin.pluginRequirements): case isFunction(plugin.bootstrap) && isFunction(plugin.pluginRequirements) && shouldAllowRegister:
plugin.pluginRequirements(plugin) plugin.pluginRequirements(plugin)
.then(plugin => { .then(plugin => {
return plugin.bootstrap(plugin); return plugin.bootstrap(plugin);
@ -153,7 +158,7 @@ const registerPlugin = (plugin) => {
}); });
break; break;
// Execute bootstrap function // Execute bootstrap function
case isFunction(plugin.bootstrap): case isFunction(plugin.bootstrap) && shouldAllowRegister:
plugin.bootstrap(plugin).then(plugin => { plugin.bootstrap(plugin).then(plugin => {
store.dispatch(pluginLoaded(plugin)); store.dispatch(pluginLoaded(plugin));
}); });

View File

@ -14,9 +14,9 @@ import PropTypes from 'prop-types';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { createStructuredSelector } from 'reselect'; import { createStructuredSelector } from 'reselect';
import { Switch, Route } from 'react-router-dom'; import { Switch, Route } from 'react-router-dom';
import { get, includes, isUndefined } from 'lodash'; import { get, includes, isFunction, isUndefined, map, omit } from 'lodash';
import { updatePlugin } from 'containers/App/actions'; import { pluginLoaded, updatePlugin } from 'containers/App/actions';
import { selectPlugins } from 'containers/App/selectors'; import { selectPlugins } from 'containers/App/selectors';
import { hideNotification } from 'containers/NotificationProvider/actions'; import { hideNotification } from 'containers/NotificationProvider/actions';
@ -36,6 +36,8 @@ import auth from 'utils/auth';
import styles from './styles.scss'; import styles from './styles.scss';
export class AdminPage extends React.Component { // eslint-disable-line react/prefer-stateless-function export class AdminPage extends React.Component { // eslint-disable-line react/prefer-stateless-function
state = { hasAlreadyRegistereOtherPlugins: false };
getChildContext = () => ( getChildContext = () => (
{ {
plugins: this.props.plugins, plugins: this.props.plugins,
@ -66,6 +68,20 @@ export class AdminPage extends React.Component { // eslint-disable-line react/pr
if (!this.isUrlProtected(props) && includes(props.location.pathname, 'register') && this.hasAdminUser()) { if (!this.isUrlProtected(props) && includes(props.location.pathname, 'register') && this.hasAdminUser()) {
this.props.history.push('/plugins/users-permissions/auth/login'); this.props.history.push('/plugins/users-permissions/auth/login');
} }
if (!this.hasUsersPlugin() || auth.getToken() && !this.state.hasAlreadyRegistereOtherPlugins) {
map(omit(this.props.plugins.toJS(), ['users-permissions', 'email']), plugin => {
if (isFunction(plugin.bootstrap)) {
plugin.bootstrap(plugin)
.then(updatedPlugin => this.props.pluginLoaded(updatedPlugin))
.catch(err => {
console.log(err);
});
}
});
this.setState({ hasAlreadyRegistereOtherPlugins: true });
}
} }
hasUsersPlugin = () => !isUndefined(get(this.props.plugins.toJS(), 'users-permissions')); hasUsersPlugin = () => !isUndefined(get(this.props.plugins.toJS(), 'users-permissions'));
@ -118,6 +134,7 @@ AdminPage.contextTypes = {
AdminPage.propTypes = { AdminPage.propTypes = {
history: PropTypes.object.isRequired, history: PropTypes.object.isRequired,
location: PropTypes.object.isRequired, location: PropTypes.object.isRequired,
pluginLoaded: PropTypes.func.isRequired,
plugins: PropTypes.object.isRequired, plugins: PropTypes.object.isRequired,
updatePlugin: PropTypes.func.isRequired, updatePlugin: PropTypes.func.isRequired,
}; };
@ -130,6 +147,7 @@ function mapDispatchToProps(dispatch) {
return { return {
onHideNotification: (id) => { dispatch(hideNotification(id)); }, onHideNotification: (id) => { dispatch(hideNotification(id)); },
updatePlugin: (pluginId, updatedKey, updatedValue) => { dispatch(updatePlugin(pluginId, updatedKey, updatedValue)); }, updatePlugin: (pluginId, updatedKey, updatedValue) => { dispatch(updatePlugin(pluginId, updatedKey, updatedValue)); },
pluginLoaded: (plugin) => { dispatch(pluginLoaded(plugin)); },
dispatch, dispatch,
}; };
} }

View File

@ -83,20 +83,20 @@ if (module.hot) {
// Register the plugin. // Register the plugin.
strapi.registerPlugin({ strapi.registerPlugin({
name: pluginPkg.strapi.name, blockerComponent: null,
icon: pluginPkg.strapi.icon, blockerComponentProps: {},
bootstrap,
description: pluginDescription, description: pluginDescription,
icon: pluginPkg.strapi.icon,
id: pluginId, id: pluginId,
injectedComponents,
layout,
leftMenuLinks: [], leftMenuLinks: [],
mainComponent: Comp, mainComponent: Comp,
translationMessages, name: pluginPkg.strapi.name,
bootstrap,
pluginRequirements, pluginRequirements,
layout,
preventComponentRendering: false, preventComponentRendering: false,
blockerComponent: null, translationMessages,
injectedComponents,
blockerComponentProps: {},
}); });
// Export store // Export store

View File

@ -0,0 +1,3 @@
const bootstrap = (plugin) => Promise.resolve(plugin);
export default bootstrap;

View File

@ -0,0 +1,3 @@
const bootstrap = (plugin) => Promise.resolve(plugin);
export default bootstrap;

View File

@ -113,7 +113,7 @@ export function getUser(user) {
export function getUserSucceeded(users) { export function getUserSucceeded(users) {
return { return {
type: GET_USER_SUCCEEDED, type: GET_USER_SUCCEEDED,
users, users: users.filter(o => o.role.toString() !== '0'),
}; };
} }

View File

@ -268,7 +268,7 @@
"controllers": { "controllers": {
"contentmanager": { "contentmanager": {
"models": { "models": {
"enabled": true, "enabled": false,
"policy": "" "policy": ""
}, },
"find": { "find": {