@strapi/plugin-users-permissions 4.3.4 → 4.3.7

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.
Files changed (75) hide show
  1. package/admin/src/components/BoundRoute/getMethodColor.js +1 -1
  2. package/admin/src/components/BoundRoute/index.js +1 -1
  3. package/admin/src/components/FormModal/Input/index.js +1 -1
  4. package/admin/src/components/FormModal/index.js +7 -9
  5. package/admin/src/components/Permissions/PermissionRow/CheckboxWrapper.js +3 -3
  6. package/admin/src/components/Permissions/PermissionRow/SubCategory.js +10 -14
  7. package/admin/src/components/Permissions/PermissionRow/index.js +1 -1
  8. package/admin/src/components/Permissions/index.js +2 -2
  9. package/admin/src/components/Permissions/init.js +1 -1
  10. package/admin/src/components/Permissions/reducer.js +1 -1
  11. package/admin/src/components/Policies/index.js +1 -1
  12. package/admin/src/components/UsersPermissions/index.js +5 -5
  13. package/admin/src/components/UsersPermissions/reducer.js +1 -1
  14. package/admin/src/hooks/useFetchRole/index.js +3 -3
  15. package/admin/src/hooks/useFetchRole/reducer.js +1 -1
  16. package/admin/src/hooks/useForm/index.js +1 -1
  17. package/admin/src/hooks/useForm/reducer.js +1 -1
  18. package/admin/src/hooks/usePlugins/index.js +1 -1
  19. package/admin/src/hooks/usePlugins/reducer.js +1 -1
  20. package/admin/src/hooks/useRolesList/reducer.js +1 -1
  21. package/admin/src/index.js +5 -5
  22. package/admin/src/pages/AdvancedSettings/index.js +12 -11
  23. package/admin/src/pages/AdvancedSettings/utils/api.js +1 -1
  24. package/admin/src/pages/AdvancedSettings/utils/schema.js +2 -4
  25. package/admin/src/pages/EmailTemplates/index.js +8 -8
  26. package/admin/src/pages/EmailTemplates/utils/api.js +1 -1
  27. package/admin/src/pages/EmailTemplates/utils/schema.js +1 -4
  28. package/admin/src/pages/Providers/index.js +22 -22
  29. package/admin/src/pages/Providers/reducer.js +1 -1
  30. package/admin/src/pages/Providers/utils/api.js +2 -2
  31. package/admin/src/pages/Providers/utils/createProvidersArray.js +1 -1
  32. package/admin/src/pages/Roles/CreatePage/index.js +1 -1
  33. package/admin/src/pages/Roles/EditPage/index.js +1 -1
  34. package/admin/src/pages/Roles/ListPage/components/TableBody.js +5 -4
  35. package/admin/src/pages/Roles/ListPage/index.js +3 -3
  36. package/admin/src/utils/axiosInstance.js +4 -4
  37. package/admin/src/utils/cleanPermissions.js +1 -1
  38. package/admin/src/utils/formatPolicies.js +1 -1
  39. package/admin/src/utils/getRequestURL.js +1 -1
  40. package/admin/src/utils/getTrad.js +1 -1
  41. package/documentation/content-api.yaml +54 -31
  42. package/jest.config.front.js +1 -1
  43. package/package.json +12 -7
  44. package/server/bootstrap/grant-config.js +1 -1
  45. package/server/bootstrap/index.js +39 -39
  46. package/server/controllers/auth.js +2 -5
  47. package/server/controllers/content-manager-user.js +4 -12
  48. package/server/controllers/settings.js +1 -1
  49. package/server/controllers/user.js +2 -2
  50. package/server/controllers/validation/auth.js +3 -12
  51. package/server/controllers/validation/email-template.js +3 -2
  52. package/server/controllers/validation/user.js +4 -16
  53. package/server/graphql/mutations/auth/change-password.js +1 -4
  54. package/server/graphql/mutations/auth/forgot-password.js +1 -4
  55. package/server/graphql/mutations/auth/login.js +1 -4
  56. package/server/graphql/mutations/auth/register.js +1 -4
  57. package/server/graphql/mutations/auth/reset-password.js +1 -4
  58. package/server/graphql/mutations/crud/role/create-role.js +1 -4
  59. package/server/graphql/mutations/crud/role/delete-role.js +1 -4
  60. package/server/graphql/mutations/crud/role/update-role.js +1 -4
  61. package/server/graphql/mutations/crud/user/create-user.js +1 -4
  62. package/server/graphql/mutations/crud/user/delete-user.js +1 -4
  63. package/server/graphql/mutations/crud/user/update-user.js +1 -4
  64. package/server/graphql/mutations/index.js +1 -1
  65. package/server/graphql/types/index.js +1 -1
  66. package/server/middlewares/rateLimit.js +22 -25
  67. package/server/register.js +2 -4
  68. package/server/services/jwt.js +11 -9
  69. package/server/services/providers-registry.js +33 -42
  70. package/server/services/providers.js +6 -6
  71. package/server/services/role.js +7 -7
  72. package/server/services/user.js +1 -1
  73. package/server/services/users-permissions.js +12 -12
  74. package/server/strategies/users-permissions.js +3 -3
  75. package/server/utils/index.js +1 -1
@@ -259,10 +259,7 @@ module.exports = {
259
259
  await getService('user').edit(user.id, { resetPasswordToken });
260
260
 
261
261
  // Send an email to the user.
262
- await strapi
263
- .plugin('email')
264
- .service('email')
265
- .send(emailToSend);
262
+ await strapi.plugin('email').service('email').send(emailToSend);
266
263
 
267
264
  ctx.send({ ok: true });
268
265
  },
@@ -326,7 +323,7 @@ module.exports = {
326
323
  }
327
324
  }
328
325
 
329
- let newUser = {
326
+ const newUser = {
330
327
  ...params,
331
328
  role: role.id,
332
329
  email: email.toLowerCase(),
@@ -2,12 +2,8 @@
2
2
 
3
3
  const _ = require('lodash');
4
4
  const { contentTypes: contentTypesUtils } = require('@strapi/utils');
5
- const {
6
- ApplicationError,
7
- ValidationError,
8
- NotFoundError,
9
- ForbiddenError,
10
- } = require('@strapi/utils').errors;
5
+ const { ApplicationError, ValidationError, NotFoundError, ForbiddenError } =
6
+ require('@strapi/utils').errors;
11
7
  const { validateCreateUserBody, validateUpdateUserBody } = require('./validation/user');
12
8
 
13
9
  const { UPDATED_BY_ATTRIBUTE, CREATED_BY_ATTRIBUTE } = contentTypesUtils.constants;
@@ -132,17 +128,13 @@ module.exports = {
132
128
 
133
129
  const { email, username, password } = body;
134
130
 
135
- let pm;
136
- let user;
137
-
138
- const { pm: permissionManager, entity } = await findEntityAndCheckPermissions(
131
+ const { pm, entity } = await findEntityAndCheckPermissions(
139
132
  userAbility,
140
133
  ACTIONS.edit,
141
134
  userModel,
142
135
  id
143
136
  );
144
- pm = permissionManager;
145
- user = entity;
137
+ const user = entity;
146
138
 
147
139
  await validateUpdateUserBody(ctx.request.body);
148
140
 
@@ -17,7 +17,7 @@ module.exports = {
17
17
 
18
18
  const emailTemplates = ctx.request.body['email-templates'];
19
19
 
20
- for (let key in emailTemplates) {
20
+ for (const key of Object.keys(emailTemplates)) {
21
21
  const template = emailTemplates[key].options.message;
22
22
 
23
23
  if (!isValidEmailTemplate(template)) {
@@ -121,7 +121,7 @@ module.exports = {
121
121
  ctx.request.body.email = ctx.request.body.email.toLowerCase();
122
122
  }
123
123
 
124
- let updateData = {
124
+ const updateData = {
125
125
  ...ctx.request.body,
126
126
  };
127
127
 
@@ -138,7 +138,7 @@ module.exports = {
138
138
  async find(ctx) {
139
139
  const users = await getService('user').fetchAll(ctx.query);
140
140
 
141
- ctx.body = await Promise.all(users.map(user => sanitizeOutput(user, ctx)));
141
+ ctx.body = await Promise.all(users.map((user) => sanitizeOutput(user, ctx)));
142
142
  },
143
143
 
144
144
  /**
@@ -8,19 +8,13 @@ const callbackSchema = yup.object({
8
8
  });
9
9
 
10
10
  const registerSchema = yup.object({
11
- email: yup
12
- .string()
13
- .email()
14
- .required(),
11
+ email: yup.string().email().required(),
15
12
  username: yup.string().required(),
16
13
  password: yup.string().required(),
17
14
  });
18
15
 
19
16
  const sendEmailConfirmationSchema = yup.object({
20
- email: yup
21
- .string()
22
- .email()
23
- .required(),
17
+ email: yup.string().email().required(),
24
18
  });
25
19
 
26
20
  const validateEmailConfirmationSchema = yup.object({
@@ -29,10 +23,7 @@ const validateEmailConfirmationSchema = yup.object({
29
23
 
30
24
  const forgotPasswordSchema = yup
31
25
  .object({
32
- email: yup
33
- .string()
34
- .email()
35
- .required(),
26
+ email: yup.string().email().required(),
36
27
  })
37
28
  .noUnknown();
38
29
 
@@ -19,6 +19,7 @@ const matchAll = (pattern, src) => {
19
19
  let match;
20
20
 
21
21
  const regexPatternWithGlobal = RegExp(pattern, 'g');
22
+ // eslint-disable-next-line no-cond-assign
22
23
  while ((match = regexPatternWithGlobal.exec(src))) {
23
24
  const [, group] = match;
24
25
 
@@ -27,8 +28,8 @@ const matchAll = (pattern, src) => {
27
28
  return matches;
28
29
  };
29
30
 
30
- const isValidEmailTemplate = template => {
31
- for (let reg of invalidPatternsRegexes) {
31
+ const isValidEmailTemplate = (template) => {
32
+ for (const reg of invalidPatternsRegexes) {
32
33
  if (reg.test(template)) {
33
34
  return false;
34
35
  }
@@ -7,26 +7,14 @@ const deleteRoleSchema = yup.object().shape({
7
7
  });
8
8
 
9
9
  const createUserBodySchema = yup.object().shape({
10
- email: yup
11
- .string()
12
- .email()
13
- .required(),
14
- username: yup
15
- .string()
16
- .min(1)
17
- .required(),
18
- password: yup
19
- .string()
20
- .min(1)
21
- .required(),
10
+ email: yup.string().email().required(),
11
+ username: yup.string().min(1).required(),
12
+ password: yup.string().min(1).required(),
22
13
  role: yup.strapiID(),
23
14
  });
24
15
 
25
16
  const updateUserBodySchema = yup.object().shape({
26
- email: yup
27
- .string()
28
- .email()
29
- .min(1),
17
+ email: yup.string().email().min(1),
30
18
  username: yup.string().min(1),
31
19
  password: yup.string().min(1),
32
20
  });
@@ -23,10 +23,7 @@ module.exports = ({ nexus, strapi }) => {
23
23
 
24
24
  koaContext.request.body = toPlainObject(args);
25
25
 
26
- await strapi
27
- .plugin('users-permissions')
28
- .controller('auth')
29
- .changePassword(koaContext);
26
+ await strapi.plugin('users-permissions').controller('auth').changePassword(koaContext);
30
27
 
31
28
  const output = koaContext.body;
32
29
 
@@ -21,10 +21,7 @@ module.exports = ({ nexus, strapi }) => {
21
21
 
22
22
  koaContext.request.body = toPlainObject(args);
23
23
 
24
- await strapi
25
- .plugin('users-permissions')
26
- .controller('auth')
27
- .forgotPassword(koaContext);
24
+ await strapi.plugin('users-permissions').controller('auth').forgotPassword(koaContext);
28
25
 
29
26
  const output = koaContext.body;
30
27
 
@@ -20,10 +20,7 @@ module.exports = ({ nexus, strapi }) => {
20
20
  koaContext.params = { provider: args.input.provider };
21
21
  koaContext.request.body = toPlainObject(args.input);
22
22
 
23
- await strapi
24
- .plugin('users-permissions')
25
- .controller('auth')
26
- .callback(koaContext);
23
+ await strapi.plugin('users-permissions').controller('auth').callback(koaContext);
27
24
 
28
25
  const output = koaContext.body;
29
26
 
@@ -21,10 +21,7 @@ module.exports = ({ nexus, strapi }) => {
21
21
 
22
22
  koaContext.request.body = toPlainObject(args.input);
23
23
 
24
- await strapi
25
- .plugin('users-permissions')
26
- .controller('auth')
27
- .register(koaContext);
24
+ await strapi.plugin('users-permissions').controller('auth').register(koaContext);
28
25
 
29
26
  const output = koaContext.body;
30
27
 
@@ -23,10 +23,7 @@ module.exports = ({ nexus, strapi }) => {
23
23
 
24
24
  koaContext.request.body = toPlainObject(args);
25
25
 
26
- await strapi
27
- .plugin('users-permissions')
28
- .controller('auth')
29
- .resetPassword(koaContext);
26
+ await strapi.plugin('users-permissions').controller('auth').resetPassword(koaContext);
30
27
 
31
28
  const output = koaContext.body;
32
29
 
@@ -26,10 +26,7 @@ module.exports = ({ nexus, strapi }) => {
26
26
 
27
27
  koaContext.request.body = toPlainObject(args.data);
28
28
 
29
- await strapi
30
- .plugin('users-permissions')
31
- .controller('role')
32
- .createRole(koaContext);
29
+ await strapi.plugin('users-permissions').controller('role').createRole(koaContext);
33
30
 
34
31
  return { ok: true };
35
32
  },
@@ -17,10 +17,7 @@ module.exports = ({ nexus, strapi }) => {
17
17
 
18
18
  koaContext.params = { role: args.id };
19
19
 
20
- await strapi
21
- .plugin('users-permissions')
22
- .controller('role')
23
- .deleteRole(koaContext);
20
+ await strapi.plugin('users-permissions').controller('role').deleteRole(koaContext);
24
21
 
25
22
  return { ok: true };
26
23
  },
@@ -27,10 +27,7 @@ module.exports = ({ nexus, strapi }) => {
27
27
  koaContext.request.body = args.data;
28
28
  koaContext.request.body.role = args.id;
29
29
 
30
- await strapi
31
- .plugin('users-permissions')
32
- .controller('role')
33
- .updateRole(koaContext);
30
+ await strapi.plugin('users-permissions').controller('role').updateRole(koaContext);
34
31
 
35
32
  return { ok: true };
36
33
  },
@@ -32,10 +32,7 @@ module.exports = ({ nexus, strapi }) => {
32
32
  koaContext.params = {};
33
33
  koaContext.request.body = toPlainObject(args.data);
34
34
 
35
- await strapi
36
- .plugin('users-permissions')
37
- .controller('user')
38
- .create(koaContext);
35
+ await strapi.plugin('users-permissions').controller('user').create(koaContext);
39
36
 
40
37
  checkBadRequest(koaContext.body);
41
38
 
@@ -26,10 +26,7 @@ module.exports = ({ nexus, strapi }) => {
26
26
 
27
27
  koaContext.params = { id: args.id };
28
28
 
29
- await strapi
30
- .plugin('users-permissions')
31
- .controller('user')
32
- .destroy(koaContext);
29
+ await strapi.plugin('users-permissions').controller('user').destroy(koaContext);
33
30
 
34
31
  checkBadRequest(koaContext.body);
35
32
 
@@ -33,10 +33,7 @@ module.exports = ({ nexus, strapi }) => {
33
33
  koaContext.params = { id: args.id };
34
34
  koaContext.request.body = toPlainObject(args.data);
35
35
 
36
- await strapi
37
- .plugin('users-permissions')
38
- .controller('user')
39
- .update(koaContext);
36
+ await strapi.plugin('users-permissions').controller('user').update(koaContext);
40
37
 
41
38
  checkBadRequest(koaContext.body);
42
39
 
@@ -3,7 +3,7 @@
3
3
  const userUID = 'plugin::users-permissions.user';
4
4
  const roleUID = 'plugin::users-permissions.role';
5
5
 
6
- module.exports = context => {
6
+ module.exports = (context) => {
7
7
  const { nexus, strapi } = context;
8
8
 
9
9
  const { naming } = strapi.plugin('graphql').service('utils');
@@ -18,4 +18,4 @@ const typesFactories = [
18
18
  * @param {object} context.strapi
19
19
  * @return {any[]}
20
20
  */
21
- module.exports = context => typesFactories.map(factory => factory(context));
21
+ module.exports = (context) => typesFactories.map((factory) => factory(context));
@@ -1,30 +1,27 @@
1
1
  'use strict';
2
2
 
3
- module.exports = (config, { strapi }) => async (ctx, next) => {
4
- const ratelimit = require('koa2-ratelimit').RateLimit;
3
+ module.exports =
4
+ (config, { strapi }) =>
5
+ async (ctx, next) => {
6
+ const ratelimit = require('koa2-ratelimit').RateLimit;
5
7
 
6
- const message = [
7
- {
8
- messages: [
9
- {
10
- id: 'Auth.form.error.ratelimit',
11
- message: 'Too many attempts, please try again in a minute.',
12
- },
13
- ],
14
- },
15
- ];
16
-
17
- return ratelimit.middleware(
18
- Object.assign(
19
- {},
8
+ const message = [
20
9
  {
21
- interval: 1 * 60 * 1000,
22
- max: 5,
23
- prefixKey: `${ctx.request.path}:${ctx.request.ip}`,
24
- message,
10
+ messages: [
11
+ {
12
+ id: 'Auth.form.error.ratelimit',
13
+ message: 'Too many attempts, please try again in a minute.',
14
+ },
15
+ ],
25
16
  },
26
- strapi.config.get('plugin.users-permissions.ratelimit'),
27
- config
28
- )
29
- )(ctx, next);
30
- };
17
+ ];
18
+
19
+ return ratelimit.middleware({
20
+ interval: 1 * 60 * 1000,
21
+ max: 5,
22
+ prefixKey: `${ctx.request.path}:${ctx.request.ip}`,
23
+ message,
24
+ ...strapi.config.get('plugin.users-permissions.ratelimit'),
25
+ ...config,
26
+ })(ctx, next);
27
+ };
@@ -1,4 +1,5 @@
1
1
  'use strict';
2
+
2
3
  const fs = require('fs');
3
4
  const path = require('path');
4
5
 
@@ -17,9 +18,6 @@ module.exports = ({ strapi }) => {
17
18
  const specPath = path.join(__dirname, '../documentation/content-api.yaml');
18
19
  const spec = fs.readFileSync(specPath, 'utf8');
19
20
 
20
- strapi
21
- .plugin('documentation')
22
- .service('documentation')
23
- .registerDoc(spec);
21
+ strapi.plugin('documentation').service('documentation').registerDoc(spec);
24
22
  }
25
23
  };
@@ -38,16 +38,18 @@ module.exports = ({ strapi }) => ({
38
38
  },
39
39
 
40
40
  verify(token) {
41
- return new Promise(function(resolve, reject) {
42
- jwt.verify(token, strapi.config.get('plugin.users-permissions.jwtSecret'), {}, function(
43
- err,
44
- tokenPayload = {}
45
- ) {
46
- if (err) {
47
- return reject(new Error('Invalid token.'));
41
+ return new Promise((resolve, reject) => {
42
+ jwt.verify(
43
+ token,
44
+ strapi.config.get('plugin.users-permissions.jwtSecret'),
45
+ {},
46
+ (err, tokenPayload = {}) => {
47
+ if (err) {
48
+ return reject(new Error('Invalid token.'));
49
+ }
50
+ resolve(tokenPayload);
48
51
  }
49
- resolve(tokenPayload);
50
- });
52
+ );
51
53
  });
52
54
  },
53
55
  });