@strapi/plugin-users-permissions 0.0.0-next.e9bb5ccdc459f4c6b6717a2d5d86359b7a47d47d → 0.0.0-next.f5107c72369ee86a8ec1b6782f2e890925033ca3

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 (49) hide show
  1. package/admin/src/components/BoundRoute/index.js +5 -3
  2. package/admin/src/components/FormModal/Input/index.js +6 -3
  3. package/admin/src/components/FormModal/index.js +13 -10
  4. package/admin/src/components/Permissions/PermissionRow/CheckboxWrapper.js +1 -1
  5. package/admin/src/components/Permissions/PermissionRow/SubCategory.js +26 -5
  6. package/admin/src/components/Permissions/PermissionRow/index.js +4 -2
  7. package/admin/src/components/Permissions/index.js +5 -2
  8. package/admin/src/components/Policies/index.js +3 -2
  9. package/admin/src/components/UsersPermissions/index.js +8 -5
  10. package/admin/src/{permissions.js → constants.js} +1 -3
  11. package/admin/src/contexts/UsersPermissionsContext/index.js +1 -0
  12. package/admin/src/hooks/index.js +1 -1
  13. package/admin/src/hooks/useFetchRole/index.js +6 -3
  14. package/admin/src/hooks/useForm/index.js +4 -3
  15. package/admin/src/hooks/usePlugins.js +71 -0
  16. package/admin/src/hooks/useRolesList/index.js +4 -1
  17. package/admin/src/index.js +7 -5
  18. package/admin/src/pages/AdvancedSettings/index.js +27 -28
  19. package/admin/src/pages/AdvancedSettings/utils/api.js +2 -3
  20. package/admin/src/pages/AdvancedSettings/utils/schema.js +1 -1
  21. package/admin/src/pages/EmailTemplates/components/EmailForm.js +14 -13
  22. package/admin/src/pages/EmailTemplates/components/EmailTable.js +9 -7
  23. package/admin/src/pages/EmailTemplates/index.js +16 -17
  24. package/admin/src/pages/EmailTemplates/utils/api.js +2 -3
  25. package/admin/src/pages/EmailTemplates/utils/schema.js +1 -1
  26. package/admin/src/pages/Providers/index.js +31 -32
  27. package/admin/src/pages/Providers/utils/api.js +2 -3
  28. package/admin/src/pages/Providers/utils/forms.js +1 -1
  29. package/admin/src/pages/Roles/{CreatePage/index.js → CreatePage.js} +26 -23
  30. package/admin/src/pages/Roles/{EditPage/index.js → EditPage.js} +23 -20
  31. package/admin/src/pages/Roles/ListPage/components/TableBody.js +4 -3
  32. package/admin/src/pages/Roles/ListPage/index.js +31 -34
  33. package/admin/src/pages/Roles/ListPage/utils/api.js +3 -4
  34. package/admin/src/pages/Roles/{ProtectedCreatePage/index.js → ProtectedCreatePage.js} +6 -3
  35. package/admin/src/pages/Roles/{ProtectedEditPage/index.js → ProtectedEditPage.js} +6 -3
  36. package/admin/src/pages/Roles/{ProtectedListPage/index.js → ProtectedListPage.js} +5 -3
  37. package/admin/src/pages/Roles/{CreatePage/utils/schema.js → constants.js} +2 -4
  38. package/admin/src/pages/Roles/index.js +9 -6
  39. package/admin/src/utils/index.js +1 -2
  40. package/documentation/content-api.yaml +1 -1
  41. package/jest.config.front.js +1 -0
  42. package/package.json +21 -24
  43. package/server/middlewares/rateLimit.js +41 -21
  44. package/server/strategies/users-permissions.js +1 -8
  45. package/admin/src/hooks/usePlugins/index.js +0 -67
  46. package/admin/src/hooks/usePlugins/init.js +0 -5
  47. package/admin/src/hooks/usePlugins/reducer.js +0 -34
  48. package/admin/src/pages/Roles/EditPage/utils/schema.js +0 -9
  49. package/admin/src/utils/getRequestURL.js +0 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/plugin-users-permissions",
3
- "version": "0.0.0-next.e9bb5ccdc459f4c6b6717a2d5d86359b7a47d47d",
3
+ "version": "0.0.0-next.f5107c72369ee86a8ec1b6782f2e890925033ca3",
4
4
  "description": "Protect your API with a full-authentication process based on JWT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,48 +29,45 @@
29
29
  "lint": "run -T eslint ."
30
30
  },
31
31
  "dependencies": {
32
- "@strapi/design-system": "1.7.5",
33
- "@strapi/helper-plugin": "0.0.0-next.e9bb5ccdc459f4c6b6717a2d5d86359b7a47d47d",
34
- "@strapi/icons": "1.7.5",
35
- "@strapi/utils": "0.0.0-next.e9bb5ccdc459f4c6b6717a2d5d86359b7a47d47d",
32
+ "@strapi/design-system": "1.8.2",
33
+ "@strapi/helper-plugin": "0.0.0-next.f5107c72369ee86a8ec1b6782f2e890925033ca3",
34
+ "@strapi/icons": "1.8.2",
35
+ "@strapi/utils": "0.0.0-next.f5107c72369ee86a8ec1b6782f2e890925033ca3",
36
36
  "bcryptjs": "2.4.3",
37
- "formik": "2.2.9",
37
+ "formik": "2.4.0",
38
38
  "grant-koa": "5.4.8",
39
39
  "immer": "9.0.19",
40
40
  "jsonwebtoken": "9.0.0",
41
41
  "jwk-to-pem": "2.0.5",
42
- "koa": "^2.13.4",
42
+ "koa": "2.13.4",
43
43
  "koa2-ratelimit": "^1.1.2",
44
44
  "lodash": "4.17.21",
45
- "prop-types": "^15.7.2",
45
+ "prop-types": "^15.8.1",
46
46
  "purest": "4.0.2",
47
47
  "react-intl": "6.4.1",
48
- "react-query": "3.24.3",
49
- "react-redux": "8.0.5",
48
+ "react-query": "3.39.3",
49
+ "react-redux": "8.1.1",
50
50
  "url-join": "4.0.1",
51
- "yup": "^0.32.9"
51
+ "yup": "0.32.9"
52
52
  },
53
53
  "devDependencies": {
54
- "@testing-library/dom": "8.19.0",
55
- "@testing-library/react": "12.1.4",
56
- "@testing-library/react-hooks": "8.0.1",
54
+ "@testing-library/dom": "9.2.0",
55
+ "@testing-library/react": "14.0.0",
57
56
  "@testing-library/user-event": "14.4.3",
58
- "history": "^4.9.0",
59
57
  "msw": "1.2.1",
60
- "react": "^17.0.2",
61
- "react-dom": "^17.0.2",
58
+ "react": "^18.2.0",
59
+ "react-dom": "^18.2.0",
62
60
  "react-router-dom": "5.3.4",
63
- "react-test-renderer": "^17.0.2",
64
61
  "styled-components": "5.3.3"
65
62
  },
66
63
  "peerDependencies": {
67
- "react": "^17.0.2",
68
- "react-dom": "^17.0.2",
69
- "react-router-dom": "^5.3.4",
70
- "styled-components": "^5.3.3"
64
+ "react": "^17.0.0 || ^18.0.0",
65
+ "react-dom": "^17.0.0 || ^18.0.0",
66
+ "react-router-dom": "5.3.4",
67
+ "styled-components": "5.3.3"
71
68
  },
72
69
  "engines": {
73
- "node": ">=14.19.1 <=18.x.x",
70
+ "node": ">=16.0.0 <=20.x.x",
74
71
  "npm": ">=6.0.0"
75
72
  },
76
73
  "strapi": {
@@ -80,5 +77,5 @@
80
77
  "required": true,
81
78
  "kind": "plugin"
82
79
  },
83
- "gitHead": "e9bb5ccdc459f4c6b6717a2d5d86359b7a47d47d"
80
+ "gitHead": "f5107c72369ee86a8ec1b6782f2e890925033ca3"
84
81
  }
@@ -1,27 +1,47 @@
1
1
  'use strict';
2
2
 
3
+ const path = require('path');
4
+ const utils = require('@strapi/utils');
5
+ const { isString, has, toLower } = require('lodash/fp');
6
+
7
+ const { RateLimitError } = utils.errors;
8
+
3
9
  module.exports =
4
10
  (config, { strapi }) =>
5
11
  async (ctx, next) => {
6
- const ratelimit = require('koa2-ratelimit').RateLimit;
7
-
8
- const message = [
9
- {
10
- messages: [
11
- {
12
- id: 'Auth.form.error.ratelimit',
13
- message: 'Too many attempts, please try again in a minute.',
14
- },
15
- ],
16
- },
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);
12
+ let rateLimitConfig = strapi.config.get('plugin.users-permissions.ratelimit');
13
+
14
+ if (!rateLimitConfig) {
15
+ rateLimitConfig = {
16
+ enabled: true,
17
+ };
18
+ }
19
+
20
+ if (!has('enabled', rateLimitConfig)) {
21
+ rateLimitConfig.enabled = true;
22
+ }
23
+
24
+ if (rateLimitConfig.enabled === true) {
25
+ const rateLimit = require('koa2-ratelimit').RateLimit;
26
+
27
+ const userIdentifier = toLower(ctx.request.body.email) || 'unknownIdentifier';
28
+ const requestPath = isString(ctx.request.path)
29
+ ? toLower(path.normalize(ctx.request.path))
30
+ : 'invalidPath';
31
+
32
+ const loadConfig = {
33
+ interval: { min: 5 },
34
+ max: 5,
35
+ prefixKey: `${userIdentifier}:${requestPath}:${ctx.request.ip}`,
36
+ handler() {
37
+ throw new RateLimitError();
38
+ },
39
+ ...rateLimitConfig,
40
+ ...config,
41
+ };
42
+
43
+ return rateLimit.middleware(loadConfig)(ctx, next);
44
+ }
45
+
46
+ return next();
27
47
  };
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const { castArray, map, every, pipe, isEmpty } = require('lodash/fp');
3
+ const { castArray, map, every, pipe } = require('lodash/fp');
4
4
  const { ForbiddenError, UnauthorizedError } = require('@strapi/utils').errors;
5
5
 
6
6
  const { getService } = require('../utils');
@@ -80,13 +80,6 @@ const authenticate = async (ctx) => {
80
80
  const verify = async (auth, config) => {
81
81
  const { credentials: user, ability } = auth;
82
82
 
83
- strapi.telemetry.send('didReceiveAPIRequest', {
84
- eventProperties: {
85
- authenticationMethod: auth?.strategy?.name,
86
- isAuthenticated: !isEmpty(user),
87
- },
88
- });
89
-
90
83
  if (!config.scope) {
91
84
  if (!user) {
92
85
  // A non authenticated user cannot access routes that do not have a scope
@@ -1,67 +0,0 @@
1
- import { useCallback, useEffect, useReducer } from 'react';
2
- import { useNotification, useFetchClient } from '@strapi/helper-plugin';
3
- import get from 'lodash/get';
4
- import init from './init';
5
- import pluginId from '../../pluginId';
6
- import { cleanPermissions } from '../../utils';
7
- import reducer, { initialState } from './reducer';
8
-
9
- const usePlugins = (shouldFetchData = true) => {
10
- const toggleNotification = useNotification();
11
- const [{ permissions, routes, isLoading }, dispatch] = useReducer(reducer, initialState, () =>
12
- init(initialState, shouldFetchData)
13
- );
14
- const fetchClient = useFetchClient();
15
-
16
- const fetchPlugins = useCallback(async () => {
17
- try {
18
- dispatch({
19
- type: 'GET_DATA',
20
- });
21
-
22
- const [{ permissions }, { routes }] = await Promise.all(
23
- [`/${pluginId}/permissions`, `/${pluginId}/routes`].map(async (endpoint) => {
24
- const res = await fetchClient.get(endpoint);
25
-
26
- return res.data;
27
- })
28
- );
29
-
30
- dispatch({
31
- type: 'GET_DATA_SUCCEEDED',
32
- permissions: cleanPermissions(permissions),
33
- routes,
34
- });
35
- } catch (err) {
36
- const message = get(err, ['response', 'payload', 'message'], 'An error occured');
37
-
38
- dispatch({
39
- type: 'GET_DATA_ERROR',
40
- });
41
-
42
- if (message !== 'Forbidden') {
43
- toggleNotification({
44
- type: 'warning',
45
- message,
46
- });
47
- }
48
- }
49
-
50
- // eslint-disable-next-line react-hooks/exhaustive-deps
51
- }, [toggleNotification]);
52
-
53
- useEffect(() => {
54
- if (shouldFetchData) {
55
- fetchPlugins();
56
- }
57
- }, [fetchPlugins, shouldFetchData]);
58
-
59
- return {
60
- permissions,
61
- routes,
62
- getData: fetchPlugins,
63
- isLoading,
64
- };
65
- };
66
-
67
- export default usePlugins;
@@ -1,5 +0,0 @@
1
- const init = (initialState, shouldFetchData) => {
2
- return { ...initialState, isLoading: shouldFetchData };
3
- };
4
-
5
- export default init;
@@ -1,34 +0,0 @@
1
- /* eslint-disable consistent-return */
2
- import produce from 'immer';
3
-
4
- export const initialState = {
5
- permissions: {},
6
- routes: {},
7
- isLoading: true,
8
- };
9
-
10
- const reducer = (state, action) =>
11
- produce(state, (draftState) => {
12
- switch (action.type) {
13
- case 'GET_DATA': {
14
- draftState.isLoading = true;
15
- draftState.permissions = {};
16
- draftState.routes = {};
17
- break;
18
- }
19
- case 'GET_DATA_SUCCEEDED': {
20
- draftState.permissions = action.permissions;
21
- draftState.routes = action.routes;
22
- draftState.isLoading = false;
23
- break;
24
- }
25
- case 'GET_DATA_ERROR': {
26
- draftState.isLoading = false;
27
- break;
28
- }
29
- default:
30
- return draftState;
31
- }
32
- });
33
-
34
- export default reducer;
@@ -1,9 +0,0 @@
1
- import * as yup from 'yup';
2
- import { translatedErrors } from '@strapi/helper-plugin';
3
-
4
- const schema = yup.object().shape({
5
- name: yup.string().required(translatedErrors.required),
6
- description: yup.string().required(translatedErrors.required),
7
- });
8
-
9
- export default schema;
@@ -1,5 +0,0 @@
1
- import pluginId from '../pluginId';
2
-
3
- const getRequestURL = (endPoint) => `/${pluginId}/${endPoint}`;
4
-
5
- export default getRequestURL;