@strapi/plugin-users-permissions 4.6.0 → 4.7.0-beta.0
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/useFetchRole/index.js +3 -3
- package/admin/src/hooks/usePlugins/index.js +5 -3
- package/admin/src/pages/AdvancedSettings/utils/api.js +7 -3
- package/admin/src/pages/EmailTemplates/utils/api.js +7 -3
- package/admin/src/pages/Providers/utils/api.js +7 -3
- package/admin/src/pages/Roles/CreatePage/index.js +3 -2
- package/admin/src/pages/Roles/EditPage/index.js +3 -2
- package/admin/src/pages/Roles/ListPage/utils/api.js +6 -3
- package/admin/src/utils/index.js +0 -1
- package/package.json +7 -7
- package/server/bootstrap/grant-config.js +8 -0
- package/server/services/providers-registry.js +30 -0
- package/server/services/providers.js +1 -1
- package/admin/src/utils/axiosInstance.js +0 -38
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { useCallback, useReducer, useEffect, useRef } from 'react';
|
|
2
|
-
import { useNotification } from '@strapi/helper-plugin';
|
|
2
|
+
import { useNotification, useFetchClient } from '@strapi/helper-plugin';
|
|
3
3
|
import reducer, { initialState } from './reducer';
|
|
4
|
-
import axiosInstance from '../../utils/axiosInstance';
|
|
5
4
|
import pluginId from '../../pluginId';
|
|
6
5
|
|
|
7
6
|
const useFetchRole = (id) => {
|
|
8
7
|
const [state, dispatch] = useReducer(reducer, initialState);
|
|
9
8
|
const toggleNotification = useNotification();
|
|
10
9
|
const isMounted = useRef(null);
|
|
10
|
+
const { get } = useFetchClient();
|
|
11
11
|
|
|
12
12
|
useEffect(() => {
|
|
13
13
|
isMounted.current = true;
|
|
@@ -29,7 +29,7 @@ const useFetchRole = (id) => {
|
|
|
29
29
|
try {
|
|
30
30
|
const {
|
|
31
31
|
data: { role },
|
|
32
|
-
} = await
|
|
32
|
+
} = await get(`/${pluginId}/roles/${roleId}`);
|
|
33
33
|
|
|
34
34
|
// Prevent updating state on an unmounted component
|
|
35
35
|
if (isMounted.current) {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { useCallback, useEffect, useReducer } from 'react';
|
|
2
|
-
import { useNotification } from '@strapi/helper-plugin';
|
|
2
|
+
import { useNotification, useFetchClient } from '@strapi/helper-plugin';
|
|
3
3
|
import { get } from 'lodash';
|
|
4
4
|
import init from './init';
|
|
5
5
|
import pluginId from '../../pluginId';
|
|
6
6
|
import { cleanPermissions } from '../../utils';
|
|
7
|
-
import axiosInstance from '../../utils/axiosInstance';
|
|
8
7
|
import reducer, { initialState } from './reducer';
|
|
9
8
|
|
|
10
9
|
const usePlugins = (shouldFetchData = true) => {
|
|
@@ -12,6 +11,7 @@ const usePlugins = (shouldFetchData = true) => {
|
|
|
12
11
|
const [{ permissions, routes, isLoading }, dispatch] = useReducer(reducer, initialState, () =>
|
|
13
12
|
init(initialState, shouldFetchData)
|
|
14
13
|
);
|
|
14
|
+
const fetchClient = useFetchClient();
|
|
15
15
|
|
|
16
16
|
const fetchPlugins = useCallback(async () => {
|
|
17
17
|
try {
|
|
@@ -21,7 +21,7 @@ const usePlugins = (shouldFetchData = true) => {
|
|
|
21
21
|
|
|
22
22
|
const [{ permissions }, { routes }] = await Promise.all(
|
|
23
23
|
[`/${pluginId}/permissions`, `/${pluginId}/routes`].map(async (endpoint) => {
|
|
24
|
-
const res = await
|
|
24
|
+
const res = await fetchClient.get(endpoint);
|
|
25
25
|
|
|
26
26
|
return res.data;
|
|
27
27
|
})
|
|
@@ -46,6 +46,8 @@ const usePlugins = (shouldFetchData = true) => {
|
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
+
|
|
50
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
49
51
|
}, [toggleNotification]);
|
|
50
52
|
|
|
51
53
|
useEffect(() => {
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getFetchClient } from '@strapi/helper-plugin';
|
|
2
|
+
import { getRequestURL } from '../../../utils';
|
|
2
3
|
|
|
3
4
|
const fetchData = async () => {
|
|
4
|
-
const {
|
|
5
|
+
const { get } = getFetchClient();
|
|
6
|
+
const { data } = await get(getRequestURL('advanced'));
|
|
5
7
|
|
|
6
8
|
return data;
|
|
7
9
|
};
|
|
8
10
|
|
|
9
11
|
const putAdvancedSettings = (body) => {
|
|
10
|
-
|
|
12
|
+
const { put } = getFetchClient();
|
|
13
|
+
|
|
14
|
+
return put(getRequestURL('advanced'), body);
|
|
11
15
|
};
|
|
12
16
|
|
|
13
17
|
export { fetchData, putAdvancedSettings };
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getFetchClient } from '@strapi/helper-plugin';
|
|
2
|
+
import { getRequestURL } from '../../../utils';
|
|
2
3
|
|
|
3
4
|
const fetchData = async () => {
|
|
4
|
-
const {
|
|
5
|
+
const { get } = getFetchClient();
|
|
6
|
+
const { data } = await get(getRequestURL('email-templates'));
|
|
5
7
|
|
|
6
8
|
return data;
|
|
7
9
|
};
|
|
8
10
|
|
|
9
11
|
const putEmailTemplate = (body) => {
|
|
10
|
-
|
|
12
|
+
const { put } = getFetchClient();
|
|
13
|
+
|
|
14
|
+
return put(getRequestURL('email-templates'), body);
|
|
11
15
|
};
|
|
12
16
|
|
|
13
17
|
export { fetchData, putEmailTemplate };
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getFetchClient } from '@strapi/helper-plugin';
|
|
2
|
+
import { getRequestURL } from '../../../utils';
|
|
2
3
|
|
|
3
4
|
// eslint-disable-next-line import/prefer-default-export
|
|
4
5
|
export const fetchData = async (toggleNotification) => {
|
|
5
6
|
try {
|
|
6
|
-
const {
|
|
7
|
+
const { get } = getFetchClient();
|
|
8
|
+
const { data } = await get(getRequestURL('providers'));
|
|
7
9
|
|
|
8
10
|
return data;
|
|
9
11
|
} catch (err) {
|
|
@@ -17,5 +19,7 @@ export const fetchData = async (toggleNotification) => {
|
|
|
17
19
|
};
|
|
18
20
|
|
|
19
21
|
export const putProvider = (body) => {
|
|
20
|
-
|
|
22
|
+
const { put } = getFetchClient();
|
|
23
|
+
|
|
24
|
+
return put(getRequestURL('providers'), body);
|
|
21
25
|
};
|
|
@@ -15,6 +15,7 @@ import { useIntl } from 'react-intl';
|
|
|
15
15
|
import {
|
|
16
16
|
useOverlayBlocker,
|
|
17
17
|
SettingsPageTitle,
|
|
18
|
+
useFetchClient,
|
|
18
19
|
useTracking,
|
|
19
20
|
Form,
|
|
20
21
|
useNotification,
|
|
@@ -24,7 +25,6 @@ import getTrad from '../../../utils/getTrad';
|
|
|
24
25
|
import pluginId from '../../../pluginId';
|
|
25
26
|
import { usePlugins } from '../../../hooks';
|
|
26
27
|
import schema from './utils/schema';
|
|
27
|
-
import axiosInstance from '../../../utils/axiosInstance';
|
|
28
28
|
|
|
29
29
|
const EditPage = () => {
|
|
30
30
|
const { formatMessage } = useIntl();
|
|
@@ -35,6 +35,7 @@ const EditPage = () => {
|
|
|
35
35
|
const { isLoading: isLoadingPlugins, permissions, routes } = usePlugins();
|
|
36
36
|
const { trackUsage } = useTracking();
|
|
37
37
|
const permissionsRef = useRef();
|
|
38
|
+
const { post } = useFetchClient();
|
|
38
39
|
|
|
39
40
|
const handleCreateRoleSubmit = async (data) => {
|
|
40
41
|
// Set loading state
|
|
@@ -43,7 +44,7 @@ const EditPage = () => {
|
|
|
43
44
|
try {
|
|
44
45
|
const permissions = permissionsRef.current.getPermissions();
|
|
45
46
|
// Update role in Strapi
|
|
46
|
-
await
|
|
47
|
+
await post(`/${pluginId}/roles`, { ...data, ...permissions, users: [] });
|
|
47
48
|
// Notify success
|
|
48
49
|
trackUsage('didCreateRole');
|
|
49
50
|
toggleNotification({
|
|
@@ -3,6 +3,7 @@ import { Formik } from 'formik';
|
|
|
3
3
|
import { useIntl } from 'react-intl';
|
|
4
4
|
import { useRouteMatch } from 'react-router-dom';
|
|
5
5
|
import {
|
|
6
|
+
useFetchClient,
|
|
6
7
|
useOverlayBlocker,
|
|
7
8
|
SettingsPageTitle,
|
|
8
9
|
LoadingIndicatorPage,
|
|
@@ -26,7 +27,6 @@ import getTrad from '../../../utils/getTrad';
|
|
|
26
27
|
import pluginId from '../../../pluginId';
|
|
27
28
|
import { usePlugins, useFetchRole } from '../../../hooks';
|
|
28
29
|
import schema from './utils/schema';
|
|
29
|
-
import axiosInstance from '../../../utils/axiosInstance';
|
|
30
30
|
|
|
31
31
|
const EditPage = () => {
|
|
32
32
|
const { formatMessage } = useIntl();
|
|
@@ -39,6 +39,7 @@ const EditPage = () => {
|
|
|
39
39
|
const { isLoading: isLoadingPlugins, routes } = usePlugins();
|
|
40
40
|
const { role, onSubmitSucceeded, isLoading: isLoadingRole } = useFetchRole(id);
|
|
41
41
|
const permissionsRef = useRef();
|
|
42
|
+
const { put } = useFetchClient();
|
|
42
43
|
|
|
43
44
|
const handleEditRoleSubmit = async (data) => {
|
|
44
45
|
// Set loading state
|
|
@@ -47,7 +48,7 @@ const EditPage = () => {
|
|
|
47
48
|
try {
|
|
48
49
|
const permissions = permissionsRef.current.getPermissions();
|
|
49
50
|
// Update role in Strapi
|
|
50
|
-
await
|
|
51
|
+
await put(`/${pluginId}/roles/${id}`, { ...data, ...permissions, users: [] });
|
|
51
52
|
// Notify success
|
|
52
53
|
onSubmitSucceeded({ name: data.name, description: data.description });
|
|
53
54
|
toggleNotification({
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getFetchClient } from '@strapi/helper-plugin';
|
|
2
|
+
import { getRequestURL } from '../../../../utils';
|
|
2
3
|
|
|
3
4
|
export const fetchData = async (toggleNotification, notifyStatus) => {
|
|
4
5
|
try {
|
|
5
|
-
const {
|
|
6
|
+
const { get } = getFetchClient();
|
|
7
|
+
const { data } = await get(getRequestURL('roles'));
|
|
6
8
|
notifyStatus('The roles have loaded successfully');
|
|
7
9
|
|
|
8
10
|
return data;
|
|
@@ -18,7 +20,8 @@ export const fetchData = async (toggleNotification, notifyStatus) => {
|
|
|
18
20
|
|
|
19
21
|
export const deleteData = async (id, toggleNotification) => {
|
|
20
22
|
try {
|
|
21
|
-
|
|
23
|
+
const { del } = getFetchClient();
|
|
24
|
+
await del(`${getRequestURL('roles')}/${id}`);
|
|
22
25
|
} catch (error) {
|
|
23
26
|
toggleNotification({
|
|
24
27
|
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.
|
|
3
|
+
"version": "4.7.0-beta.0",
|
|
4
4
|
"description": "Protect your API with a full-authentication process based on JWT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"test:front:watch:ce": "cross-env IS_EE=false jest --config ./jest.config.front.js --watchAll"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@strapi/helper-plugin": "4.
|
|
31
|
-
"@strapi/utils": "4.
|
|
30
|
+
"@strapi/helper-plugin": "4.7.0-beta.0",
|
|
31
|
+
"@strapi/utils": "4.7.0-beta.0",
|
|
32
32
|
"bcryptjs": "2.4.3",
|
|
33
33
|
"grant-koa": "5.4.8",
|
|
34
34
|
"jsonwebtoken": "9.0.0",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"purest": "4.0.2",
|
|
40
40
|
"react": "^17.0.2",
|
|
41
41
|
"react-dom": "^17.0.2",
|
|
42
|
-
"react-intl": "
|
|
43
|
-
"react-redux": "
|
|
42
|
+
"react-intl": "6.2.7",
|
|
43
|
+
"react-redux": "8.0.5",
|
|
44
44
|
"react-router": "^5.2.0",
|
|
45
45
|
"react-router-dom": "5.3.4",
|
|
46
46
|
"request": "^2.83.0",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@testing-library/react": "12.1.4",
|
|
52
52
|
"@testing-library/react-hooks": "8.0.1",
|
|
53
53
|
"@testing-library/user-event": "14.4.3",
|
|
54
|
-
"msw": "0.
|
|
54
|
+
"msw": "1.0.0",
|
|
55
55
|
"react-test-renderer": "^17.0.2"
|
|
56
56
|
},
|
|
57
57
|
"engines": {
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"required": true,
|
|
66
66
|
"kind": "plugin"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "880ba7af867ad43c4cc45b47467b76a9b5606b6e"
|
|
69
69
|
}
|
|
@@ -120,4 +120,12 @@ module.exports = (baseURL) => ({
|
|
|
120
120
|
scope: ['openid email'], // scopes should be space delimited
|
|
121
121
|
subdomain: 'my.subdomain.com/cas',
|
|
122
122
|
},
|
|
123
|
+
patreon: {
|
|
124
|
+
enabled: false,
|
|
125
|
+
icon: '',
|
|
126
|
+
key: '',
|
|
127
|
+
secret: '',
|
|
128
|
+
callback: `${baseURL}/patreon/callback`,
|
|
129
|
+
scope: ['identity', 'identity[email]'],
|
|
130
|
+
},
|
|
123
131
|
});
|
|
@@ -48,6 +48,7 @@ const getCognitoPayload = async ({ idToken, jwksUrl, purest }) => {
|
|
|
48
48
|
const getInitialProviders = ({ purest }) => ({
|
|
49
49
|
async discord({ accessToken }) {
|
|
50
50
|
const discord = purest({ provider: 'discord' });
|
|
51
|
+
|
|
51
52
|
return discord
|
|
52
53
|
.get('users/@me')
|
|
53
54
|
.auth(accessToken)
|
|
@@ -301,6 +302,35 @@ const getInitialProviders = ({ purest }) => ({
|
|
|
301
302
|
};
|
|
302
303
|
});
|
|
303
304
|
},
|
|
305
|
+
async patreon({ accessToken }) {
|
|
306
|
+
const patreon = purest({
|
|
307
|
+
provider: 'patreon',
|
|
308
|
+
config: {
|
|
309
|
+
patreon: {
|
|
310
|
+
default: {
|
|
311
|
+
origin: 'https://www.patreon.com',
|
|
312
|
+
path: 'api/oauth2/{path}',
|
|
313
|
+
headers: {
|
|
314
|
+
authorization: 'Bearer {auth}',
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
return patreon
|
|
322
|
+
.get('v2/identity')
|
|
323
|
+
.auth(accessToken)
|
|
324
|
+
.qs(new URLSearchParams({ 'fields[user]': 'full_name,email' }).toString())
|
|
325
|
+
.request()
|
|
326
|
+
.then(({ body }) => {
|
|
327
|
+
const patreonData = body.data.attributes;
|
|
328
|
+
return {
|
|
329
|
+
username: patreonData.full_name,
|
|
330
|
+
email: patreonData.email,
|
|
331
|
+
};
|
|
332
|
+
});
|
|
333
|
+
},
|
|
304
334
|
});
|
|
305
335
|
|
|
306
336
|
module.exports = () => {
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { auth, wrapAxiosInstance } from '@strapi/helper-plugin';
|
|
3
|
-
|
|
4
|
-
const instance = axios.create({
|
|
5
|
-
baseURL: process.env.STRAPI_ADMIN_BACKEND_URL,
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
instance.interceptors.request.use(
|
|
9
|
-
async (config) => {
|
|
10
|
-
config.headers = {
|
|
11
|
-
Authorization: `Bearer ${auth.getToken()}`,
|
|
12
|
-
Accept: 'application/json',
|
|
13
|
-
'Content-Type': 'application/json',
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
return config;
|
|
17
|
-
},
|
|
18
|
-
(error) => {
|
|
19
|
-
Promise.reject(error);
|
|
20
|
-
}
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
instance.interceptors.response.use(
|
|
24
|
-
(response) => response,
|
|
25
|
-
(error) => {
|
|
26
|
-
// whatever you want to do with the error
|
|
27
|
-
if (error.response?.status === 401) {
|
|
28
|
-
auth.clearAppStorage();
|
|
29
|
-
window.location.reload();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
throw error;
|
|
33
|
-
}
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
const wrapper = wrapAxiosInstance(instance);
|
|
37
|
-
|
|
38
|
-
export default wrapper;
|