@strapi/plugin-users-permissions 4.12.0-beta.5 → 4.12.1
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.
- package/admin/src/hooks/useForm/index.js +1 -3
- package/admin/src/pages/AdvancedSettings/utils/api.js +2 -4
- package/admin/src/pages/EmailTemplates/utils/api.js +2 -4
- package/admin/src/pages/Providers/utils/api.js +2 -4
- package/admin/src/pages/Roles/ListPage/utils/api.js +2 -4
- package/admin/src/utils/index.js +0 -1
- package/documentation/content-api.yaml +1 -1
- package/package.json +7 -7
- package/server/middlewares/rateLimit.js +41 -21
- package/admin/src/utils/getRequestURL.js +0 -5
|
@@ -2,8 +2,6 @@ import { useCallback, useEffect, useReducer, useRef } from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { useFetchClient, useNotification, useRBAC } from '@strapi/helper-plugin';
|
|
4
4
|
|
|
5
|
-
import { getRequestURL } from '../../utils';
|
|
6
|
-
|
|
7
5
|
import reducer, { initialState } from './reducer';
|
|
8
6
|
|
|
9
7
|
const useUserForm = (endPoint, permissions) => {
|
|
@@ -21,7 +19,7 @@ const useUserForm = (endPoint, permissions) => {
|
|
|
21
19
|
type: 'GET_DATA',
|
|
22
20
|
});
|
|
23
21
|
|
|
24
|
-
const { data } = await get(
|
|
22
|
+
const { data } = await get(`/users-permissions/${endPoint}`);
|
|
25
23
|
|
|
26
24
|
dispatch({
|
|
27
25
|
type: 'GET_DATA_SUCCEEDED',
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { getFetchClient } from '@strapi/helper-plugin';
|
|
2
2
|
|
|
3
|
-
import { getRequestURL } from '../../../utils';
|
|
4
|
-
|
|
5
3
|
const fetchData = async () => {
|
|
6
4
|
const { get } = getFetchClient();
|
|
7
|
-
const { data } = await get(
|
|
5
|
+
const { data } = await get('/users-permissions/advanced');
|
|
8
6
|
|
|
9
7
|
return data;
|
|
10
8
|
};
|
|
@@ -12,7 +10,7 @@ const fetchData = async () => {
|
|
|
12
10
|
const putAdvancedSettings = (body) => {
|
|
13
11
|
const { put } = getFetchClient();
|
|
14
12
|
|
|
15
|
-
return put(
|
|
13
|
+
return put('/users-permissions/advanced', body);
|
|
16
14
|
};
|
|
17
15
|
|
|
18
16
|
export { fetchData, putAdvancedSettings };
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { getFetchClient } from '@strapi/helper-plugin';
|
|
2
2
|
|
|
3
|
-
import { getRequestURL } from '../../../utils';
|
|
4
|
-
|
|
5
3
|
const fetchData = async () => {
|
|
6
4
|
const { get } = getFetchClient();
|
|
7
|
-
const { data } = await get(
|
|
5
|
+
const { data } = await get('/users-permissions/email-templates');
|
|
8
6
|
|
|
9
7
|
return data;
|
|
10
8
|
};
|
|
@@ -12,7 +10,7 @@ const fetchData = async () => {
|
|
|
12
10
|
const putEmailTemplate = (body) => {
|
|
13
11
|
const { put } = getFetchClient();
|
|
14
12
|
|
|
15
|
-
return put(
|
|
13
|
+
return put('/users-permissions/email-templates', body);
|
|
16
14
|
};
|
|
17
15
|
|
|
18
16
|
export { fetchData, putEmailTemplate };
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { getFetchClient } from '@strapi/helper-plugin';
|
|
2
2
|
|
|
3
|
-
import { getRequestURL } from '../../../utils';
|
|
4
|
-
|
|
5
3
|
// eslint-disable-next-line import/prefer-default-export
|
|
6
4
|
export const fetchData = async (toggleNotification) => {
|
|
7
5
|
try {
|
|
8
6
|
const { get } = getFetchClient();
|
|
9
|
-
const { data } = await get(
|
|
7
|
+
const { data } = await get('/users-permissions/providers');
|
|
10
8
|
|
|
11
9
|
return data;
|
|
12
10
|
} catch (err) {
|
|
@@ -22,5 +20,5 @@ export const fetchData = async (toggleNotification) => {
|
|
|
22
20
|
export const putProvider = (body) => {
|
|
23
21
|
const { put } = getFetchClient();
|
|
24
22
|
|
|
25
|
-
return put(
|
|
23
|
+
return put('/users-permissions/providers', body);
|
|
26
24
|
};
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { getFetchClient } from '@strapi/helper-plugin';
|
|
2
2
|
|
|
3
|
-
import { getRequestURL } from '../../../../utils';
|
|
4
|
-
|
|
5
3
|
export const fetchData = async (toggleNotification, notifyStatus) => {
|
|
6
4
|
try {
|
|
7
5
|
const { get } = getFetchClient();
|
|
8
|
-
const { data } = await get(
|
|
6
|
+
const { data } = await get('/users-permissions/roles');
|
|
9
7
|
notifyStatus('The roles have loaded successfully');
|
|
10
8
|
|
|
11
9
|
return data;
|
|
@@ -22,7 +20,7 @@ export const fetchData = async (toggleNotification, notifyStatus) => {
|
|
|
22
20
|
export const deleteData = async (id, toggleNotification) => {
|
|
23
21
|
try {
|
|
24
22
|
const { del } = getFetchClient();
|
|
25
|
-
await del(
|
|
23
|
+
await del(`/users-permissions/roles/${id}`);
|
|
26
24
|
} catch (error) {
|
|
27
25
|
toggleNotification({
|
|
28
26
|
type: 'warning',
|
package/admin/src/utils/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/plugin-users-permissions",
|
|
3
|
-
"version": "4.12.
|
|
3
|
+
"version": "4.12.1",
|
|
4
4
|
"description": "Protect your API with a full-authentication process based on JWT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -30,16 +30,16 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@strapi/design-system": "1.8.2",
|
|
33
|
-
"@strapi/helper-plugin": "4.12.
|
|
33
|
+
"@strapi/helper-plugin": "4.12.1",
|
|
34
34
|
"@strapi/icons": "1.8.2",
|
|
35
|
-
"@strapi/utils": "4.12.
|
|
35
|
+
"@strapi/utils": "4.12.1",
|
|
36
36
|
"bcryptjs": "2.4.3",
|
|
37
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": "
|
|
42
|
+
"koa": "2.13.4",
|
|
43
43
|
"koa2-ratelimit": "^1.1.2",
|
|
44
44
|
"lodash": "4.17.21",
|
|
45
45
|
"prop-types": "^15.8.1",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"react-query": "3.39.3",
|
|
49
49
|
"react-redux": "8.1.1",
|
|
50
50
|
"url-join": "4.0.1",
|
|
51
|
-
"yup": "
|
|
51
|
+
"yup": "0.32.9"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@testing-library/dom": "9.2.0",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"styled-components": "5.3.3"
|
|
68
68
|
},
|
|
69
69
|
"engines": {
|
|
70
|
-
"node": ">=
|
|
70
|
+
"node": ">=16.0.0 <=20.x.x",
|
|
71
71
|
"npm": ">=6.0.0"
|
|
72
72
|
},
|
|
73
73
|
"strapi": {
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"required": true,
|
|
78
78
|
"kind": "plugin"
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "be8985fa20cb357981bca97bc65ee5c1b843f801"
|
|
81
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
{
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
};
|