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

View File

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

View File

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

File diff suppressed because one or more lines are too long

View File

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

View File

@ -5,28 +5,13 @@
*/ */
import React from 'react'; 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 { FormattedMessage } from 'react-intl';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import cn from 'classnames';
import styles from './styles.scss'; import styles from './styles.scss';
function BoundRoute({ route }) { 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 title = get(route, 'handler');
const formattedRoute = get(route, 'path') ? tail(get(route, 'path').split('/')) : []; const formattedRoute = get(route, 'path') ? tail(get(route, 'path').split('/')) : [];
const [ controller = '', action = '' ] = title ? title.split('.') : []; const [ controller = '', action = '' ] = title ? title.split('.') : [];
@ -40,7 +25,7 @@ function BoundRoute({ route }) {
<span>.{action} </span> <span>.{action} </span>
</div> </div>
<div className={styles.boundRoute}> <div className={styles.boundRoute}>
<div className={styles.verb} style={{ backgroundColor: color }}> <div className={cn(styles.verb, styles[toLower(get(route, 'method'))])}>
{get(route, 'method')} {get(route, 'method')}
</div> </div>
<div className={styles.path}> <div className={styles.path}>

View File

@ -41,3 +41,19 @@
font-weight: 600; 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 }) => { handleChange = ({ target }) => {
const filteredUsers = isEmpty(target.value) ? const filteredUsers = isEmpty(target.value) ?
this.state.users this.state.users
: this.state.users.filter((user) => { : this.state.users.filter((user) => includes(toLower(user.name), toLower(target.value)));
if (includes(toLower(user.name), toLower(target.value))) {
return user;
}
});
if (isEmpty(filteredUsers) && !isEmpty(target.value)) { if (isEmpty(filteredUsers) && !isEmpty(target.value)) {
this.props.getUser(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 { call, fork, takeLatest, put, select } from 'redux-saga/effects';
import auth from 'utils/auth'; import auth from 'utils/auth';
import request from 'utils/request'; import request from 'utils/request';
@ -42,6 +42,8 @@ export function* submitForm() {
} catch(error) { } catch(error) {
const formType = yield select(makeSelectFormType()); const formType = yield select(makeSelectFormType());
if (isArray(error.response.payload.message)) {
const errors = error.response.payload.message.reduce((acc, key) => { const errors = error.response.payload.message.reduce((acc, key) => {
const err = key.messages.reduce((acc, key) => { const err = key.messages.reduce((acc, key) => {
acc.id = `users-permissions.${key.id}`; acc.id = `users-permissions.${key.id}`;
@ -76,6 +78,9 @@ export function* submitForm() {
} }
yield put(submitError(formErrors)); yield put(submitError(formErrors));
} else {
strapi.notification.error('notification.error');
}
} }
} }

View File

@ -1,6 +1,6 @@
module.exports = async (ctx, next) => { module.exports = async (ctx, next) => {
if (!ctx.state.user) { if (!ctx.state.user) {
throw new Error('Authentication is required.'); throw new Error('Authentication required.');
} }
await next(); 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) { if (!permission) {
return await next(); return await next();
@ -25,7 +25,7 @@ module.exports = async (ctx, next) => {
if (permission.enabled && permission.policy) { if (permission.enabled && permission.policy) {
try { try {
await require(`./${permission.policy}.js`)(ctx, next); await strapi.plugins['users-permissions'].config.policies[permission.policy](ctx, next);
} catch (err) { } catch (err) {
ctx.unauthorized(err); ctx.unauthorized(err);
} }

View File

@ -26,13 +26,13 @@ module.exports = {
}, },
findOne: async function (params) { findOne: async function (params) {
if (_.get(params, 'where._id')) { if (_.get(params, '_id')) {
params.where.id = params.where._id; params.id = params._id;
delete params.where._id; delete params._id;
} }
const record = await this const record = await this
.forge(params.where) .forge(params)
.fetch({ .fetch({
withRelated: this.associations.map(x => x.alias) withRelated: this.associations.map(x => x.alias)
}); });
@ -99,7 +99,7 @@ module.exports = {
}, },
countByRoles: async function () { 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) => { return result.rows.reduce((acc, current) => {
acc.push({ acc.push({
_id: parseFloat(current.role), _id: parseFloat(current.role),

View File

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

View File

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

View File

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

View File

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