@strapi/plugin-users-permissions 0.0.0-next.e41415e8ff5f565ff959667d5c5ba4f20bee013c → 0.0.0-next.e8d8fc824d0f6a695b2a9ebaa4680ed21c3645ca

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 (231) hide show
  1. package/.eslintignore +1 -2
  2. package/.eslintrc +17 -0
  3. package/LICENSE +18 -3
  4. package/admin/src/components/BoundRoute/{index.js → index.jsx} +6 -4
  5. package/admin/src/components/FormModal/Input/{index.js → index.jsx} +34 -32
  6. package/admin/src/components/FormModal/index.jsx +115 -0
  7. package/admin/src/components/Permissions/PermissionRow/{CheckboxWrapper.js → CheckboxWrapper.jsx} +4 -3
  8. package/admin/src/components/Permissions/PermissionRow/{SubCategory.js → SubCategory.jsx} +27 -15
  9. package/admin/src/components/Permissions/PermissionRow/{index.js → index.jsx} +4 -2
  10. package/admin/src/components/Permissions/index.jsx +47 -0
  11. package/admin/src/components/Permissions/reducer.js +1 -1
  12. package/admin/src/components/Policies/{index.js → index.jsx} +9 -6
  13. package/admin/src/components/UsersPermissions/{index.js → index.jsx} +22 -11
  14. package/admin/src/components/UsersPermissions/reducer.js +1 -1
  15. package/admin/src/{permissions.js → constants.js} +1 -3
  16. package/admin/src/contexts/UsersPermissionsContext/{index.js → index.jsx} +1 -0
  17. package/admin/src/index.js +25 -51
  18. package/admin/src/pages/AdvancedSettings/index.jsx +214 -0
  19. package/admin/src/pages/AdvancedSettings/utils/layout.js +20 -35
  20. package/admin/src/pages/AdvancedSettings/utils/schema.js +5 -2
  21. package/admin/src/pages/EmailTemplates/components/EmailForm.jsx +156 -0
  22. package/admin/src/pages/EmailTemplates/components/{EmailTable.js → EmailTable.jsx} +27 -22
  23. package/admin/src/pages/EmailTemplates/index.jsx +148 -0
  24. package/admin/src/pages/EmailTemplates/utils/schema.js +18 -6
  25. package/admin/src/pages/Providers/index.jsx +262 -0
  26. package/admin/src/pages/Providers/utils/forms.js +23 -11
  27. package/admin/src/pages/Roles/constants.js +7 -0
  28. package/admin/src/pages/Roles/hooks/usePlugins.js +78 -0
  29. package/admin/src/pages/Roles/index.jsx +24 -0
  30. package/admin/src/pages/Roles/pages/CreatePage.jsx +194 -0
  31. package/admin/src/pages/Roles/pages/EditPage.jsx +215 -0
  32. package/admin/src/pages/Roles/pages/ListPage/components/TableBody.jsx +119 -0
  33. package/admin/src/pages/Roles/{ListPage/index.js → pages/ListPage/index.jsx} +108 -83
  34. package/admin/src/translations/en.json +1 -1
  35. package/admin/src/translations/zh-Hans.json +80 -80
  36. package/admin/src/utils/index.js +1 -2
  37. package/admin/src/utils/prefixPluginTranslations.js +13 -0
  38. package/dist/_chunks/ar-BguGUqwK.js +44 -0
  39. package/dist/_chunks/ar-BguGUqwK.js.map +1 -0
  40. package/dist/_chunks/ar-CK8BRRXB.mjs +44 -0
  41. package/dist/_chunks/ar-CK8BRRXB.mjs.map +1 -0
  42. package/dist/_chunks/cs-BVigMk0l.mjs +50 -0
  43. package/dist/_chunks/cs-BVigMk0l.mjs.map +1 -0
  44. package/dist/_chunks/cs-BW8-K_GY.js +50 -0
  45. package/dist/_chunks/cs-BW8-K_GY.js.map +1 -0
  46. package/dist/_chunks/de-BKUdRFI4.mjs +62 -0
  47. package/dist/_chunks/de-BKUdRFI4.mjs.map +1 -0
  48. package/dist/_chunks/de-owXpVluI.js +62 -0
  49. package/dist/_chunks/de-owXpVluI.js.map +1 -0
  50. package/dist/_chunks/dk-BQiTK50l.mjs +86 -0
  51. package/dist/_chunks/dk-BQiTK50l.mjs.map +1 -0
  52. package/dist/_chunks/dk-LXAnbuBk.js +86 -0
  53. package/dist/_chunks/dk-LXAnbuBk.js.map +1 -0
  54. package/dist/_chunks/en-DOHtPf-2.mjs +86 -0
  55. package/dist/_chunks/en-DOHtPf-2.mjs.map +1 -0
  56. package/dist/_chunks/en-MHo5mcsU.js +86 -0
  57. package/dist/_chunks/en-MHo5mcsU.js.map +1 -0
  58. package/dist/_chunks/es-BwLCLXAQ.js +86 -0
  59. package/dist/_chunks/es-BwLCLXAQ.js.map +1 -0
  60. package/dist/_chunks/es-DNgOVMjD.mjs +86 -0
  61. package/dist/_chunks/es-DNgOVMjD.mjs.map +1 -0
  62. package/dist/_chunks/fr-DkgRugiU.mjs +50 -0
  63. package/dist/_chunks/fr-DkgRugiU.mjs.map +1 -0
  64. package/dist/_chunks/fr-DkhpSjjm.js +50 -0
  65. package/dist/_chunks/fr-DkhpSjjm.js.map +1 -0
  66. package/dist/_chunks/id-BTemOeTZ.js +62 -0
  67. package/dist/_chunks/id-BTemOeTZ.js.map +1 -0
  68. package/dist/_chunks/id-BdEsvnaF.mjs +62 -0
  69. package/dist/_chunks/id-BdEsvnaF.mjs.map +1 -0
  70. package/dist/_chunks/index-BP1KkpZq.js +280 -0
  71. package/dist/_chunks/index-BP1KkpZq.js.map +1 -0
  72. package/dist/_chunks/index-BnvtBuUS.js +365 -0
  73. package/dist/_chunks/index-BnvtBuUS.js.map +1 -0
  74. package/dist/_chunks/index-BphRo4l2.js +252 -0
  75. package/dist/_chunks/index-BphRo4l2.js.map +1 -0
  76. package/dist/_chunks/index-C_5QiATG.mjs +344 -0
  77. package/dist/_chunks/index-C_5QiATG.mjs.map +1 -0
  78. package/dist/_chunks/index-Cn5HftCc-CvJvlZwK.js +11113 -0
  79. package/dist/_chunks/index-Cn5HftCc-CvJvlZwK.js.map +1 -0
  80. package/dist/_chunks/index-Cn5HftCc-Dku5eOkP.mjs +11090 -0
  81. package/dist/_chunks/index-Cn5HftCc-Dku5eOkP.mjs.map +1 -0
  82. package/dist/_chunks/index-Cxhs260c.mjs +1142 -0
  83. package/dist/_chunks/index-Cxhs260c.mjs.map +1 -0
  84. package/dist/_chunks/index-D4Ge_-Bp.mjs +262 -0
  85. package/dist/_chunks/index-D4Ge_-Bp.mjs.map +1 -0
  86. package/dist/_chunks/index-D5yExFYc.mjs +253 -0
  87. package/dist/_chunks/index-D5yExFYc.mjs.map +1 -0
  88. package/dist/_chunks/index-D_J3MMcj.mjs +617 -0
  89. package/dist/_chunks/index-D_J3MMcj.mjs.map +1 -0
  90. package/dist/_chunks/index-DoogNdMf.js +639 -0
  91. package/dist/_chunks/index-DoogNdMf.js.map +1 -0
  92. package/dist/_chunks/index-iJPHXbGD.js +1171 -0
  93. package/dist/_chunks/index-iJPHXbGD.js.map +1 -0
  94. package/dist/_chunks/it-B-rv0E24.mjs +62 -0
  95. package/dist/_chunks/it-B-rv0E24.mjs.map +1 -0
  96. package/dist/_chunks/it-D1rH6V6_.js +62 -0
  97. package/dist/_chunks/it-D1rH6V6_.js.map +1 -0
  98. package/dist/_chunks/ja-C8K-VBPD.mjs +48 -0
  99. package/dist/_chunks/ja-C8K-VBPD.mjs.map +1 -0
  100. package/dist/_chunks/ja-DqShgTMf.js +48 -0
  101. package/dist/_chunks/ja-DqShgTMf.js.map +1 -0
  102. package/dist/_chunks/ko-B9DGEPWH.js +86 -0
  103. package/dist/_chunks/ko-B9DGEPWH.js.map +1 -0
  104. package/dist/_chunks/ko-Busb0wIY.mjs +86 -0
  105. package/dist/_chunks/ko-Busb0wIY.mjs.map +1 -0
  106. package/dist/_chunks/ms-ByvsQjRt.mjs +49 -0
  107. package/dist/_chunks/ms-ByvsQjRt.mjs.map +1 -0
  108. package/dist/_chunks/ms-CPBU3LWf.js +49 -0
  109. package/dist/_chunks/ms-CPBU3LWf.js.map +1 -0
  110. package/dist/_chunks/nl-5qO8Rpcy.mjs +48 -0
  111. package/dist/_chunks/nl-5qO8Rpcy.mjs.map +1 -0
  112. package/dist/_chunks/nl-CwNB6YoO.js +48 -0
  113. package/dist/_chunks/nl-CwNB6YoO.js.map +1 -0
  114. package/dist/_chunks/pl-BdIzifBE.mjs +86 -0
  115. package/dist/_chunks/pl-BdIzifBE.mjs.map +1 -0
  116. package/dist/_chunks/pl-Do9UD69f.js +86 -0
  117. package/dist/_chunks/pl-Do9UD69f.js.map +1 -0
  118. package/dist/_chunks/pt-BIO24ioG.mjs +48 -0
  119. package/dist/_chunks/pt-BIO24ioG.mjs.map +1 -0
  120. package/dist/_chunks/pt-BR-D7dZhxuP.js +44 -0
  121. package/dist/_chunks/pt-BR-D7dZhxuP.js.map +1 -0
  122. package/dist/_chunks/pt-BR-f0p23AQZ.mjs +44 -0
  123. package/dist/_chunks/pt-BR-f0p23AQZ.mjs.map +1 -0
  124. package/dist/_chunks/pt-fdvyOnUp.js +48 -0
  125. package/dist/_chunks/pt-fdvyOnUp.js.map +1 -0
  126. package/dist/_chunks/ru-C94rjPGA.js +86 -0
  127. package/dist/_chunks/ru-C94rjPGA.js.map +1 -0
  128. package/dist/_chunks/ru-VWy-IB7K.mjs +86 -0
  129. package/dist/_chunks/ru-VWy-IB7K.mjs.map +1 -0
  130. package/dist/_chunks/sk-BABEhykl.js +50 -0
  131. package/dist/_chunks/sk-BABEhykl.js.map +1 -0
  132. package/dist/_chunks/sk-B_LIcepm.mjs +50 -0
  133. package/dist/_chunks/sk-B_LIcepm.mjs.map +1 -0
  134. package/dist/_chunks/sv-ABLKOokl.mjs +86 -0
  135. package/dist/_chunks/sv-ABLKOokl.mjs.map +1 -0
  136. package/dist/_chunks/sv-Be43LhA9.js +86 -0
  137. package/dist/_chunks/sv-Be43LhA9.js.map +1 -0
  138. package/dist/_chunks/th-DKyP7ueR.mjs +60 -0
  139. package/dist/_chunks/th-DKyP7ueR.mjs.map +1 -0
  140. package/dist/_chunks/th-DgVhVLhL.js +60 -0
  141. package/dist/_chunks/th-DgVhVLhL.js.map +1 -0
  142. package/dist/_chunks/tr-B_idhkEs.js +85 -0
  143. package/dist/_chunks/tr-B_idhkEs.js.map +1 -0
  144. package/dist/_chunks/tr-qa1Q5UjC.mjs +85 -0
  145. package/dist/_chunks/tr-qa1Q5UjC.mjs.map +1 -0
  146. package/dist/_chunks/uk-BmRqbeQc.mjs +49 -0
  147. package/dist/_chunks/uk-BmRqbeQc.mjs.map +1 -0
  148. package/dist/_chunks/uk-LHOivnhP.js +49 -0
  149. package/dist/_chunks/uk-LHOivnhP.js.map +1 -0
  150. package/dist/_chunks/vi-CdVRdKDw.js +50 -0
  151. package/dist/_chunks/vi-CdVRdKDw.js.map +1 -0
  152. package/dist/_chunks/vi-HW-EdMea.mjs +50 -0
  153. package/dist/_chunks/vi-HW-EdMea.mjs.map +1 -0
  154. package/dist/_chunks/zh-5hKkVPA4.mjs +86 -0
  155. package/dist/_chunks/zh-5hKkVPA4.mjs.map +1 -0
  156. package/dist/_chunks/zh-Cuq8gMnF.js +86 -0
  157. package/dist/_chunks/zh-Cuq8gMnF.js.map +1 -0
  158. package/dist/_chunks/zh-Hans-BHilK-yc.mjs +86 -0
  159. package/dist/_chunks/zh-Hans-BHilK-yc.mjs.map +1 -0
  160. package/dist/_chunks/zh-Hans-GQDMKtY4.js +86 -0
  161. package/dist/_chunks/zh-Hans-GQDMKtY4.js.map +1 -0
  162. package/dist/admin/index.js +4 -0
  163. package/dist/admin/index.js.map +1 -0
  164. package/dist/admin/index.mjs +5 -0
  165. package/dist/admin/index.mjs.map +1 -0
  166. package/documentation/content-api.yaml +1 -1
  167. package/jest.config.front.js +1 -0
  168. package/package.json +47 -29
  169. package/packup.config.ts +22 -0
  170. package/server/bootstrap/index.js +18 -15
  171. package/server/bootstrap/users-permissions-actions.js +6 -0
  172. package/server/config.js +29 -0
  173. package/server/content-types/user/index.js +0 -1
  174. package/server/controllers/auth.js +74 -38
  175. package/server/controllers/content-manager-user.js +28 -30
  176. package/server/controllers/role.js +17 -4
  177. package/server/controllers/user.js +18 -8
  178. package/server/controllers/validation/auth.js +81 -25
  179. package/server/graphql/types/index.js +1 -0
  180. package/server/graphql/types/me.js +1 -0
  181. package/server/graphql/types/user-input.js +20 -0
  182. package/server/middlewares/rateLimit.js +41 -21
  183. package/server/register.js +1 -1
  184. package/server/services/jwt.js +3 -3
  185. package/server/services/permission.js +3 -7
  186. package/server/services/providers-registry.js +469 -261
  187. package/server/services/providers.js +10 -5
  188. package/server/services/role.js +15 -13
  189. package/server/services/user.js +56 -19
  190. package/server/services/users-permissions.js +15 -13
  191. package/server/strategies/users-permissions.js +1 -8
  192. package/server/utils/index.d.ts +2 -1
  193. package/server/utils/sanitize/sanitizers.js +7 -3
  194. package/server/utils/sanitize/visitors/remove-user-relation-from-role-entities.js +2 -2
  195. package/.eslintrc.js +0 -14
  196. package/admin/src/components/FormModal/index.js +0 -123
  197. package/admin/src/components/Permissions/index.js +0 -54
  198. package/admin/src/hooks/index.js +0 -5
  199. package/admin/src/hooks/useFetchRole/index.js +0 -64
  200. package/admin/src/hooks/useFetchRole/reducer.js +0 -31
  201. package/admin/src/hooks/useForm/index.js +0 -67
  202. package/admin/src/hooks/useForm/reducer.js +0 -40
  203. package/admin/src/hooks/usePlugins/index.js +0 -67
  204. package/admin/src/hooks/usePlugins/init.js +0 -5
  205. package/admin/src/hooks/usePlugins/reducer.js +0 -34
  206. package/admin/src/hooks/useRolesList/index.js +0 -62
  207. package/admin/src/hooks/useRolesList/init.js +0 -5
  208. package/admin/src/hooks/useRolesList/reducer.js +0 -31
  209. package/admin/src/pages/AdvancedSettings/index.js +0 -243
  210. package/admin/src/pages/AdvancedSettings/utils/api.js +0 -17
  211. package/admin/src/pages/EmailTemplates/components/EmailForm.js +0 -175
  212. package/admin/src/pages/EmailTemplates/index.js +0 -160
  213. package/admin/src/pages/EmailTemplates/utils/api.js +0 -17
  214. package/admin/src/pages/Providers/index.js +0 -272
  215. package/admin/src/pages/Providers/reducer.js +0 -54
  216. package/admin/src/pages/Providers/utils/api.js +0 -25
  217. package/admin/src/pages/Providers/utils/createProvidersArray.js +0 -21
  218. package/admin/src/pages/Roles/CreatePage/index.js +0 -182
  219. package/admin/src/pages/Roles/CreatePage/utils/schema.js +0 -9
  220. package/admin/src/pages/Roles/EditPage/index.js +0 -194
  221. package/admin/src/pages/Roles/EditPage/utils/schema.js +0 -9
  222. package/admin/src/pages/Roles/ListPage/components/TableBody.js +0 -92
  223. package/admin/src/pages/Roles/ListPage/utils/api.js +0 -31
  224. package/admin/src/pages/Roles/ProtectedCreatePage/index.js +0 -12
  225. package/admin/src/pages/Roles/ProtectedEditPage/index.js +0 -12
  226. package/admin/src/pages/Roles/ProtectedListPage/index.js +0 -15
  227. package/admin/src/pages/Roles/index.js +0 -27
  228. package/admin/src/utils/getRequestURL.js +0 -5
  229. package/server/bootstrap/grant-config.js +0 -131
  230. package/strapi-admin.js +0 -3
  231. package/strapi-server.js +0 -3
@@ -1,64 +0,0 @@
1
- import { useCallback, useReducer, useEffect, useRef } from 'react';
2
- import { useNotification, useFetchClient } from '@strapi/helper-plugin';
3
- import reducer, { initialState } from './reducer';
4
- import pluginId from '../../pluginId';
5
-
6
- const useFetchRole = (id) => {
7
- const [state, dispatch] = useReducer(reducer, initialState);
8
- const toggleNotification = useNotification();
9
- const isMounted = useRef(null);
10
- const { get } = useFetchClient();
11
-
12
- useEffect(() => {
13
- isMounted.current = true;
14
-
15
- if (id) {
16
- fetchRole(id);
17
- } else {
18
- dispatch({
19
- type: 'GET_DATA_SUCCEEDED',
20
- role: {},
21
- });
22
- }
23
-
24
- return () => (isMounted.current = false);
25
- // eslint-disable-next-line react-hooks/exhaustive-deps
26
- }, [id]);
27
-
28
- const fetchRole = async (roleId) => {
29
- try {
30
- const {
31
- data: { role },
32
- } = await get(`/${pluginId}/roles/${roleId}`);
33
-
34
- // Prevent updating state on an unmounted component
35
- if (isMounted.current) {
36
- dispatch({
37
- type: 'GET_DATA_SUCCEEDED',
38
- role,
39
- });
40
- }
41
- } catch (err) {
42
- console.error(err);
43
-
44
- dispatch({
45
- type: 'GET_DATA_ERROR',
46
- });
47
- toggleNotification({
48
- type: 'warning',
49
- message: { id: 'notification.error' },
50
- });
51
- }
52
- };
53
-
54
- const handleSubmitSucceeded = useCallback((data) => {
55
- dispatch({
56
- type: 'ON_SUBMIT_SUCCEEDED',
57
- ...data,
58
- });
59
- }, []);
60
-
61
- return { ...state, onSubmitSucceeded: handleSubmitSucceeded };
62
- };
63
-
64
- export default useFetchRole;
@@ -1,31 +0,0 @@
1
- /* eslint-disable consistent-return */
2
- import produce from 'immer';
3
-
4
- export const initialState = {
5
- role: {},
6
- isLoading: true,
7
- };
8
-
9
- const reducer = (state, action) =>
10
- produce(state, (draftState) => {
11
- switch (action.type) {
12
- case 'GET_DATA_SUCCEEDED': {
13
- draftState.role = action.role;
14
- draftState.isLoading = false;
15
- break;
16
- }
17
- case 'GET_DATA_ERROR': {
18
- draftState.isLoading = false;
19
- break;
20
- }
21
- case 'ON_SUBMIT_SUCCEEDED': {
22
- draftState.role.name = action.name;
23
- draftState.role.description = action.description;
24
- break;
25
- }
26
- default:
27
- return draftState;
28
- }
29
- });
30
-
31
- export default reducer;
@@ -1,67 +0,0 @@
1
- import { useCallback, useEffect, useReducer, useRef } from 'react';
2
- import { useRBAC, useFetchClient, useNotification } from '@strapi/helper-plugin';
3
- import { getRequestURL } from '../../utils';
4
- import reducer, { initialState } from './reducer';
5
-
6
- const useUserForm = (endPoint, permissions) => {
7
- const { isLoading: isLoadingForPermissions, allowedActions } = useRBAC(permissions);
8
- const [{ isLoading, modifiedData }, dispatch] = useReducer(reducer, initialState);
9
- const toggleNotification = useNotification();
10
- const isMounted = useRef(true);
11
-
12
- const { get } = useFetchClient();
13
-
14
- useEffect(() => {
15
- const getData = async () => {
16
- try {
17
- dispatch({
18
- type: 'GET_DATA',
19
- });
20
-
21
- const { data } = await get(getRequestURL(endPoint));
22
-
23
- dispatch({
24
- type: 'GET_DATA_SUCCEEDED',
25
- data,
26
- });
27
- } catch (err) {
28
- // The user aborted the request
29
- if (isMounted.current) {
30
- dispatch({
31
- type: 'GET_DATA_ERROR',
32
- });
33
- console.error(err);
34
- toggleNotification({
35
- type: 'warning',
36
- message: { id: 'notification.error' },
37
- });
38
- }
39
- }
40
- };
41
-
42
- if (!isLoadingForPermissions) {
43
- getData();
44
- }
45
-
46
- return () => {
47
- isMounted.current = false;
48
- };
49
- }, [isLoadingForPermissions, endPoint, get, toggleNotification]);
50
-
51
- const dispatchSubmitSucceeded = useCallback((data) => {
52
- dispatch({
53
- type: 'ON_SUBMIT_SUCCEEDED',
54
- data,
55
- });
56
- }, []);
57
-
58
- return {
59
- allowedActions,
60
- dispatchSubmitSucceeded,
61
- isLoading,
62
- isLoadingForPermissions,
63
- modifiedData,
64
- };
65
- };
66
-
67
- export default useUserForm;
@@ -1,40 +0,0 @@
1
- import produce from 'immer';
2
-
3
- const initialState = {
4
- isLoading: true,
5
- modifiedData: {},
6
- };
7
-
8
- const reducer = (state, action) =>
9
- // eslint-disable-next-line consistent-return
10
- produce(state, (draftState) => {
11
- switch (action.type) {
12
- case 'GET_DATA': {
13
- draftState.isLoading = true;
14
- draftState.modifiedData = {};
15
-
16
- break;
17
- }
18
- case 'GET_DATA_SUCCEEDED': {
19
- draftState.isLoading = false;
20
- draftState.modifiedData = action.data;
21
-
22
- break;
23
- }
24
- case 'GET_DATA_ERROR': {
25
- draftState.isLoading = true;
26
- break;
27
- }
28
- case 'ON_SUBMIT_SUCCEEDED': {
29
- draftState.modifiedData = action.data;
30
-
31
- break;
32
- }
33
- default: {
34
- return draftState;
35
- }
36
- }
37
- });
38
-
39
- export default reducer;
40
- export { initialState };
@@ -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,62 +0,0 @@
1
- import { useCallback, useEffect, useReducer, useRef } from 'react';
2
- import { useFetchClient, useNotification } from '@strapi/helper-plugin';
3
- import get from 'lodash/get';
4
- import init from './init';
5
- import pluginId from '../../pluginId';
6
- import reducer, { initialState } from './reducer';
7
-
8
- const useRolesList = (shouldFetchData = true) => {
9
- const [{ roles, isLoading }, dispatch] = useReducer(reducer, initialState, () =>
10
- init(initialState, shouldFetchData)
11
- );
12
- const toggleNotification = useNotification();
13
-
14
- const isMounted = useRef(true);
15
- const fetchClient = useFetchClient();
16
-
17
- const fetchRolesList = useCallback(async () => {
18
- try {
19
- dispatch({
20
- type: 'GET_DATA',
21
- });
22
-
23
- const {
24
- data: { roles },
25
- } = await fetchClient.get(`/${pluginId}/roles`);
26
-
27
- dispatch({
28
- type: 'GET_DATA_SUCCEEDED',
29
- data: roles,
30
- });
31
- } catch (err) {
32
- const message = get(err, ['response', 'payload', 'message'], 'An error occured');
33
-
34
- if (isMounted.current) {
35
- dispatch({
36
- type: 'GET_DATA_ERROR',
37
- });
38
-
39
- if (message !== 'Forbidden') {
40
- toggleNotification({
41
- type: 'warning',
42
- message,
43
- });
44
- }
45
- }
46
- }
47
- }, [fetchClient, toggleNotification]);
48
-
49
- useEffect(() => {
50
- if (shouldFetchData) {
51
- fetchRolesList();
52
- }
53
-
54
- return () => {
55
- isMounted.current = false;
56
- };
57
- }, [shouldFetchData, fetchRolesList]);
58
-
59
- return { roles, isLoading, getData: fetchRolesList };
60
- };
61
-
62
- export default useRolesList;
@@ -1,5 +0,0 @@
1
- const init = (initialState, shouldFetchData) => {
2
- return { ...initialState, isLoading: shouldFetchData };
3
- };
4
-
5
- export default init;
@@ -1,31 +0,0 @@
1
- /* eslint-disable consistent-return */
2
- import produce from 'immer';
3
-
4
- export const initialState = {
5
- roles: [],
6
- isLoading: true,
7
- };
8
-
9
- const reducer = (state, action) =>
10
- produce(state, (draftState) => {
11
- switch (action.type) {
12
- case 'GET_DATA': {
13
- draftState.isLoading = true;
14
- draftState.roles = [];
15
- break;
16
- }
17
- case 'GET_DATA_SUCCEEDED': {
18
- draftState.roles = action.data;
19
- draftState.isLoading = false;
20
- break;
21
- }
22
- case 'GET_DATA_ERROR': {
23
- draftState.isLoading = false;
24
- break;
25
- }
26
- default:
27
- return draftState;
28
- }
29
- });
30
-
31
- export default reducer;
@@ -1,243 +0,0 @@
1
- import React, { useMemo } from 'react';
2
- import { useQuery, useMutation, useQueryClient } from 'react-query';
3
- import { useIntl } from 'react-intl';
4
- import { Formik } from 'formik';
5
- import {
6
- CheckPagePermissions,
7
- Form,
8
- GenericInput,
9
- LoadingIndicatorPage,
10
- SettingsPageTitle,
11
- useFocusWhenNavigate,
12
- useNotification,
13
- useOverlayBlocker,
14
- useRBAC,
15
- } from '@strapi/helper-plugin';
16
- import {
17
- useNotifyAT,
18
- Main,
19
- HeaderLayout,
20
- ContentLayout,
21
- Button,
22
- Box,
23
- Flex,
24
- Select,
25
- Option,
26
- Typography,
27
- Grid,
28
- GridItem,
29
- } from '@strapi/design-system';
30
- import { Check } from '@strapi/icons';
31
- import pluginPermissions from '../../permissions';
32
- import { getTrad } from '../../utils';
33
- import layout from './utils/layout';
34
- import schema from './utils/schema';
35
- import { fetchData, putAdvancedSettings } from './utils/api';
36
-
37
- const ProtectedAdvancedSettingsPage = () => (
38
- <CheckPagePermissions permissions={pluginPermissions.readAdvancedSettings}>
39
- <AdvancedSettingsPage />
40
- </CheckPagePermissions>
41
- );
42
-
43
- const AdvancedSettingsPage = () => {
44
- const { formatMessage } = useIntl();
45
- const toggleNotification = useNotification();
46
- const { lockApp, unlockApp } = useOverlayBlocker();
47
- const { notifyStatus } = useNotifyAT();
48
- const queryClient = useQueryClient();
49
- useFocusWhenNavigate();
50
-
51
- const updatePermissions = useMemo(
52
- () => ({ update: pluginPermissions.updateAdvancedSettings }),
53
- []
54
- );
55
- const {
56
- isLoading: isLoadingForPermissions,
57
- allowedActions: { canUpdate },
58
- } = useRBAC(updatePermissions);
59
-
60
- const { status: isLoadingData, data } = useQuery('advanced', () => fetchData(), {
61
- onSuccess() {
62
- notifyStatus(
63
- formatMessage({
64
- id: getTrad('Form.advancedSettings.data.loaded'),
65
- defaultMessage: 'Advanced settings data has been loaded',
66
- })
67
- );
68
- },
69
- onError() {
70
- toggleNotification({
71
- type: 'warning',
72
- message: { id: getTrad('notification.error'), defaultMessage: 'An error occured' },
73
- });
74
- },
75
- });
76
-
77
- const isLoading = isLoadingForPermissions || isLoadingData !== 'success';
78
-
79
- const submitMutation = useMutation((body) => putAdvancedSettings(body), {
80
- async onSuccess() {
81
- await queryClient.invalidateQueries('advanced');
82
- toggleNotification({
83
- type: 'success',
84
- message: { id: getTrad('notification.success.saved'), defaultMessage: 'Saved' },
85
- });
86
-
87
- unlockApp();
88
- },
89
- onError() {
90
- toggleNotification({
91
- type: 'warning',
92
- message: { id: getTrad('notification.error'), defaultMessage: 'An error occured' },
93
- });
94
- unlockApp();
95
- },
96
- refetchActive: true,
97
- });
98
-
99
- const { isLoading: isSubmittingForm } = submitMutation;
100
-
101
- const handleSubmit = async (body) => {
102
- lockApp();
103
-
104
- const urlConfirmation = body.email_confirmation ? body.email_confirmation_redirection : '';
105
-
106
- await submitMutation.mutateAsync({ ...body, email_confirmation_redirection: urlConfirmation });
107
- };
108
-
109
- if (isLoading) {
110
- return (
111
- <Main aria-busy="true">
112
- <SettingsPageTitle
113
- name={formatMessage({
114
- id: getTrad('HeaderNav.link.advancedSettings'),
115
- defaultMessage: 'Advanced Settings',
116
- })}
117
- />
118
- <HeaderLayout
119
- title={formatMessage({
120
- id: getTrad('HeaderNav.link.advancedSettings'),
121
- defaultMessage: 'Advanced Settings',
122
- })}
123
- />
124
- <ContentLayout>
125
- <LoadingIndicatorPage />
126
- </ContentLayout>
127
- </Main>
128
- );
129
- }
130
-
131
- return (
132
- <Main aria-busy={isSubmittingForm}>
133
- <SettingsPageTitle
134
- name={formatMessage({
135
- id: getTrad('HeaderNav.link.advancedSettings'),
136
- defaultMessage: 'Advanced Settings',
137
- })}
138
- />
139
- <Formik
140
- onSubmit={handleSubmit}
141
- initialValues={data.settings}
142
- validateOnChange={false}
143
- validationSchema={schema}
144
- enableReinitialize
145
- >
146
- {({ errors, values, handleChange, isSubmitting }) => {
147
- return (
148
- <Form>
149
- <HeaderLayout
150
- title={formatMessage({
151
- id: getTrad('HeaderNav.link.advancedSettings'),
152
- defaultMessage: 'Advanced Settings',
153
- })}
154
- primaryAction={
155
- <Button
156
- loading={isSubmitting}
157
- type="submit"
158
- disabled={!canUpdate}
159
- startIcon={<Check />}
160
- size="S"
161
- >
162
- {formatMessage({ id: 'global.save', defaultMessage: 'Save' })}
163
- </Button>
164
- }
165
- />
166
- <ContentLayout>
167
- <Box
168
- background="neutral0"
169
- hasRadius
170
- shadow="filterShadow"
171
- paddingTop={6}
172
- paddingBottom={6}
173
- paddingLeft={7}
174
- paddingRight={7}
175
- >
176
- <Flex direction="column" alignItems="stretch" gap={4}>
177
- <Typography variant="delta" as="h2">
178
- {formatMessage({
179
- id: 'global.settings',
180
- defaultMessage: 'Settings',
181
- })}
182
- </Typography>
183
- <Grid gap={6}>
184
- <GridItem col={6} s={12}>
185
- <Select
186
- label={formatMessage({
187
- id: getTrad('EditForm.inputSelect.label.role'),
188
- defaultMessage: 'Default role for authenticated users',
189
- })}
190
- value={values.default_role}
191
- hint={formatMessage({
192
- id: getTrad('EditForm.inputSelect.description.role'),
193
- defaultMessage:
194
- 'It will attach the new authenticated user to the selected role.',
195
- })}
196
- onChange={(e) =>
197
- handleChange({ target: { name: 'default_role', value: e } })
198
- }
199
- >
200
- {data.roles.map((role) => {
201
- return (
202
- <Option key={role.type} value={role.type}>
203
- {role.name}
204
- </Option>
205
- );
206
- })}
207
- </Select>
208
- </GridItem>
209
- {layout.map((input) => {
210
- let value = values[input.name];
211
-
212
- if (!value) {
213
- value = input.type === 'bool' ? false : '';
214
- }
215
-
216
- return (
217
- <GridItem key={input.name} {...input.size}>
218
- <GenericInput
219
- {...input}
220
- value={value}
221
- error={errors[input.name]}
222
- disabled={
223
- input.name === 'email_confirmation_redirection' &&
224
- values.email_confirmation === false
225
- }
226
- onChange={handleChange}
227
- />
228
- </GridItem>
229
- );
230
- })}
231
- </Grid>
232
- </Flex>
233
- </Box>
234
- </ContentLayout>
235
- </Form>
236
- );
237
- }}
238
- </Formik>
239
- </Main>
240
- );
241
- };
242
-
243
- export default ProtectedAdvancedSettingsPage;
@@ -1,17 +0,0 @@
1
- import { getFetchClient } from '@strapi/helper-plugin';
2
- import { getRequestURL } from '../../../utils';
3
-
4
- const fetchData = async () => {
5
- const { get } = getFetchClient();
6
- const { data } = await get(getRequestURL('advanced'));
7
-
8
- return data;
9
- };
10
-
11
- const putAdvancedSettings = (body) => {
12
- const { put } = getFetchClient();
13
-
14
- return put(getRequestURL('advanced'), body);
15
- };
16
-
17
- export { fetchData, putAdvancedSettings };