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

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 (196) 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} +5 -3
  5. package/admin/src/components/FormModal/Input/{index.js → index.jsx} +3 -2
  6. package/admin/src/components/FormModal/{index.js → index.jsx} +13 -10
  7. package/admin/src/components/Permissions/PermissionRow/{SubCategory.js → SubCategory.jsx} +26 -5
  8. package/admin/src/components/Permissions/PermissionRow/{index.js → index.jsx} +4 -2
  9. package/admin/src/components/Permissions/{index.js → index.jsx} +6 -5
  10. package/admin/src/components/Policies/{index.js → index.jsx} +3 -2
  11. package/admin/src/components/UsersPermissions/{index.js → index.jsx} +8 -5
  12. package/admin/src/{permissions.js → constants.js} +1 -3
  13. package/admin/src/contexts/UsersPermissionsContext/{index.js → index.jsx} +1 -0
  14. package/admin/src/index.js +19 -28
  15. package/admin/src/pages/AdvancedSettings/{index.js → index.jsx} +68 -52
  16. package/admin/src/pages/AdvancedSettings/utils/schema.js +1 -1
  17. package/admin/src/pages/EmailTemplates/components/{EmailForm.js → EmailForm.jsx} +13 -12
  18. package/admin/src/pages/EmailTemplates/components/{EmailTable.js → EmailTable.jsx} +9 -7
  19. package/admin/src/pages/EmailTemplates/{index.js → index.jsx} +77 -63
  20. package/admin/src/pages/EmailTemplates/utils/schema.js +1 -1
  21. package/admin/src/pages/Providers/{index.js → index.jsx} +91 -86
  22. package/admin/src/pages/Providers/utils/forms.js +1 -1
  23. package/admin/src/pages/Roles/{CreatePage/utils/schema.js → constants.js} +2 -4
  24. package/admin/src/pages/Roles/hooks/usePlugins.js +78 -0
  25. package/admin/src/pages/Roles/index.jsx +33 -0
  26. package/admin/src/pages/Roles/pages/CreatePage.jsx +199 -0
  27. package/admin/src/pages/Roles/pages/EditPage.jsx +220 -0
  28. package/admin/src/pages/Roles/{ListPage/components/TableBody.js → pages/ListPage/components/TableBody.jsx} +46 -15
  29. package/admin/src/pages/Roles/{ListPage/index.js → pages/ListPage/index.jsx} +48 -47
  30. package/admin/src/pages/Roles/{ListPage → pages/ListPage}/utils/api.js +3 -4
  31. package/admin/src/translations/zh-Hans.json +80 -80
  32. package/admin/src/utils/index.js +1 -2
  33. package/dist/_chunks/ar-MvD8Ghac.mjs +44 -0
  34. package/dist/_chunks/ar-MvD8Ghac.mjs.map +1 -0
  35. package/dist/_chunks/ar-t5qTFaAD.js +44 -0
  36. package/dist/_chunks/ar-t5qTFaAD.js.map +1 -0
  37. package/dist/_chunks/cs-BMuXwxA1.mjs +50 -0
  38. package/dist/_chunks/cs-BMuXwxA1.mjs.map +1 -0
  39. package/dist/_chunks/cs-I8N4u-Sd.js +50 -0
  40. package/dist/_chunks/cs-I8N4u-Sd.js.map +1 -0
  41. package/dist/_chunks/de-YTjtq89K.js +62 -0
  42. package/dist/_chunks/de-YTjtq89K.js.map +1 -0
  43. package/dist/_chunks/de-zs2qqc0W.mjs +62 -0
  44. package/dist/_chunks/de-zs2qqc0W.mjs.map +1 -0
  45. package/dist/_chunks/dk-HctVBMsG.mjs +86 -0
  46. package/dist/_chunks/dk-HctVBMsG.mjs.map +1 -0
  47. package/dist/_chunks/dk-TF-dWjzl.js +86 -0
  48. package/dist/_chunks/dk-TF-dWjzl.js.map +1 -0
  49. package/dist/_chunks/en-CE3wEy_c.mjs +86 -0
  50. package/dist/_chunks/en-CE3wEy_c.mjs.map +1 -0
  51. package/dist/_chunks/en-m608rMZx.js +86 -0
  52. package/dist/_chunks/en-m608rMZx.js.map +1 -0
  53. package/dist/_chunks/es-9381tih_.mjs +86 -0
  54. package/dist/_chunks/es-9381tih_.mjs.map +1 -0
  55. package/dist/_chunks/es-XBQsB8_9.js +86 -0
  56. package/dist/_chunks/es-XBQsB8_9.js.map +1 -0
  57. package/dist/_chunks/fr-6cz3U-IF.js +50 -0
  58. package/dist/_chunks/fr-6cz3U-IF.js.map +1 -0
  59. package/dist/_chunks/fr-CMSc77If.mjs +50 -0
  60. package/dist/_chunks/fr-CMSc77If.mjs.map +1 -0
  61. package/dist/_chunks/id-RJ934rq-.js +62 -0
  62. package/dist/_chunks/id-RJ934rq-.js.map +1 -0
  63. package/dist/_chunks/id-SDuyIkZa.mjs +62 -0
  64. package/dist/_chunks/id-SDuyIkZa.mjs.map +1 -0
  65. package/dist/_chunks/index--NjZI15Z.mjs +301 -0
  66. package/dist/_chunks/index--NjZI15Z.mjs.map +1 -0
  67. package/dist/_chunks/index-EFtzpYTe.mjs +385 -0
  68. package/dist/_chunks/index-EFtzpYTe.mjs.map +1 -0
  69. package/dist/_chunks/index-M6VUX9Xe.mjs +250 -0
  70. package/dist/_chunks/index-M6VUX9Xe.mjs.map +1 -0
  71. package/dist/_chunks/index-PIkWT4fR.js +1191 -0
  72. package/dist/_chunks/index-PIkWT4fR.js.map +1 -0
  73. package/dist/_chunks/index-RINRWbs5.mjs +615 -0
  74. package/dist/_chunks/index-RINRWbs5.mjs.map +1 -0
  75. package/dist/_chunks/index-V3CiTkmR.mjs +1159 -0
  76. package/dist/_chunks/index-V3CiTkmR.mjs.map +1 -0
  77. package/dist/_chunks/index-d2k7RBd6.js +407 -0
  78. package/dist/_chunks/index-d2k7RBd6.js.map +1 -0
  79. package/dist/_chunks/index-f7pS9YU1.js +249 -0
  80. package/dist/_chunks/index-f7pS9YU1.js.map +1 -0
  81. package/dist/_chunks/index-j8_HHqx2.js +638 -0
  82. package/dist/_chunks/index-j8_HHqx2.js.map +1 -0
  83. package/dist/_chunks/index-zhL5rDjK.js +320 -0
  84. package/dist/_chunks/index-zhL5rDjK.js.map +1 -0
  85. package/dist/_chunks/it-YhZOlM2X.js +62 -0
  86. package/dist/_chunks/it-YhZOlM2X.js.map +1 -0
  87. package/dist/_chunks/it-bvH7DgQo.mjs +62 -0
  88. package/dist/_chunks/it-bvH7DgQo.mjs.map +1 -0
  89. package/dist/_chunks/ja-o_-JPvQv.mjs +48 -0
  90. package/dist/_chunks/ja-o_-JPvQv.mjs.map +1 -0
  91. package/dist/_chunks/ja-xssHUXFv.js +48 -0
  92. package/dist/_chunks/ja-xssHUXFv.js.map +1 -0
  93. package/dist/_chunks/ko-C3mHUSJa.js +86 -0
  94. package/dist/_chunks/ko-C3mHUSJa.js.map +1 -0
  95. package/dist/_chunks/ko-XJbPSez_.mjs +86 -0
  96. package/dist/_chunks/ko-XJbPSez_.mjs.map +1 -0
  97. package/dist/_chunks/ms-II5Ea73J.mjs +49 -0
  98. package/dist/_chunks/ms-II5Ea73J.mjs.map +1 -0
  99. package/dist/_chunks/ms-d0hfg65Z.js +49 -0
  100. package/dist/_chunks/ms-d0hfg65Z.js.map +1 -0
  101. package/dist/_chunks/nl-TA7TfK_5.js +48 -0
  102. package/dist/_chunks/nl-TA7TfK_5.js.map +1 -0
  103. package/dist/_chunks/nl-vEy6TN0K.mjs +48 -0
  104. package/dist/_chunks/nl-vEy6TN0K.mjs.map +1 -0
  105. package/dist/_chunks/pl-0pUL9hdA.js +86 -0
  106. package/dist/_chunks/pl-0pUL9hdA.js.map +1 -0
  107. package/dist/_chunks/pl-2VowaFGt.mjs +86 -0
  108. package/dist/_chunks/pl-2VowaFGt.mjs.map +1 -0
  109. package/dist/_chunks/pt-BR-WNOhafR4.js +44 -0
  110. package/dist/_chunks/pt-BR-WNOhafR4.js.map +1 -0
  111. package/dist/_chunks/pt-BR-sS1Xp3Jt.mjs +44 -0
  112. package/dist/_chunks/pt-BR-sS1Xp3Jt.mjs.map +1 -0
  113. package/dist/_chunks/pt-Rf9W51IO.mjs +48 -0
  114. package/dist/_chunks/pt-Rf9W51IO.mjs.map +1 -0
  115. package/dist/_chunks/pt-guNR9Gax.js +48 -0
  116. package/dist/_chunks/pt-guNR9Gax.js.map +1 -0
  117. package/dist/_chunks/ru-X3BMXDds.js +86 -0
  118. package/dist/_chunks/ru-X3BMXDds.js.map +1 -0
  119. package/dist/_chunks/ru-qKHnd5or.mjs +86 -0
  120. package/dist/_chunks/ru-qKHnd5or.mjs.map +1 -0
  121. package/dist/_chunks/sk-NWPw1oTN.js +50 -0
  122. package/dist/_chunks/sk-NWPw1oTN.js.map +1 -0
  123. package/dist/_chunks/sk-_Ryr-eTT.mjs +50 -0
  124. package/dist/_chunks/sk-_Ryr-eTT.mjs.map +1 -0
  125. package/dist/_chunks/sv-76NnbB__.js +86 -0
  126. package/dist/_chunks/sv-76NnbB__.js.map +1 -0
  127. package/dist/_chunks/sv-BqzScFXS.mjs +86 -0
  128. package/dist/_chunks/sv-BqzScFXS.mjs.map +1 -0
  129. package/dist/_chunks/th-WsknMEpq.mjs +60 -0
  130. package/dist/_chunks/th-WsknMEpq.mjs.map +1 -0
  131. package/dist/_chunks/th-cbppX21D.js +60 -0
  132. package/dist/_chunks/th-cbppX21D.js.map +1 -0
  133. package/dist/_chunks/tr-6mm_Fmz7.js +85 -0
  134. package/dist/_chunks/tr-6mm_Fmz7.js.map +1 -0
  135. package/dist/_chunks/tr-_DB1F1GW.mjs +85 -0
  136. package/dist/_chunks/tr-_DB1F1GW.mjs.map +1 -0
  137. package/dist/_chunks/uk-sI2I1ogF.js +49 -0
  138. package/dist/_chunks/uk-sI2I1ogF.js.map +1 -0
  139. package/dist/_chunks/uk-yxMSQAwI.mjs +49 -0
  140. package/dist/_chunks/uk-yxMSQAwI.mjs.map +1 -0
  141. package/dist/_chunks/vi-A3zJxaiI.js +50 -0
  142. package/dist/_chunks/vi-A3zJxaiI.js.map +1 -0
  143. package/dist/_chunks/vi-xY0zCW3d.mjs +50 -0
  144. package/dist/_chunks/vi-xY0zCW3d.mjs.map +1 -0
  145. package/dist/_chunks/zh-72SpmFXa.js +86 -0
  146. package/dist/_chunks/zh-72SpmFXa.js.map +1 -0
  147. package/dist/_chunks/zh-Hans-ArWWtyP4.js +86 -0
  148. package/dist/_chunks/zh-Hans-ArWWtyP4.js.map +1 -0
  149. package/dist/_chunks/zh-Hans-E84cu4kP.mjs +86 -0
  150. package/dist/_chunks/zh-Hans-E84cu4kP.mjs.map +1 -0
  151. package/dist/_chunks/zh-OFeldzbX.mjs +86 -0
  152. package/dist/_chunks/zh-OFeldzbX.mjs.map +1 -0
  153. package/dist/admin/index.js +5 -0
  154. package/dist/admin/index.js.map +1 -0
  155. package/dist/admin/index.mjs +6 -0
  156. package/dist/admin/index.mjs.map +1 -0
  157. package/documentation/content-api.yaml +1 -1
  158. package/jest.config.front.js +1 -0
  159. package/package.json +37 -18
  160. package/packup.config.ts +22 -0
  161. package/server/bootstrap/grant-config.js +9 -0
  162. package/server/bootstrap/index.js +36 -0
  163. package/server/bootstrap/users-permissions-actions.js +6 -0
  164. package/server/config.js +29 -0
  165. package/server/controllers/auth.js +73 -18
  166. package/server/controllers/user.js +12 -1
  167. package/server/middlewares/rateLimit.js +41 -21
  168. package/server/services/providers-registry.js +21 -2
  169. package/server/strategies/users-permissions.js +1 -8
  170. package/.eslintrc.js +0 -14
  171. package/admin/src/hooks/index.js +0 -5
  172. package/admin/src/hooks/useFetchRole/index.js +0 -64
  173. package/admin/src/hooks/useFetchRole/reducer.js +0 -31
  174. package/admin/src/hooks/useForm/index.js +0 -67
  175. package/admin/src/hooks/useForm/reducer.js +0 -40
  176. package/admin/src/hooks/usePlugins/index.js +0 -67
  177. package/admin/src/hooks/usePlugins/init.js +0 -5
  178. package/admin/src/hooks/usePlugins/reducer.js +0 -34
  179. package/admin/src/hooks/useRolesList/index.js +0 -62
  180. package/admin/src/hooks/useRolesList/init.js +0 -5
  181. package/admin/src/hooks/useRolesList/reducer.js +0 -31
  182. package/admin/src/pages/AdvancedSettings/utils/api.js +0 -17
  183. package/admin/src/pages/EmailTemplates/utils/api.js +0 -17
  184. package/admin/src/pages/Providers/reducer.js +0 -54
  185. package/admin/src/pages/Providers/utils/api.js +0 -25
  186. package/admin/src/pages/Providers/utils/createProvidersArray.js +0 -21
  187. package/admin/src/pages/Roles/CreatePage/index.js +0 -182
  188. package/admin/src/pages/Roles/EditPage/index.js +0 -194
  189. package/admin/src/pages/Roles/EditPage/utils/schema.js +0 -9
  190. package/admin/src/pages/Roles/ProtectedCreatePage/index.js +0 -12
  191. package/admin/src/pages/Roles/ProtectedEditPage/index.js +0 -12
  192. package/admin/src/pages/Roles/ProtectedListPage/index.js +0 -15
  193. package/admin/src/pages/Roles/index.js +0 -27
  194. package/admin/src/utils/getRequestURL.js +0 -5
  195. package/strapi-admin.js +0 -3
  196. package/admin/src/components/Permissions/PermissionRow/{CheckboxWrapper.js → CheckboxWrapper.jsx} +1 -1
@@ -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,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 };
@@ -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('email-templates'));
7
-
8
- return data;
9
- };
10
-
11
- const putEmailTemplate = (body) => {
12
- const { put } = getFetchClient();
13
-
14
- return put(getRequestURL('email-templates'), body);
15
- };
16
-
17
- export { fetchData, putEmailTemplate };
@@ -1,54 +0,0 @@
1
- import produce from 'immer';
2
- import set from 'lodash/set';
3
-
4
- const initialState = {
5
- formErrors: {},
6
- isLoading: true,
7
- initialData: {},
8
- modifiedData: {},
9
- };
10
-
11
- const reducer = (state, action) =>
12
- // eslint-disable-next-line consistent-return
13
- produce(state, (draftState) => {
14
- switch (action.type) {
15
- case 'GET_DATA': {
16
- draftState.isLoading = true;
17
- draftState.initialData = {};
18
- draftState.modifiedData = {};
19
-
20
- break;
21
- }
22
-
23
- case 'GET_DATA_SUCCEEDED': {
24
- draftState.isLoading = false;
25
- draftState.initialData = action.data;
26
- draftState.modifiedData = action.data;
27
-
28
- break;
29
- }
30
- case 'GET_DATA_ERROR': {
31
- draftState.isLoading = true;
32
- break;
33
- }
34
- case 'ON_CHANGE': {
35
- set(draftState, ['modifiedData', ...action.keys.split('.')], action.value);
36
- break;
37
- }
38
- case 'RESET_FORM': {
39
- draftState.modifiedData = state.initialData;
40
- draftState.formErrors = {};
41
- break;
42
- }
43
- case 'SET_ERRORS': {
44
- draftState.formErrors = action.errors;
45
- break;
46
- }
47
- default: {
48
- return draftState;
49
- }
50
- }
51
- });
52
-
53
- export default reducer;
54
- export { initialState };
@@ -1,25 +0,0 @@
1
- import { getFetchClient } from '@strapi/helper-plugin';
2
- import { getRequestURL } from '../../../utils';
3
-
4
- // eslint-disable-next-line import/prefer-default-export
5
- export const fetchData = async (toggleNotification) => {
6
- try {
7
- const { get } = getFetchClient();
8
- const { data } = await get(getRequestURL('providers'));
9
-
10
- return data;
11
- } catch (err) {
12
- toggleNotification({
13
- type: 'warning',
14
- message: { id: 'notification.error' },
15
- });
16
-
17
- throw new Error('error');
18
- }
19
- };
20
-
21
- export const putProvider = (body) => {
22
- const { put } = getFetchClient();
23
-
24
- return put(getRequestURL('providers'), body);
25
- };
@@ -1,21 +0,0 @@
1
- import sortBy from 'lodash/sortBy';
2
-
3
- const createProvidersArray = (data) => {
4
- return sortBy(
5
- Object.keys(data).reduce((acc, current) => {
6
- const { icon: iconName, enabled, subdomain } = data[current];
7
- const icon = iconName === 'envelope' ? ['fas', 'envelope'] : ['fab', iconName];
8
-
9
- if (subdomain !== undefined) {
10
- acc.push({ name: current, icon, enabled, subdomain });
11
- } else {
12
- acc.push({ name: current, icon, enabled });
13
- }
14
-
15
- return acc;
16
- }, []),
17
- 'name'
18
- );
19
- };
20
-
21
- export default createProvidersArray;
@@ -1,182 +0,0 @@
1
- import React, { useState, useRef } from 'react';
2
- import { useHistory } from 'react-router-dom';
3
- import {
4
- ContentLayout,
5
- HeaderLayout,
6
- Main,
7
- Button,
8
- Flex,
9
- Box,
10
- TextInput,
11
- Textarea,
12
- Typography,
13
- GridItem,
14
- Grid,
15
- } from '@strapi/design-system';
16
- import { Check } from '@strapi/icons';
17
- import { Formik } from 'formik';
18
- import { useIntl } from 'react-intl';
19
- import {
20
- useOverlayBlocker,
21
- SettingsPageTitle,
22
- useFetchClient,
23
- useTracking,
24
- Form,
25
- useNotification,
26
- } from '@strapi/helper-plugin';
27
- import UsersPermissions from '../../../components/UsersPermissions';
28
- import getTrad from '../../../utils/getTrad';
29
- import pluginId from '../../../pluginId';
30
- import { usePlugins } from '../../../hooks';
31
- import schema from './utils/schema';
32
-
33
- const EditPage = () => {
34
- const { formatMessage } = useIntl();
35
- const [isSubmitting, setIsSubmitting] = useState(false);
36
- const toggleNotification = useNotification();
37
- const { goBack } = useHistory();
38
- const { lockApp, unlockApp } = useOverlayBlocker();
39
- const { isLoading: isLoadingPlugins, permissions, routes } = usePlugins();
40
- const { trackUsage } = useTracking();
41
- const permissionsRef = useRef();
42
- const { post } = useFetchClient();
43
-
44
- const handleCreateRoleSubmit = async (data) => {
45
- // Set loading state
46
- lockApp();
47
- setIsSubmitting(true);
48
- try {
49
- const permissions = permissionsRef.current.getPermissions();
50
- // Update role in Strapi
51
- await post(`/${pluginId}/roles`, { ...data, ...permissions, users: [] });
52
- // Notify success
53
- trackUsage('didCreateRole');
54
- toggleNotification({
55
- type: 'success',
56
- message: {
57
- id: getTrad('Settings.roles.created'),
58
- defaultMessage: 'Role created',
59
- },
60
- });
61
- // Forcing redirecting since we don't have the id in the response
62
- goBack();
63
- } catch (err) {
64
- console.error(err);
65
- toggleNotification({
66
- type: 'warning',
67
- message: {
68
- id: 'notification.error',
69
- defaultMessage: 'An error occurred',
70
- },
71
- });
72
- }
73
- // Unset loading state
74
- setIsSubmitting(false);
75
- unlockApp();
76
- };
77
-
78
- return (
79
- <Main>
80
- <SettingsPageTitle name="Roles" />
81
- <Formik
82
- enableReinitialize
83
- initialValues={{ name: '', description: '' }}
84
- onSubmit={handleCreateRoleSubmit}
85
- validationSchema={schema}
86
- >
87
- {({ handleSubmit, values, handleChange, errors }) => (
88
- <Form noValidate onSubmit={handleSubmit}>
89
- <HeaderLayout
90
- primaryAction={
91
- !isLoadingPlugins && (
92
- <Button type="submit" loading={isSubmitting} startIcon={<Check />}>
93
- {formatMessage({
94
- id: 'global.save',
95
- defaultMessage: 'Save',
96
- })}
97
- </Button>
98
- )
99
- }
100
- title={formatMessage({
101
- id: 'Settings.roles.create.title',
102
- defaultMessage: 'Create a role',
103
- })}
104
- subtitle={formatMessage({
105
- id: 'Settings.roles.create.description',
106
- defaultMessage: 'Define the rights given to the role',
107
- })}
108
- />
109
- <ContentLayout>
110
- <Flex direction="column" alignItems="stretch" gap={7}>
111
- <Box
112
- background="neutral0"
113
- hasRadius
114
- shadow="filterShadow"
115
- paddingTop={6}
116
- paddingBottom={6}
117
- paddingLeft={7}
118
- paddingRight={7}
119
- >
120
- <Flex direction="column" alignItems="stretch" gap={4}>
121
- <Typography variant="delta" as="h2">
122
- {formatMessage({
123
- id: getTrad('EditPage.form.roles'),
124
- defaultMessage: 'Role details',
125
- })}
126
- </Typography>
127
- <Grid gap={4}>
128
- <GridItem col={6}>
129
- <TextInput
130
- name="name"
131
- value={values.name || ''}
132
- onChange={handleChange}
133
- label={formatMessage({
134
- id: 'global.name',
135
- defaultMessage: 'Name',
136
- })}
137
- error={
138
- errors.name
139
- ? formatMessage({ id: errors.name, defaultMessage: 'Invalid value' })
140
- : null
141
- }
142
- />
143
- </GridItem>
144
- <GridItem col={6}>
145
- <Textarea
146
- id="description"
147
- value={values.description || ''}
148
- onChange={handleChange}
149
- label={formatMessage({
150
- id: 'global.description',
151
- defaultMessage: 'Description',
152
- })}
153
- error={
154
- errors.description
155
- ? formatMessage({
156
- id: errors.description,
157
- defaultMessage: 'Invalid value',
158
- })
159
- : null
160
- }
161
- />
162
- </GridItem>
163
- </Grid>
164
- </Flex>
165
- </Box>
166
- {!isLoadingPlugins && (
167
- <UsersPermissions
168
- ref={permissionsRef}
169
- permissions={permissions}
170
- routes={routes}
171
- />
172
- )}
173
- </Flex>
174
- </ContentLayout>
175
- </Form>
176
- )}
177
- </Formik>
178
- </Main>
179
- );
180
- };
181
-
182
- export default EditPage;