mirror of
https://github.com/strapi/strapi.git
synced 2025-12-25 06:04:29 +00:00
Handle create role
This commit is contained in:
parent
1fe2ffdbf8
commit
b3574dee6e
@ -27,7 +27,7 @@ class ListRow extends React.Component { // eslint-disable-line react/prefer-stat
|
||||
|
||||
// Roles that can't be deleted
|
||||
// Don't delete this line
|
||||
protectedRoleIDs = ['0', '2'];
|
||||
protectedRoleIDs = ['0', '1'];
|
||||
|
||||
generateContent = () => {
|
||||
let icons = [
|
||||
|
||||
@ -71,8 +71,10 @@ export function* submit() {
|
||||
|
||||
const requestURL = actionType === 'POST' ? '/users-permissions/roles' : `/users-permissions/roles/${roleId}`;
|
||||
|
||||
yield call(request, requestURL, opts);
|
||||
yield put(submitSucceeded());
|
||||
const response = yield call(request, requestURL, opts);
|
||||
if (response.ok) {
|
||||
yield put(submitSucceeded());
|
||||
}
|
||||
} catch(error) {
|
||||
console.log(error.response.payload);
|
||||
// TODO handle error message
|
||||
|
||||
@ -22,6 +22,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
try {
|
||||
await strapi.plugins['users-permissions'].services.userspermissions.createRole(ctx.request.body);
|
||||
ctx.send({ ok: true });
|
||||
} catch(err) {
|
||||
ctx.badRequest(null, [{ messages: [{ id: 'An error occured' }] }]);
|
||||
|
||||
@ -12,6 +12,23 @@ const _ = require('lodash');
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
createRole: (role) => {
|
||||
const Service = strapi.plugins['users-permissions'].services.userspermissions;
|
||||
const roleConfigPath = Service.getRoleConfigPath();
|
||||
const currentRoles = require(Service.getRoleConfigPath());
|
||||
const highestId = _.last(Object.keys(currentRoles).reduce((acc, key) => {
|
||||
acc.push(_.toNumber(key));
|
||||
|
||||
return acc;
|
||||
}, []).sort()) + 1;
|
||||
|
||||
const newRole = _.pick(role, ['name', 'description', 'permissions']);
|
||||
|
||||
_.set(currentRoles, highestId.toString(), newRole);
|
||||
|
||||
Service.writePermissions(currentRoles);
|
||||
},
|
||||
|
||||
getActions: () => {
|
||||
const generateActions = (data) => (
|
||||
Object.keys(data).reduce((acc, key) => {
|
||||
@ -39,7 +56,6 @@ module.exports = {
|
||||
|
||||
const permissions = {
|
||||
application: {
|
||||
icon: '',
|
||||
controllers: appControllers.controllers,
|
||||
},
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user