From a07663afe446947f6d07ef3b5d7d8d522695804e Mon Sep 17 00:00:00 2001 From: Aurelsicoko Date: Tue, 6 Feb 2018 14:43:26 +0100 Subject: [PATCH] Populate type field when creating a role #553 --- .../services/UsersPermissions.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/strapi-plugin-users-permissions/services/UsersPermissions.js b/packages/strapi-plugin-users-permissions/services/UsersPermissions.js index ab67305c3a..b91687b320 100644 --- a/packages/strapi-plugin-users-permissions/services/UsersPermissions.js +++ b/packages/strapi-plugin-users-permissions/services/UsersPermissions.js @@ -17,7 +17,11 @@ module.exports = { return new Error('This feature requires to install the Content Manager plugin'); } - const role = await strapi.query('role', 'users-permissions').create(_.omit(params, ['users', 'permissions', 'type'])); + if (!params.type) { + params.type = _.snakeCase(_.deburr(_.toLower(params.name))); + } + + const role = await strapi.query('role', 'users-permissions').create(_.omit(params, ['users', 'permissions'])); const arrayOfPromises = Object.keys(params.permissions).reduce((acc, type) => { Object.keys(params.permissions[type].controllers).forEach(controller => {