mirror of
https://github.com/strapi/strapi.git
synced 2025-09-28 09:49:36 +00:00
Resolve conflicts
This commit is contained in:
commit
bbde1dc125
@ -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;
|
||||||
|
@ -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"
|
||||||
/>
|
/>
|
||||||
|
@ -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
@ -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 {
|
||||||
|
@ -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}>
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
@ -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);
|
||||||
|
@ -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,40 +42,45 @@ export function* submitForm() {
|
|||||||
} catch(error) {
|
} catch(error) {
|
||||||
const formType = yield select(makeSelectFormType());
|
const formType = yield select(makeSelectFormType());
|
||||||
|
|
||||||
const errors = error.response.payload.message.reduce((acc, key) => {
|
if (isArray(error.response.payload.message)) {
|
||||||
const err = key.messages.reduce((acc, key) => {
|
|
||||||
acc.id = `users-permissions.${key.id}`;
|
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;
|
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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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();
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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),
|
||||||
|
@ -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 });
|
||||||
|
@ -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`
|
||||||
|
@ -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' }] }]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -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,17 +150,15 @@ 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';
|
const isNewPassword = actionName === 'changePassword-password' && 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 isInit = actionName === 'init' && controllerName === 'userspermissions';
|
const enabled = isCallback || isRegister || roleId === '0' || isInit || isPassword || isNewPassword;
|
||||||
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) => {
|
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 || {
|
||||||
|
'0': {
|
||||||
try {
|
description: '',
|
||||||
currentRoles = require(roleConfigPath);
|
name: 'Administrator',
|
||||||
} catch(err) {
|
permissions: {
|
||||||
currentRoles = {
|
application: {
|
||||||
'0': {
|
controllers: {},
|
||||||
description: '',
|
|
||||||
name: 'Administrator',
|
|
||||||
permissions: {
|
|
||||||
application: {
|
|
||||||
controllers: {},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'1': {
|
},
|
||||||
description: '',
|
'1': {
|
||||||
name: 'Guest',
|
description: '',
|
||||||
permissions: {
|
name: 'Guest',
|
||||||
application: {
|
permissions: {
|
||||||
controllers: {},
|
application: {
|
||||||
},
|
controllers: {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
},
|
||||||
}
|
};
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user