Resolve conflicts

This commit is contained in:
Aurelsicoko 2017-12-07 19:15:24 +01:00
commit bbde1dc125
18 changed files with 117 additions and 123 deletions

View File

@ -17,6 +17,7 @@
color: $left-menu-link-color;
text-decoration: none;
display: block;
-webkit-font-smoothing: antialiased;
&:hover {
color: $white;
@ -43,7 +44,6 @@
.linkIcon {
position: relative;
margin-right: 1.2rem;
vertical-align: middle;
font-size: 1.2rem;
width: 1.4rem;
height: 1.2rem;

View File

@ -79,7 +79,7 @@ function LeftMenuLinkContainer({ plugins }) {
<p className={styles.title}><FormattedMessage {...messages.general} /></p>
<ul className={styles.list}>
<LeftMenuLink
icon="cubes"
icon="puzzle-piece"
label={messages.listPlugins.id}
destination="/list-plugins"
/>

View File

@ -60,7 +60,7 @@
&:active {
box-shadow: inset 1px 1px 3px rgba(0,0,0,.15);
}
padding-top: 4px;
padding-left: 1.6rem;
padding-right: 1.6rem;
&:before {

File diff suppressed because one or more lines are too long

View File

@ -77,7 +77,6 @@
&:active {
box-shadow: inset 1px 1px 3px rgba(0,0,0,.15);
}
padding-top: 4px;
padding-left: 1.6rem;
padding-right: 1.6rem;
&:before {

View File

@ -10,7 +10,7 @@ const shouldRenderCompo = (plugin) => new Promise((resolve, reject) => {
blockerComponentIcon: 'fa-refresh',
blockerComponentContent: 'renderIde',
};
if (response.environment !== 'development') {
plugin.preventComponentRendering = true;
plugin.blockerComponentProps = {

View File

@ -5,28 +5,13 @@
*/
import React from 'react';
import { get, includes, map, tail } from 'lodash';
import { get, includes, map, tail, toLower } from 'lodash';
import { FormattedMessage } from 'react-intl';
import PropTypes from 'prop-types';
import cn from 'classnames';
import styles from './styles.scss';
function BoundRoute({ route }) {
let color;
switch (get(route, 'method')) {
case 'GET':
color = '#008DFE';
break;
case 'POST':
color = '#69BA05';
break;
case 'PUT':
color = '#F68E0E';
break;
default:
color = '#F64D0A';
}
const title = get(route, 'handler');
const formattedRoute = get(route, 'path') ? tail(get(route, 'path').split('/')) : [];
const [ controller = '', action = '' ] = title ? title.split('.') : [];
@ -40,7 +25,7 @@ function BoundRoute({ route }) {
<span>.{action} </span>
</div>
<div className={styles.boundRoute}>
<div className={styles.verb} style={{ backgroundColor: color }}>
<div className={cn(styles.verb, styles[toLower(get(route, 'method'))])}>
{get(route, 'method')}
</div>
<div className={styles.path}>

View File

@ -41,3 +41,19 @@
font-weight: 600;
}
}
.get {
background-color: #008DFE;
}
.post {
background-color: #69BA05;
}
.put {
background-color: #F68E0E;
}
.delete {
background-color: #F64D0A;
}

View File

@ -41,11 +41,7 @@ class InputSearch extends React.Component { // eslint-disable-line react/prefer-
handleChange = ({ target }) => {
const filteredUsers = isEmpty(target.value) ?
this.state.users
: this.state.users.filter((user) => {
if (includes(toLower(user.name), toLower(target.value))) {
return user;
}
});
: this.state.users.filter((user) => includes(toLower(user.name), toLower(target.value)));
if (isEmpty(filteredUsers) && !isEmpty(target.value)) {
this.props.getUser(target.value);

View File

@ -1,4 +1,4 @@
import { get, includes, set } from 'lodash';
import { get, includes, isArray, set } from 'lodash';
import { call, fork, takeLatest, put, select } from 'redux-saga/effects';
import auth from 'utils/auth';
import request from 'utils/request';
@ -42,40 +42,45 @@ export function* submitForm() {
} catch(error) {
const formType = yield select(makeSelectFormType());
const errors = error.response.payload.message.reduce((acc, key) => {
const err = key.messages.reduce((acc, key) => {
acc.id = `users-permissions.${key.id}`;
if (isArray(error.response.payload.message)) {
const errors = error.response.payload.message.reduce((acc, key) => {
const err = key.messages.reduce((acc, key) => {
acc.id = `users-permissions.${key.id}`;
return acc;
}, { id: '' });
acc.push(err);
return acc;
}, { id: '' });
}, []);
acc.push(err);
let formErrors;
return acc;
}, []);
switch (formType) {
case 'forgot-password':
formErrors = [{ name: 'email', errors }];
break;
case 'login':
formErrors = [{ name: 'identifier', errors }];
break;
case 'reset-password':
formErrors = [{ name: 'password', errors: [{ id: 'users-permissions.Auth.form.error.password.matching' }] }];
break;
case 'register': {
const target = includes(get(errors, ['0', 'id']), 'username') ? 'username' : 'email';
formErrors = [{ name: target, errors }];
break;
}
default:
let formErrors;
switch (formType) {
case 'forgot-password':
formErrors = [{ name: 'email', errors }];
break;
case 'login':
formErrors = [{ name: 'identifier', errors }];
break;
case 'reset-password':
formErrors = [{ name: 'password', errors: [{ id: 'users-permissions.Auth.form.error.password.matching' }] }];
break;
case 'register': {
const target = includes(get(errors, ['0', 'id']), 'username') ? 'username' : 'email';
formErrors = [{ name: target, errors }];
break;
}
default:
yield put(submitError(formErrors));
} else {
strapi.notification.error('notification.error');
}
yield put(submitError(formErrors));
}
}

View File

@ -124,7 +124,7 @@ export class EditPage extends React.Component { // eslint-disable-line react/pre
disabled: isEqual(this.props.editPage.modifiedData, this.props.editPage.initialData),
},
];
return (
<div>
<BackHeader onClick={() => this.props.history.goBack()} />

View File

@ -1,6 +1,6 @@
module.exports = async (ctx, next) => {
if (!ctx.state.user) {
throw new Error('Authentication is required.');
throw new Error('Authentication required.');
}
await next();

View File

@ -17,7 +17,7 @@ module.exports = async (ctx, next) => {
}
}
const permission = _.get(_.clone(strapi.plugins['users-permissions'].config), [role.toString(), 'permissions', route.plugin || 'application', 'controllers', route.controller, route.action]);
const permission = _.get(strapi.plugins['users-permissions'].config, [role.toString(), 'permissions', route.plugin || 'application', 'controllers', route.controller, route.action]);
if (!permission) {
return await next();
@ -25,7 +25,7 @@ module.exports = async (ctx, next) => {
if (permission.enabled && permission.policy) {
try {
await require(`./${permission.policy}.js`)(ctx, next);
await strapi.plugins['users-permissions'].config.policies[permission.policy](ctx, next);
} catch (err) {
ctx.unauthorized(err);
}

View File

@ -26,13 +26,13 @@ module.exports = {
},
findOne: async function (params) {
if (_.get(params, 'where._id')) {
params.where.id = params.where._id;
delete params.where._id;
if (_.get(params, '_id')) {
params.id = params._id;
delete params._id;
}
const record = await this
.forge(params.where)
.forge(params)
.fetch({
withRelated: this.associations.map(x => x.alias)
});
@ -99,7 +99,7 @@ module.exports = {
},
countByRoles: async function () {
const result = await strapi.connections[this.connection].raw('SELECT COUNT("id") AS total, "role" FROM "user" GROUP BY "role";');
const result = await strapi.connections[this.connection].raw(`SELECT COUNT("id") AS total, "role" FROM "${strapi.plugins['users-permissions'].models.user.collectionName}" GROUP BY "role";`);
return result.rows.reduce((acc, current) => {
acc.push({
_id: parseFloat(current.role),

View File

@ -98,8 +98,7 @@ module.exports = {
},
forgotPassword: async (ctx) => {
const email = ctx.request.body.email;
const url = ctx.request.body.url;
const { email, url } = ctx.request.body;
// Find the user user thanks to his email.
const user = await strapi.query('user', 'users-permissions').findOne({ email });

View File

@ -17,14 +17,8 @@ module.exports = {
*/
find: async (ctx) => {
let data = await strapi.plugins['users-permissions'].services.user.fetchAll(ctx.query);
if (data) {
data = _.reduce(data, (acc, user) => {
acc.push(_.omit(user.toJSON(), ['password', 'resetPasswordToken']));
return acc;
}, []);
}
const data = await strapi.plugins['users-permissions'].services.user.fetchAll(ctx.query)
.map(user => _.omit(user.toJSON ? user.toJSON() : user, ['password', 'resetPasswordToken']));
// Send 200 `ok`
ctx.send(data);
@ -41,7 +35,7 @@ module.exports = {
let data = await strapi.plugins['users-permissions'].services.user.fetch(ctx.params);
if (data) {
data = _.omit(data.toJSON(), ['password', 'resetPasswordToken']);
data = _.omit(data.toJSON ? data.toJSON() : data, ['password', 'resetPasswordToken']);
}
// Send 200 `ok`

View File

@ -90,6 +90,7 @@ module.exports = {
ctx.send({ roles });
} catch(err) {
console.log(err);
ctx.badRequest(null, [{ messages: [{ id: 'Not found' }] }]);
}
},
@ -100,7 +101,6 @@ module.exports = {
ctx.send({ routes });
} catch(err) {
console.log(err);
ctx.badRequest(null, [{ messages: [{ id: 'Not found' }] }]);
}
},

View File

@ -4,7 +4,7 @@ const fs = require('fs')
const path = require('path');
const stringify = JSON.stringify;
const _ = require('lodash');
// const Service = strapi.plugins['users-permissions'].services;
/**
* UsersPermissions.js service
*
@ -14,7 +14,7 @@ const _ = require('lodash');
module.exports = {
createRole: (role) => {
const Service = strapi.plugins['users-permissions'].services.userspermissions;
const appRoles = require(Service.getRoleConfigPath());
const appRoles = strapi.plugins['users-permissions'].config.roles;
const highestId = _.last(Object.keys(appRoles).reduce((acc, key) => {
acc.push(_.toNumber(key));
@ -34,7 +34,7 @@ module.exports = {
deleteRole: async (roleId) => {
const Service = strapi.plugins['users-permissions'].services.userspermissions;
const appRoles = require(Service.getRoleConfigPath());
const appRoles = strapi.plugins['users-permissions'].config.roles
Service.writePermissions(_.omit(appRoles, [roleId]));
@ -85,7 +85,7 @@ module.exports = {
getRole: async (roleId) => {
const Service = strapi.plugins['users-permissions'].services.userspermissions;
const appRoles = require(Service.getRoleConfigPath());
const appRoles = strapi.plugins['users-permissions'].config.roles
appRoles[roleId].users = await strapi.query('user', 'users-permissions').find(strapi.utils.models.convertParams('user', { role: roleId }));
return appRoles[roleId];
@ -93,7 +93,7 @@ module.exports = {
getRoles: async () => {
const Service = strapi.plugins['users-permissions'].services.userspermissions;
const roles = require(Service.getRoleConfigPath());
const roles = strapi.plugins['users-permissions'].config.roles;
const usersCount = await strapi.query('user', 'users-permissions').countByRoles();
const formattedRoles = Object.keys(roles).reduce((acc, key) => {
const role = _.pick(roles[key], ['name', 'description']);
@ -109,11 +109,17 @@ module.exports = {
},
getRoutes: async () => {
return Object.keys(strapi.plugins).reduce((acc, current) => {
const apiRoutes = Object.keys(strapi.api).reduce((acc, current) => {
return acc.concat(strapi.api[current].config.routes);
}, []);
const pluginsRoutes = Object.keys(strapi.plugins).reduce((acc, current) => {
acc[current] = strapi.plugins[current].config.routes;
return acc;
}, {});
}, []);
return _.merge({ application: apiRoutes}, pluginsRoutes);
},
getRoleConfigPath: () => (
@ -144,17 +150,15 @@ module.exports = {
if (!_.get(dataToCompare, [pluginName, 'controllers', controllerName, actionName])) {
_.unset(data, [roleId, 'permissions', pluginName, 'controllers', controllerName, actionName]);
}
} else {
if (!_.get(data, [roleId, 'permissions', pluginName, 'controllers', controllerName, actionName])) {
const isCallback = actionName === 'callback' && controllerName === 'auth' && pluginName === 'users-permissions' && roleId === '1';
const isRegister = actionName === 'register' && controllerName === 'auth' && pluginName === 'users-permissions' && roleId === '1';
const isPassword = actionName === 'forgotPassword' && controllerName === 'auth' && pluginName === 'users-permissions' && roleId === '1';
const isNewPassword = actionName === 'changePassword-password' && controllerName === 'auth' && pluginName === 'users-permissions' && roleId === '1';
const isInit = actionName === 'init' && controllerName === 'userspermissions';
const enabled = isCallback || isRegister || roleId === '0' || isInit || isPassword || isNewPassword;
} else if (!_.get(data, [roleId, 'permissions', pluginName, 'controllers', controllerName, actionName])) {
const isCallback = actionName === 'callback' && controllerName === 'auth' && pluginName === 'users-permissions' && roleId === '1';
const isRegister = actionName === 'register' && controllerName === 'auth' && pluginName === 'users-permissions' && roleId === '1';
const isPassword = actionName === 'forgotPassword' && controllerName === 'auth' && pluginName === 'users-permissions' && roleId === '1';
const isNewPassword = actionName === 'changePassword-password' && controllerName === 'auth' && pluginName === 'users-permissions' && roleId === '1';
const isInit = actionName === 'init' && controllerName === 'userspermissions';
const enabled = isCallback || isRegister || roleId === '0' || isInit || isPassword || isNewPassword;
_.set(data, [roleId, 'permissions', pluginName, 'controllers', controllerName, actionName], { enabled, policy: '' })
}
_.set(data, [roleId, 'permissions', pluginName, 'controllers', controllerName, actionName], { enabled, policy: '' })
}
});
});
@ -167,34 +171,27 @@ module.exports = {
updatePermissions: async (cb) => {
const Service = strapi.plugins['users-permissions'].services.userspermissions;
const appActions = Service.getActions();
const roleConfigPath = Service.getRoleConfigPath();
const writePermissions = Service.writePermissions;
let currentRoles;
try {
currentRoles = require(roleConfigPath);
} catch(err) {
currentRoles = {
'0': {
description: '',
name: 'Administrator',
permissions: {
application: {
controllers: {},
},
const currentRoles = strapi.plugins['users-permissions'].config.roles || {
'0': {
description: '',
name: 'Administrator',
permissions: {
application: {
controllers: {},
},
},
'1': {
description: '',
name: 'Guest',
permissions: {
application: {
controllers: {},
},
},
'1': {
description: '',
name: 'Guest',
permissions: {
application: {
controllers: {},
},
},
};
}
},
};
const remove = await Service.updateData(_.cloneDeep(currentRoles));
const added = await Service.updateData(_.cloneDeep(remove), 'set');
@ -210,7 +207,7 @@ module.exports = {
updateRole: async (roleId, body) => {
const Service = strapi.plugins['users-permissions'].services.userspermissions;
const appRoles = require(Service.getRoleConfigPath());
const appRoles = strapi.plugins['users-permissions'].config.roles
const updatedRole = _.pick(body, ['name', 'description', 'permissions']);
_.set(appRoles, [roleId], updatedRole);
@ -219,9 +216,8 @@ module.exports = {
const currentUsers = await strapi.query('user', 'users-permissions').find(strapi.utils.models.convertParams('user', {
role: roleId
}));
const userToAdd = _.differenceBy(body.users, currentUsers, 'id');
const userToRemove = _.differenceBy(currentUsers, body.users, 'id');
const userToAdd = _.differenceBy(body.users, currentUsers.toJSON ? currentUsers.toJSON() : currentUsers, 'id');
const userToRemove = _.differenceBy(currentUsers.toJSON ? currentUsers.toJSON() : currentUsers, body.users, 'id');
_.forEach(userToAdd, (user) => {
Service.updateUserRole(user, roleId);
@ -232,7 +228,7 @@ module.exports = {
},
updateUserRole: async (user, role) => {
await strapi.query('user', 'users-permissions').update({
strapi.query('user', 'users-permissions').update({
_id: user._id || user.id,
role: role.toString()
});
@ -242,7 +238,7 @@ module.exports = {
const roleConfigPath = strapi.plugins['users-permissions'].services.userspermissions.getRoleConfigPath();
try {
fs.writeFileSync(roleConfigPath, stringify(data, null, 2), 'utf8');
fs.writeFileSync(roleConfigPath, stringify({ roles: data }, null, 2), 'utf8');
} catch(err) {
strapi.log.error(err);
}