@strapi/plugin-users-permissions 4.0.4 → 4.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,12 +28,12 @@ const Input = ({
28
28
 
29
29
  const label = formatMessage(
30
30
  { id: intlLabel.id, defaultMessage: intlLabel.defaultMessage },
31
- { ...intlLabel.values }
31
+ { provider: providerToEditName, ...intlLabel.values }
32
32
  );
33
33
  const hint = description
34
34
  ? formatMessage(
35
35
  { id: description.id, defaultMessage: description.defaultMessage },
36
- { ...description.values }
36
+ { provider: providerToEditName, ...description.values }
37
37
  )
38
38
  : '';
39
39
 
@@ -23,9 +23,6 @@ const keyLabel = { id: getTrad('PopUpForm.Providers.key.label'), defaultMessage:
23
23
  const hintLabel = {
24
24
  id: getTrad('PopUpForm.Providers.redirectURL.label'),
25
25
  defaultMessage: 'The redirect URL to add in your {provider} application configurations',
26
- values: {
27
- provider: 'VK',
28
- },
29
26
  };
30
27
  const textPlaceholder = {
31
28
  id: getTrad('PopUpForm.Providers.key.placeholder'),
@@ -44,5 +44,51 @@
44
44
  "notification.success.submit": "Indstillingerne er blevet opdateret",
45
45
  "plugin.description.long": "Beskyt din API med fuld godkendelse med JWT. Dette plugin kommer også med en ACL strategi som tillader dig at håndtere rettigeheder mellem grupper af brugere.",
46
46
  "plugin.description.short": "Beskyt din API med fuld godkendelse med JWT",
47
- "plugin.name": "Roller & rettigheder"
47
+ "plugin.name": "Roller & rettigheder",
48
+ "EditForm.inputToggle.placeholder.email-confirmation-redirection": "f.eks. https://hjemmeside.dk/nulstil-kodeord",
49
+ "EditForm.inputToggle.placeholder.email-reset-password": "f.eks. https://hjemmeside.dk/nulstil-kodeord",
50
+ "EditPage.form.roles": "Rolle detaljer",
51
+ "Email.template.data.loaded": "E-mail skabeloner er hentet",
52
+ "Email.template.form.edit.label": "Redigér en skabelon",
53
+ "Email.template.table.action.label": "handling",
54
+ "Email.template.table.icon.label": "ikon",
55
+ "Email.template.table.name.label": "navn",
56
+ "Form.advancedSettings.data.loaded": "Avancerede indstillinger hentet",
57
+ "Form.save": "Gem",
58
+ "Form.title.advancedSettings": "Indstillinger",
59
+ "PopUpForm.Email.options.object.placeholder": "Bekræft venligst din e-mail adresse for %APP_NAME%",
60
+ "PopUpForm.Providers.redirectURL.front-end.label": "Omstillings URL til din font-end app",
61
+ "PopUpForm.Providers.redirectURL.label": "Omstillings URL som tilføjes til din {provider} applikation konfigurationer",
62
+ "PopUpForm.Providers.subdomain.label": "Host URI (Subdomain)",
63
+ "PopUpForm.Providers.subdomain.placeholder": "mit.subdomain.dk",
64
+ "Providers.data.loaded": "Providers hentet",
65
+ "Providers.disabled": "Deaktiveret",
66
+ "Providers.enabled": "Aktiveret",
67
+ "Providers.image": "Billede",
68
+ "Providers.name": "Navn",
69
+ "Providers.settings": "Indstillinger",
70
+ "Providers.status": "Status",
71
+ "Roles.description": "Beskrivelse",
72
+ "Roles.empty": "Du har endnu ingen roller.",
73
+ "Roles.empty.search": "Ingen roller matcher søgningen.",
74
+ "Roles.name": "Navn",
75
+ "Roles.users": "Brugere",
76
+ "Settings.roles.deleted": "Rolle slettet",
77
+ "Settings.roles.edited": "Rolle redigeret",
78
+ "Settings.section-label": "Brugere & Tilladelser plugin",
79
+ "components.Input.error.validation.email": "Dette er en ugyldig e.mail",
80
+ "components.Input.error.validation.json": "Dette stemmer ikke med JSON formatet",
81
+ "components.Input.error.validation.max": "Værdien er for høj.",
82
+ "components.Input.error.validation.maxLength": "Værdien er for lang.",
83
+ "components.Input.error.validation.min": "Værdien er for lav.",
84
+ "components.Input.error.validation.minLength": "Værdien er for kort.",
85
+ "components.Input.error.validation.minSupMax": "Kan ikke være overlegen",
86
+ "components.Input.error.validation.regex": "Værdien stemmer ikke overens med regex.",
87
+ "components.Input.error.validation.required": "Værdien er påkrævet.",
88
+ "components.Input.error.validation.unique": "Værdien er allerede brugt.",
89
+ "page.title": "Indstillinger - Roller",
90
+ "popUpWarning.button.cancel": "Annuller",
91
+ "popUpWarning.button.confirm": "Bekræft",
92
+ "popUpWarning.title": "Bekræft venligst",
93
+ "popUpWarning.warning.cancel": "Er du sikker på at du vil annullere dine ændringer?"
48
94
  }
@@ -12,8 +12,19 @@
12
12
  "EditForm.inputToggle.label.email-confirmation-redirection": "URL de redirección",
13
13
  "EditForm.inputToggle.label.email-reset-password": "Página de reestablecer la contraseña",
14
14
  "EditForm.inputToggle.label.sign-up": "Habilitar inscripciones",
15
+ "EditForm.inputToggle.placeholder.email-confirmation-redirection": "ej: https://tufrontend.com/restablecer-contrasena",
16
+ "EditForm.inputToggle.placeholder.email-reset-password": "ej: https://tufrontend.com/restablecer-contrasena",
17
+ "EditPage.form.roles": "Detalles del rol",
18
+ "Email.template.data.loaded": "Se han cargado las plantillas de correo electrónico",
15
19
  "Email.template.email_confirmation": "Confirmación de dirección de correo electrónico",
20
+ "Email.template.form.edit.label": "Editar una plantilla",
16
21
  "Email.template.reset_password": "Restablecer la contraseña",
22
+ "Email.template.table.action.label": "acción",
23
+ "Email.template.table.icon.label": "icono",
24
+ "Email.template.table.name.label": "nombre",
25
+ "Form.advancedSettings.data.loaded": "Se han cargado los datos de configuración avanzada",
26
+ "Form.save": "Guardar",
27
+ "Form.title.advancedSettings": "Ajustes",
17
28
  "HeaderNav.link.advancedSettings": "Ajustes avanzados",
18
29
  "HeaderNav.link.emailTemplates": "Plantillas de email",
19
30
  "HeaderNav.link.providers": "Proveedores",
@@ -42,14 +53,37 @@
42
53
  "PopUpForm.Providers.redirectURL.label": "La URL de redireccionamiento para agregar en las configuraciones de su aplicación de {proveedor}",
43
54
  "PopUpForm.Providers.secret.label": "Secreto Cliente",
44
55
  "PopUpForm.Providers.secret.placeholder": "TEXTO",
45
- "PopUpForm.Providers.subdomain.label": "Host URI (Subdomain)",
46
- "PopUpForm.Providers.subdomain.placeholder": "my.subdomain.com",
56
+ "PopUpForm.Providers.subdomain.label": "URI de host (subdominio)",
57
+ "PopUpForm.Providers.subdomain.placeholder": "mi.subdominio.com",
47
58
  "PopUpForm.header.edit.email-templates": "Editar Plantillas de Email",
48
59
  "PopUpForm.header.edit.providers": "Editar proveedor",
60
+ "Providers.data.loaded": "Los proveedores se han cargado",
61
+ "Providers.disabled": "Deshabilitado",
62
+ "Providers.enabled": "Habilitado",
63
+ "Providers.image": "Imagen",
64
+ "Providers.name": "Nombre",
65
+ "Providers.settings": "Ajustes",
66
+ "Providers.status": "Estado",
67
+ "Roles.description": "Descripción",
68
+ "Roles.empty": "Aún no tienes ningún rol.",
69
+ "Roles.empty.search": "Ningún rol coincide con la búsqueda.",
70
+ "Roles.name": "Nombre",
71
+ "Roles.users": "Usuarios",
49
72
  "Settings.roles.deleted": "Rol eliminado",
50
73
  "Settings.roles.edited": "Rol editado",
51
74
  "Settings.section-label": "Plugin de Usuarios y Permisos",
75
+ "components.Input.error.validation.email": "El correo electrónico inválido",
76
+ "components.Input.error.validation.json": "No coincide con el formato JSON",
77
+ "components.Input.error.validation.max": "El valor es demasiado alto.",
78
+ "components.Input.error.validation.maxLength": "El valor es demasiado largo.",
79
+ "components.Input.error.validation.min": "El valor es demasiado bajo.",
80
+ "components.Input.error.validation.minLength": "El valor es demasiado corto.",
81
+ "components.Input.error.validation.minSupMax": "No puede ser superior",
82
+ "components.Input.error.validation.regex": "El valor no coincide con la expresión regular.",
83
+ "components.Input.error.validation.required": "Este valor es obligatorio.",
84
+ "components.Input.error.validation.unique": "Este valor ya se utiliza.",
52
85
  "notification.success.submit": "Los ajustes se han actualizado",
86
+ "page.title": "Configuración - Roles",
53
87
  "plugin.description.long": "Proteja su API con un proceso de autenticación completo basado en JWT. Este plugin viene también con una estrategia ACL que le permite administrar los permisos entre los grupos de usuarios.",
54
88
  "plugin.description.short": "Proteja su API con un proceso de autenticación completo basado en JWT",
55
89
  "plugin.name": "Roles y Permisos",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/plugin-users-permissions",
3
- "version": "4.0.4",
3
+ "version": "4.0.8",
4
4
  "description": "Protect your API with a full-authentication process based on JWT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,8 +28,8 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@purest/providers": "^1.0.2",
31
- "@strapi/helper-plugin": "4.0.4",
32
- "@strapi/utils": "4.0.4",
31
+ "@strapi/helper-plugin": "4.0.8",
32
+ "@strapi/utils": "4.0.8",
33
33
  "bcryptjs": "2.4.3",
34
34
  "grant-koa": "5.4.8",
35
35
  "jsonwebtoken": "^8.1.0",
@@ -61,5 +61,5 @@
61
61
  "required": true,
62
62
  "kind": "plugin"
63
63
  },
64
- "gitHead": "d81919ac2272948b3f5d3b25a4cf8cc7b6994460"
64
+ "gitHead": "669bb2f0440d3b21a23c8d665fdba98bd3d8cc71"
65
65
  }
@@ -8,6 +8,7 @@
8
8
  * run jobs, or perform some special logic.
9
9
  */
10
10
  const _ = require('lodash');
11
+ const urljoin = require('url-join');
11
12
  const uuid = require('uuid/v4');
12
13
  const { getService } = require('../utils');
13
14
 
@@ -31,14 +32,17 @@ module.exports = async ({ strapi }) => {
31
32
  strapi.config.set('plugin.users-permissions.jwtSecret', jwtSecret);
32
33
 
33
34
  if (!process.env.JWT_SECRET) {
34
- strapi.fs.appendFile('.env', `JWT_SECRET=${jwtSecret}\n`);
35
+ strapi.fs.appendFile(process.env.ENV_PATH || '.env', `JWT_SECRET=${jwtSecret}\n`);
36
+ strapi.log.info(
37
+ 'The Users & Permissions plugin automatically generated a jwt secret and stored it in your .env file under the name JWT_SECRET.'
38
+ );
35
39
  }
36
40
  }
37
41
  };
38
42
 
39
43
  const initGrant = async pluginStore => {
40
44
  const apiPrefix = strapi.config.get('api.rest.prefix');
41
- const baseURL = `${strapi.config.server.url}/${apiPrefix}/auth`;
45
+ const baseURL = urljoin(strapi.config.server.url, apiPrefix, 'auth');
42
46
 
43
47
  const grantConfig = {
44
48
  email: {
@@ -137,13 +137,8 @@ module.exports = {
137
137
  throw new ValidationError('Incorrect code provided');
138
138
  }
139
139
 
140
- const password = await getService('user').hashPassword({ password: params.password });
141
-
140
+ await getService('user').edit(user.id, { resetPasswordToken: null, password: params.password });
142
141
  // Update the user.
143
- await strapi
144
- .query('plugin::users-permissions.user')
145
- .update({ where: { id: user.id }, data: { resetPasswordToken: null, password } });
146
-
147
142
  ctx.send({
148
143
  jwt: getService('jwt').issue({ id: user.id }),
149
144
  user: await sanitizeUser(user, ctx),
@@ -188,7 +183,10 @@ module.exports = {
188
183
  }
189
184
 
190
185
  // Ability to pass OAuth callback dynamically
191
- grantConfig[provider].callback = _.get(ctx, 'query.callback') || grantConfig[provider].callback;
186
+ grantConfig[provider].callback =
187
+ _.get(ctx, 'query.callback') ||
188
+ _.get(ctx, 'session.grant.dynamic.callback') ||
189
+ grantConfig[provider].callback;
192
190
  grantConfig[provider].redirect_uri = getService('providers').buildRedirectUri(provider);
193
191
 
194
192
  return grant(grantConfig)(ctx, next);
@@ -322,7 +320,6 @@ module.exports = {
322
320
  }
323
321
 
324
322
  params.role = role.id;
325
- params.password = await getService('user').hashPassword(params);
326
323
 
327
324
  const user = await strapi.query('plugin::users-permissions.user').findOne({
328
325
  where: { email: params.email },
@@ -341,7 +338,7 @@ module.exports = {
341
338
  params.confirmed = true;
342
339
  }
343
340
 
344
- const user = await strapi.query('plugin::users-permissions.user').create({ data: params });
341
+ const user = await getService('user').add(params);
345
342
 
346
343
  const sanitizedUser = await sanitizeUser(user, ctx);
347
344
 
@@ -364,8 +361,11 @@ module.exports = {
364
361
  } catch (err) {
365
362
  if (_.includes(err.message, 'username')) {
366
363
  throw new ApplicationError('Username already taken');
367
- } else {
364
+ } else if (_.includes(err.message, 'email')) {
368
365
  throw new ApplicationError('Email already taken');
366
+ } else {
367
+ strapi.log.error(err);
368
+ throw new ApplicationError('An error occurred during account creation');
369
369
  }
370
370
  }
371
371
  },
@@ -21,8 +21,6 @@ module.exports = ({ strapi }) => ({
21
21
  }
22
22
 
23
23
  token = parts[1];
24
- } else if (ctx.query.access_token) {
25
- token = ctx.query.access_token;
26
24
  } else {
27
25
  return null;
28
26
  }
@@ -8,6 +8,7 @@
8
8
 
9
9
  const crypto = require('crypto');
10
10
  const bcrypt = require('bcryptjs');
11
+ const urlJoin = require('url-join');
11
12
 
12
13
  const { getAbsoluteServerUrl, sanitize } = require('@strapi/utils');
13
14
  const { getService } = require('../utils');
@@ -34,13 +35,10 @@ module.exports = ({ strapi }) => ({
34
35
  * @return {Promise}
35
36
  */
36
37
  async add(values) {
37
- if (values.password) {
38
- values.password = await getService('user').hashPassword(values);
39
- }
40
-
41
- return strapi
42
- .query('plugin::users-permissions.user')
43
- .create({ data: values, populate: ['role'] });
38
+ return strapi.entityService.create('plugin::users-permissions.user', {
39
+ data: values,
40
+ populate: ['role'],
41
+ });
44
42
  },
45
43
 
46
44
  /**
@@ -50,18 +48,10 @@ module.exports = ({ strapi }) => ({
50
48
  * @return {Promise}
51
49
  */
52
50
  async edit(userId, params = {}) {
53
- if (params.password) {
54
- params.password = await getService('user').hashPassword(params);
55
- }
56
-
57
- return strapi.entityService.update(
58
- 'plugin::users-permissions.user',
59
- userId,
60
- {
61
- data: params,
62
- populate: ['role']
63
- }
64
- );
51
+ return strapi.entityService.update('plugin::users-permissions.user', userId, {
52
+ data: params,
53
+ populate: ['role'],
54
+ });
65
55
  },
66
56
 
67
57
  /**
@@ -90,21 +80,13 @@ module.exports = ({ strapi }) => ({
90
80
  return strapi.query('plugin::users-permissions.user').findMany({ where: params, populate });
91
81
  },
92
82
 
93
- hashPassword(user = {}) {
94
- return new Promise((resolve, reject) => {
95
- if (!user.password || this.isHashed(user.password)) {
96
- resolve(null);
97
- } else {
98
- bcrypt.hash(`${user.password}`, 10, (err, hash) => {
99
- if (err) {
100
- return reject(err);
101
- }
102
- resolve(hash);
103
- });
104
- }
105
- });
83
+ /**
84
+ * Promise to remove a/an user.
85
+ * @return {Promise}
86
+ */
87
+ async remove(params) {
88
+ return strapi.query('plugin::users-permissions.user').delete({ where: params });
106
89
  },
107
-
108
90
  isHashed(password) {
109
91
  if (typeof password !== 'string' || !password) {
110
92
  return false;
@@ -113,14 +95,6 @@ module.exports = ({ strapi }) => ({
113
95
  return password.split('$').length === 4;
114
96
  },
115
97
 
116
- /**
117
- * Promise to remove a/an user.
118
- * @return {Promise}
119
- */
120
- async remove(params) {
121
- return strapi.query('plugin::users-permissions.user').delete({ where: params });
122
- },
123
-
124
98
  validatePassword(password, hash) {
125
99
  return bcrypt.compare(password, hash);
126
100
  },
@@ -141,8 +115,9 @@ module.exports = ({ strapi }) => ({
141
115
 
142
116
  await this.edit(user.id, { confirmationToken });
143
117
 
118
+ const apiPrefix = strapi.config.get('api.rest.prefix');
144
119
  settings.message = await userPermissionService.template(settings.message, {
145
- URL: `${getAbsoluteServerUrl(strapi.config)}/auth/email-confirmation`,
120
+ URL: urlJoin(getAbsoluteServerUrl(strapi.config), apiPrefix, '/auth/email-confirmation'),
146
121
  USER: sanitizedUserInfo,
147
122
  CODE: confirmationToken,
148
123
  });
@@ -2,6 +2,7 @@
2
2
 
3
3
  const _ = require('lodash');
4
4
  const { filter, map, pipe, prop } = require('lodash/fp');
5
+ const urlJoin = require('url-join');
5
6
 
6
7
  const { getService } = require('../utils');
7
8
 
@@ -112,9 +113,10 @@ module.exports = ({ strapi }) => ({
112
113
  return;
113
114
  }
114
115
 
116
+ const apiPrefix = strapi.config.get('api.rest.prefix');
115
117
  routesMap[`api::${apiName}`] = routes.map(route => ({
116
118
  ...route,
117
- path: `/api${route.path}`,
119
+ path: urlJoin(apiPrefix, route.path),
118
120
  }));
119
121
  });
120
122
 
@@ -133,9 +135,10 @@ module.exports = ({ strapi }) => ({
133
135
  return;
134
136
  }
135
137
 
138
+ const apiPrefix = strapi.config.get('api.rest.prefix');
136
139
  routesMap[`plugin::${pluginName}`] = routes.map(route => ({
137
140
  ...route,
138
- path: `/api${route.path}`,
141
+ path: urlJoin(apiPrefix, route.path),
139
142
  }));
140
143
  });
141
144
 
@@ -67,40 +67,25 @@ const authenticate = async ctx => {
67
67
  const verify = async (auth, config) => {
68
68
  const { credentials: user } = auth;
69
69
 
70
- // public accesss
71
- if (!user) {
72
- // test against public role
73
- const publicPermissions = await strapi.query('plugin::users-permissions.permission').findMany({
74
- where: {
75
- role: { type: 'public' },
76
- },
77
- });
78
-
79
- const allowedActions = map('action', publicPermissions);
80
-
81
- // A non authenticated user cannot access routes that do not have a scope
82
- if (!config.scope) {
70
+ if (!config.scope) {
71
+ if (!user) {
72
+ // A non authenticated user cannot access routes that do not have a scope
83
73
  throw new UnauthorizedError();
74
+ } else {
75
+ // An authenticated user can access non scoped routes
76
+ return;
84
77
  }
85
-
86
- const isAllowed = castArray(config.scope).every(scope => allowedActions.includes(scope));
87
-
88
- if (!isAllowed) {
89
- throw new ForbiddenError();
90
- }
91
-
92
- return;
93
78
  }
94
79
 
95
- const permissions = await strapi.query('plugin::users-permissions.permission').findMany({
96
- where: { role: user.role.id },
97
- });
80
+ let allowedActions = auth.allowedActions;
98
81
 
99
- const allowedActions = map('action', permissions);
82
+ if (!allowedActions) {
83
+ const permissions = await strapi.query('plugin::users-permissions.permission').findMany({
84
+ where: { role: user ? user.role.id : { type: 'public' } },
85
+ });
100
86
 
101
- // An authenticated user can access non scoped routes
102
- if (!config.scope) {
103
- return;
87
+ allowedActions = map('action', permissions);
88
+ auth.allowedActions = allowedActions;
104
89
  }
105
90
 
106
91
  const isAllowed = castArray(config.scope).every(scope => allowedActions.includes(scope));
@@ -108,12 +93,6 @@ const verify = async (auth, config) => {
108
93
  if (!isAllowed) {
109
94
  throw new ForbiddenError();
110
95
  }
111
-
112
- // TODO: if we need to keep policies for u&p execution
113
- // Execute the policies.
114
- // if (permission.policy) {
115
- // return await strapi.plugin('users-permissions').policy(permission.policy)(ctx, next);
116
- // }
117
96
  };
118
97
 
119
98
  module.exports = {