@strapi/plugin-users-permissions 0.0.0-next.f45143c5e2a8a9d85691d0abf79a3f42024a0c71 → 0.0.0-next.f4ec69568d980c6fee91ce2ee0f41c138347aa81

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 (229) 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} +37 -33
  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/ru.json +50 -26
  36. package/admin/src/translations/zh-Hans.json +80 -80
  37. package/admin/src/utils/index.js +1 -2
  38. package/admin/src/utils/prefixPluginTranslations.js +13 -0
  39. package/dist/_chunks/ar-BguGUqwK.js +44 -0
  40. package/dist/_chunks/ar-BguGUqwK.js.map +1 -0
  41. package/dist/_chunks/ar-CK8BRRXB.mjs +44 -0
  42. package/dist/_chunks/ar-CK8BRRXB.mjs.map +1 -0
  43. package/dist/_chunks/cs-BVigMk0l.mjs +50 -0
  44. package/dist/_chunks/cs-BVigMk0l.mjs.map +1 -0
  45. package/dist/_chunks/cs-BW8-K_GY.js +50 -0
  46. package/dist/_chunks/cs-BW8-K_GY.js.map +1 -0
  47. package/dist/_chunks/de-BKUdRFI4.mjs +62 -0
  48. package/dist/_chunks/de-BKUdRFI4.mjs.map +1 -0
  49. package/dist/_chunks/de-owXpVluI.js +62 -0
  50. package/dist/_chunks/de-owXpVluI.js.map +1 -0
  51. package/dist/_chunks/dk-BQiTK50l.mjs +86 -0
  52. package/dist/_chunks/dk-BQiTK50l.mjs.map +1 -0
  53. package/dist/_chunks/dk-LXAnbuBk.js +86 -0
  54. package/dist/_chunks/dk-LXAnbuBk.js.map +1 -0
  55. package/dist/_chunks/en-DOHtPf-2.mjs +86 -0
  56. package/dist/_chunks/en-DOHtPf-2.mjs.map +1 -0
  57. package/dist/_chunks/en-MHo5mcsU.js +86 -0
  58. package/dist/_chunks/en-MHo5mcsU.js.map +1 -0
  59. package/dist/_chunks/es-BwLCLXAQ.js +86 -0
  60. package/dist/_chunks/es-BwLCLXAQ.js.map +1 -0
  61. package/dist/_chunks/es-DNgOVMjD.mjs +86 -0
  62. package/dist/_chunks/es-DNgOVMjD.mjs.map +1 -0
  63. package/dist/_chunks/fr-DkgRugiU.mjs +50 -0
  64. package/dist/_chunks/fr-DkgRugiU.mjs.map +1 -0
  65. package/dist/_chunks/fr-DkhpSjjm.js +50 -0
  66. package/dist/_chunks/fr-DkhpSjjm.js.map +1 -0
  67. package/dist/_chunks/id-BTemOeTZ.js +62 -0
  68. package/dist/_chunks/id-BTemOeTZ.js.map +1 -0
  69. package/dist/_chunks/id-BdEsvnaF.mjs +62 -0
  70. package/dist/_chunks/id-BdEsvnaF.mjs.map +1 -0
  71. package/dist/_chunks/index-2awRBazk.js +281 -0
  72. package/dist/_chunks/index-2awRBazk.js.map +1 -0
  73. package/dist/_chunks/index-BAHBK68t.js +1172 -0
  74. package/dist/_chunks/index-BAHBK68t.js.map +1 -0
  75. package/dist/_chunks/index-BHbzbu1p.mjs +246 -0
  76. package/dist/_chunks/index-BHbzbu1p.mjs.map +1 -0
  77. package/dist/_chunks/index-Be4qNiZI.js +640 -0
  78. package/dist/_chunks/index-Be4qNiZI.js.map +1 -0
  79. package/dist/_chunks/index-C88EQQJQ-C4oUQUND.js +12026 -0
  80. package/dist/_chunks/index-C88EQQJQ-C4oUQUND.js.map +1 -0
  81. package/dist/_chunks/index-C88EQQJQ-DAZ1lfuF.mjs +12002 -0
  82. package/dist/_chunks/index-C88EQQJQ-DAZ1lfuF.mjs.map +1 -0
  83. package/dist/_chunks/index-CbKOY95_.mjs +344 -0
  84. package/dist/_chunks/index-CbKOY95_.mjs.map +1 -0
  85. package/dist/_chunks/index-CeweK3q9.mjs +617 -0
  86. package/dist/_chunks/index-CeweK3q9.mjs.map +1 -0
  87. package/dist/_chunks/index-QcDREbPt.mjs +262 -0
  88. package/dist/_chunks/index-QcDREbPt.mjs.map +1 -0
  89. package/dist/_chunks/index-YTFP-hNZ.js +245 -0
  90. package/dist/_chunks/index-YTFP-hNZ.js.map +1 -0
  91. package/dist/_chunks/index-YZkqoYZN.js +366 -0
  92. package/dist/_chunks/index-YZkqoYZN.js.map +1 -0
  93. package/dist/_chunks/index-mKh-etKG.mjs +1142 -0
  94. package/dist/_chunks/index-mKh-etKG.mjs.map +1 -0
  95. package/dist/_chunks/it-B-rv0E24.mjs +62 -0
  96. package/dist/_chunks/it-B-rv0E24.mjs.map +1 -0
  97. package/dist/_chunks/it-D1rH6V6_.js +62 -0
  98. package/dist/_chunks/it-D1rH6V6_.js.map +1 -0
  99. package/dist/_chunks/ja-C8K-VBPD.mjs +48 -0
  100. package/dist/_chunks/ja-C8K-VBPD.mjs.map +1 -0
  101. package/dist/_chunks/ja-DqShgTMf.js +48 -0
  102. package/dist/_chunks/ja-DqShgTMf.js.map +1 -0
  103. package/dist/_chunks/ko-B9DGEPWH.js +86 -0
  104. package/dist/_chunks/ko-B9DGEPWH.js.map +1 -0
  105. package/dist/_chunks/ko-Busb0wIY.mjs +86 -0
  106. package/dist/_chunks/ko-Busb0wIY.mjs.map +1 -0
  107. package/dist/_chunks/ms-ByvsQjRt.mjs +49 -0
  108. package/dist/_chunks/ms-ByvsQjRt.mjs.map +1 -0
  109. package/dist/_chunks/ms-CPBU3LWf.js +49 -0
  110. package/dist/_chunks/ms-CPBU3LWf.js.map +1 -0
  111. package/dist/_chunks/nl-5qO8Rpcy.mjs +48 -0
  112. package/dist/_chunks/nl-5qO8Rpcy.mjs.map +1 -0
  113. package/dist/_chunks/nl-CwNB6YoO.js +48 -0
  114. package/dist/_chunks/nl-CwNB6YoO.js.map +1 -0
  115. package/dist/_chunks/pl-BdIzifBE.mjs +86 -0
  116. package/dist/_chunks/pl-BdIzifBE.mjs.map +1 -0
  117. package/dist/_chunks/pl-Do9UD69f.js +86 -0
  118. package/dist/_chunks/pl-Do9UD69f.js.map +1 -0
  119. package/dist/_chunks/pt-BIO24ioG.mjs +48 -0
  120. package/dist/_chunks/pt-BIO24ioG.mjs.map +1 -0
  121. package/dist/_chunks/pt-BR-D7dZhxuP.js +44 -0
  122. package/dist/_chunks/pt-BR-D7dZhxuP.js.map +1 -0
  123. package/dist/_chunks/pt-BR-f0p23AQZ.mjs +44 -0
  124. package/dist/_chunks/pt-BR-f0p23AQZ.mjs.map +1 -0
  125. package/dist/_chunks/pt-fdvyOnUp.js +48 -0
  126. package/dist/_chunks/pt-fdvyOnUp.js.map +1 -0
  127. package/dist/_chunks/ru-C94rjPGA.js +86 -0
  128. package/dist/_chunks/ru-C94rjPGA.js.map +1 -0
  129. package/dist/_chunks/ru-VWy-IB7K.mjs +86 -0
  130. package/dist/_chunks/ru-VWy-IB7K.mjs.map +1 -0
  131. package/dist/_chunks/sk-BABEhykl.js +50 -0
  132. package/dist/_chunks/sk-BABEhykl.js.map +1 -0
  133. package/dist/_chunks/sk-B_LIcepm.mjs +50 -0
  134. package/dist/_chunks/sk-B_LIcepm.mjs.map +1 -0
  135. package/dist/_chunks/sv-ABLKOokl.mjs +86 -0
  136. package/dist/_chunks/sv-ABLKOokl.mjs.map +1 -0
  137. package/dist/_chunks/sv-Be43LhA9.js +86 -0
  138. package/dist/_chunks/sv-Be43LhA9.js.map +1 -0
  139. package/dist/_chunks/th-DKyP7ueR.mjs +60 -0
  140. package/dist/_chunks/th-DKyP7ueR.mjs.map +1 -0
  141. package/dist/_chunks/th-DgVhVLhL.js +60 -0
  142. package/dist/_chunks/th-DgVhVLhL.js.map +1 -0
  143. package/dist/_chunks/tr-B_idhkEs.js +85 -0
  144. package/dist/_chunks/tr-B_idhkEs.js.map +1 -0
  145. package/dist/_chunks/tr-qa1Q5UjC.mjs +85 -0
  146. package/dist/_chunks/tr-qa1Q5UjC.mjs.map +1 -0
  147. package/dist/_chunks/uk-BmRqbeQc.mjs +49 -0
  148. package/dist/_chunks/uk-BmRqbeQc.mjs.map +1 -0
  149. package/dist/_chunks/uk-LHOivnhP.js +49 -0
  150. package/dist/_chunks/uk-LHOivnhP.js.map +1 -0
  151. package/dist/_chunks/vi-CdVRdKDw.js +50 -0
  152. package/dist/_chunks/vi-CdVRdKDw.js.map +1 -0
  153. package/dist/_chunks/vi-HW-EdMea.mjs +50 -0
  154. package/dist/_chunks/vi-HW-EdMea.mjs.map +1 -0
  155. package/dist/_chunks/zh-5hKkVPA4.mjs +86 -0
  156. package/dist/_chunks/zh-5hKkVPA4.mjs.map +1 -0
  157. package/dist/_chunks/zh-Cuq8gMnF.js +86 -0
  158. package/dist/_chunks/zh-Cuq8gMnF.js.map +1 -0
  159. package/dist/_chunks/zh-Hans-BHilK-yc.mjs +86 -0
  160. package/dist/_chunks/zh-Hans-BHilK-yc.mjs.map +1 -0
  161. package/dist/_chunks/zh-Hans-GQDMKtY4.js +86 -0
  162. package/dist/_chunks/zh-Hans-GQDMKtY4.js.map +1 -0
  163. package/dist/admin/index.js +4 -0
  164. package/dist/admin/index.js.map +1 -0
  165. package/dist/admin/index.mjs +5 -0
  166. package/dist/admin/index.mjs.map +1 -0
  167. package/documentation/content-api.yaml +23 -15
  168. package/jest.config.front.js +2 -0
  169. package/package.json +51 -35
  170. package/packup.config.ts +22 -0
  171. package/server/bootstrap/index.js +18 -15
  172. package/server/bootstrap/users-permissions-actions.js +6 -0
  173. package/server/config.js +29 -0
  174. package/server/content-types/user/index.js +0 -1
  175. package/server/controllers/auth.js +74 -38
  176. package/server/controllers/content-manager-user.js +28 -30
  177. package/server/controllers/role.js +17 -4
  178. package/server/controllers/user.js +18 -8
  179. package/server/controllers/validation/auth.js +81 -25
  180. package/server/middlewares/rateLimit.js +41 -21
  181. package/server/register.js +8 -2
  182. package/server/services/jwt.js +3 -3
  183. package/server/services/permission.js +3 -7
  184. package/server/services/providers-registry.js +469 -261
  185. package/server/services/providers.js +10 -5
  186. package/server/services/role.js +15 -13
  187. package/server/services/user.js +56 -19
  188. package/server/services/users-permissions.js +15 -13
  189. package/server/strategies/users-permissions.js +1 -8
  190. package/server/utils/index.d.ts +2 -1
  191. package/server/utils/sanitize/sanitizers.js +7 -3
  192. package/server/utils/sanitize/visitors/remove-user-relation-from-role-entities.js +2 -2
  193. package/.eslintrc.js +0 -14
  194. package/admin/src/components/FormModal/index.js +0 -123
  195. package/admin/src/components/Permissions/index.js +0 -54
  196. package/admin/src/hooks/index.js +0 -5
  197. package/admin/src/hooks/useFetchRole/index.js +0 -64
  198. package/admin/src/hooks/useFetchRole/reducer.js +0 -31
  199. package/admin/src/hooks/useForm/index.js +0 -70
  200. package/admin/src/hooks/useForm/reducer.js +0 -40
  201. package/admin/src/hooks/usePlugins/index.js +0 -67
  202. package/admin/src/hooks/usePlugins/init.js +0 -5
  203. package/admin/src/hooks/usePlugins/reducer.js +0 -34
  204. package/admin/src/hooks/useRolesList/index.js +0 -63
  205. package/admin/src/hooks/useRolesList/init.js +0 -5
  206. package/admin/src/hooks/useRolesList/reducer.js +0 -31
  207. package/admin/src/pages/AdvancedSettings/index.js +0 -243
  208. package/admin/src/pages/AdvancedSettings/utils/api.js +0 -17
  209. package/admin/src/pages/EmailTemplates/components/EmailForm.js +0 -175
  210. package/admin/src/pages/EmailTemplates/index.js +0 -160
  211. package/admin/src/pages/EmailTemplates/utils/api.js +0 -17
  212. package/admin/src/pages/Providers/index.js +0 -272
  213. package/admin/src/pages/Providers/reducer.js +0 -54
  214. package/admin/src/pages/Providers/utils/api.js +0 -25
  215. package/admin/src/pages/Providers/utils/createProvidersArray.js +0 -21
  216. package/admin/src/pages/Roles/CreatePage/index.js +0 -182
  217. package/admin/src/pages/Roles/CreatePage/utils/schema.js +0 -9
  218. package/admin/src/pages/Roles/EditPage/index.js +0 -194
  219. package/admin/src/pages/Roles/EditPage/utils/schema.js +0 -9
  220. package/admin/src/pages/Roles/ListPage/components/TableBody.js +0 -92
  221. package/admin/src/pages/Roles/ListPage/utils/api.js +0 -31
  222. package/admin/src/pages/Roles/ProtectedCreatePage/index.js +0 -12
  223. package/admin/src/pages/Roles/ProtectedEditPage/index.js +0 -12
  224. package/admin/src/pages/Roles/ProtectedListPage/index.js +0 -15
  225. package/admin/src/pages/Roles/index.js +0 -27
  226. package/admin/src/utils/getRequestURL.js +0 -5
  227. package/server/bootstrap/grant-config.js +0 -131
  228. package/strapi-admin.js +0 -3
  229. package/strapi-server.js +0 -3
@@ -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
- name="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;
@@ -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,194 +0,0 @@
1
- import React, { useState, useRef } from 'react';
2
- import { Formik } from 'formik';
3
- import { useIntl } from 'react-intl';
4
- import { useRouteMatch } from 'react-router-dom';
5
- import {
6
- useFetchClient,
7
- useOverlayBlocker,
8
- SettingsPageTitle,
9
- LoadingIndicatorPage,
10
- Form,
11
- useNotification,
12
- Link,
13
- } from '@strapi/helper-plugin';
14
- import {
15
- ContentLayout,
16
- HeaderLayout,
17
- Main,
18
- Button,
19
- Flex,
20
- Box,
21
- TextInput,
22
- Textarea,
23
- Typography,
24
- GridItem,
25
- Grid,
26
- } from '@strapi/design-system';
27
- import { ArrowLeft, Check } from '@strapi/icons';
28
- import UsersPermissions from '../../../components/UsersPermissions';
29
- import getTrad from '../../../utils/getTrad';
30
- import pluginId from '../../../pluginId';
31
- import { usePlugins, useFetchRole } from '../../../hooks';
32
- import schema from './utils/schema';
33
-
34
- const EditPage = () => {
35
- const { formatMessage } = useIntl();
36
- const [isSubmitting, setIsSubmitting] = useState(false);
37
- const toggleNotification = useNotification();
38
- const { lockApp, unlockApp } = useOverlayBlocker();
39
- const {
40
- params: { id },
41
- } = useRouteMatch(`/settings/${pluginId}/roles/:id`);
42
- const { isLoading: isLoadingPlugins, routes } = usePlugins();
43
- const { role, onSubmitSucceeded, isLoading: isLoadingRole } = useFetchRole(id);
44
- const permissionsRef = useRef();
45
- const { put } = useFetchClient();
46
-
47
- const handleEditRoleSubmit = async (data) => {
48
- // Set loading state
49
- lockApp();
50
- setIsSubmitting(true);
51
- try {
52
- const permissions = permissionsRef.current.getPermissions();
53
- // Update role in Strapi
54
- await put(`/${pluginId}/roles/${id}`, { ...data, ...permissions, users: [] });
55
- // Notify success
56
- onSubmitSucceeded({ name: data.name, description: data.description });
57
- toggleNotification({
58
- type: 'success',
59
- message: {
60
- id: getTrad('Settings.roles.edited'),
61
- defaultMessage: 'Role edited',
62
- },
63
- });
64
- } catch (err) {
65
- console.error(err);
66
- toggleNotification({
67
- type: 'warning',
68
- message: {
69
- id: 'notification.error',
70
- defaultMessage: 'An error occurred',
71
- },
72
- });
73
- }
74
- // Unset loading state
75
- setIsSubmitting(false);
76
- unlockApp();
77
- };
78
-
79
- if (isLoadingRole) {
80
- return <LoadingIndicatorPage />;
81
- }
82
-
83
- return (
84
- <Main>
85
- <SettingsPageTitle name="Roles" />
86
- <Formik
87
- enableReinitialize
88
- initialValues={{ name: role.name, description: role.description }}
89
- onSubmit={handleEditRoleSubmit}
90
- validationSchema={schema}
91
- >
92
- {({ handleSubmit, values, handleChange, errors }) => (
93
- <Form noValidate onSubmit={handleSubmit}>
94
- <HeaderLayout
95
- primaryAction={
96
- !isLoadingPlugins && (
97
- <Button
98
- disabled={role.code === 'strapi-super-admin'}
99
- type="submit"
100
- loading={isSubmitting}
101
- startIcon={<Check />}
102
- >
103
- {formatMessage({
104
- id: 'global.save',
105
- defaultMessage: 'Save',
106
- })}
107
- </Button>
108
- )
109
- }
110
- title={role.name}
111
- subtitle={role.description}
112
- navigationAction={
113
- <Link startIcon={<ArrowLeft />} to="/settings/users-permissions/roles">
114
- {formatMessage({
115
- id: 'global.back',
116
- defaultMessage: 'Back',
117
- })}
118
- </Link>
119
- }
120
- />
121
- <ContentLayout>
122
- <Flex direction="column" alignItems="stretch" gap={7}>
123
- <Box
124
- background="neutral0"
125
- hasRadius
126
- shadow="filterShadow"
127
- paddingTop={6}
128
- paddingBottom={6}
129
- paddingLeft={7}
130
- paddingRight={7}
131
- >
132
- <Flex direction="column" alignItems="stretch" gap={4}>
133
- <Typography variant="delta" as="h2">
134
- {formatMessage({
135
- id: getTrad('EditPage.form.roles'),
136
- defaultMessage: 'Role details',
137
- })}
138
- </Typography>
139
- <Grid gap={4}>
140
- <GridItem col={6}>
141
- <TextInput
142
- name="name"
143
- value={values.name || ''}
144
- onChange={handleChange}
145
- label={formatMessage({
146
- id: 'global.name',
147
- defaultMessage: 'Name',
148
- })}
149
- error={
150
- errors.name
151
- ? formatMessage({ id: errors.name, defaultMessage: 'Invalid value' })
152
- : null
153
- }
154
- />
155
- </GridItem>
156
- <GridItem col={6}>
157
- <Textarea
158
- name="description"
159
- value={values.description || ''}
160
- onChange={handleChange}
161
- label={formatMessage({
162
- id: 'global.description',
163
- defaultMessage: 'Description',
164
- })}
165
- error={
166
- errors.description
167
- ? formatMessage({
168
- id: errors.description,
169
- defaultMessage: 'Invalid value',
170
- })
171
- : null
172
- }
173
- />
174
- </GridItem>
175
- </Grid>
176
- </Flex>
177
- </Box>
178
- {!isLoadingPlugins && (
179
- <UsersPermissions
180
- ref={permissionsRef}
181
- permissions={role.permissions}
182
- routes={routes}
183
- />
184
- )}
185
- </Flex>
186
- </ContentLayout>
187
- </Form>
188
- )}
189
- </Formik>
190
- </Main>
191
- );
192
- };
193
-
194
- export default EditPage;
@@ -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,92 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { IconButton, Typography, Flex, Tbody, Tr, Td } from '@strapi/design-system';
4
- import { Pencil, Trash } from '@strapi/icons';
5
- import { CheckPermissions, onRowClick, stopPropagation } from '@strapi/helper-plugin';
6
- import { useIntl } from 'react-intl';
7
- import { useHistory } from 'react-router-dom';
8
-
9
- import pluginId from '../../../../pluginId';
10
-
11
- const TableBody = ({ sortedRoles, canDelete, permissions, setRoleToDelete, onDelete }) => {
12
- const { formatMessage } = useIntl();
13
- const { push } = useHistory();
14
- const [showConfirmDelete, setShowConfirmDelete] = onDelete;
15
-
16
- const checkCanDeleteRole = (role) =>
17
- canDelete && !['public', 'authenticated'].includes(role.type);
18
-
19
- const handleClickDelete = (id) => {
20
- setRoleToDelete(id);
21
- setShowConfirmDelete(!showConfirmDelete);
22
- };
23
-
24
- const handleClickEdit = (id) => {
25
- push(`/settings/${pluginId}/roles/${id}`);
26
- };
27
-
28
- return (
29
- <Tbody>
30
- {sortedRoles?.map((role) => (
31
- <Tr key={role.name} {...onRowClick({ fn: () => handleClickEdit(role.id) })}>
32
- <Td width="20%">
33
- <Typography>{role.name}</Typography>
34
- </Td>
35
- <Td width="50%">
36
- <Typography>{role.description}</Typography>
37
- </Td>
38
- <Td width="30%">
39
- <Typography>
40
- {`${role.nb_users} ${formatMessage({
41
- id: 'global.users',
42
- defaultMessage: 'users',
43
- }).toLowerCase()}`}
44
- </Typography>
45
- </Td>
46
- <Td>
47
- <Flex justifyContent="end" {...stopPropagation}>
48
- <CheckPermissions permissions={permissions.updateRole}>
49
- <IconButton
50
- onClick={() => handleClickEdit(role.id)}
51
- noBorder
52
- icon={<Pencil />}
53
- label={formatMessage(
54
- { id: 'app.component.table.edit', defaultMessage: 'Edit {target}' },
55
- { target: `${role.name}` }
56
- )}
57
- />
58
- </CheckPermissions>
59
- {checkCanDeleteRole(role) && (
60
- <CheckPermissions permissions={permissions.deleteRole}>
61
- <IconButton
62
- onClick={() => handleClickDelete(role.id)}
63
- noBorder
64
- icon={<Trash />}
65
- label={formatMessage(
66
- { id: 'global.delete-target', defaultMessage: 'Delete {target}' },
67
- { target: `${role.name}` }
68
- )}
69
- />
70
- </CheckPermissions>
71
- )}
72
- </Flex>
73
- </Td>
74
- </Tr>
75
- ))}
76
- </Tbody>
77
- );
78
- };
79
-
80
- export default TableBody;
81
-
82
- TableBody.defaultProps = {
83
- canDelete: false,
84
- };
85
-
86
- TableBody.propTypes = {
87
- onDelete: PropTypes.array.isRequired,
88
- permissions: PropTypes.object.isRequired,
89
- setRoleToDelete: PropTypes.func.isRequired,
90
- sortedRoles: PropTypes.array.isRequired,
91
- canDelete: PropTypes.bool,
92
- };
@@ -1,31 +0,0 @@
1
- import { getFetchClient } from '@strapi/helper-plugin';
2
- import { getRequestURL } from '../../../../utils';
3
-
4
- export const fetchData = async (toggleNotification, notifyStatus) => {
5
- try {
6
- const { get } = getFetchClient();
7
- const { data } = await get(getRequestURL('roles'));
8
- notifyStatus('The roles have loaded successfully');
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 deleteData = async (id, toggleNotification) => {
22
- try {
23
- const { del } = getFetchClient();
24
- await del(`${getRequestURL('roles')}/${id}`);
25
- } catch (error) {
26
- toggleNotification({
27
- type: 'warning',
28
- message: { id: 'notification.error', defaultMessage: 'An error occured' },
29
- });
30
- }
31
- };
@@ -1,12 +0,0 @@
1
- import React from 'react';
2
- import { CheckPagePermissions } from '@strapi/helper-plugin';
3
- import pluginPermissions from '../../../permissions';
4
- import RolesCreatePage from '../CreatePage';
5
-
6
- const ProtectedRolesCreatePage = () => (
7
- <CheckPagePermissions permissions={pluginPermissions.createRole}>
8
- <RolesCreatePage />
9
- </CheckPagePermissions>
10
- );
11
-
12
- export default ProtectedRolesCreatePage;
@@ -1,12 +0,0 @@
1
- import React from 'react';
2
- import { CheckPagePermissions } from '@strapi/helper-plugin';
3
- import pluginPermissions from '../../../permissions';
4
- import RolesEditPage from '../EditPage';
5
-
6
- const ProtectedRolesEditPage = () => (
7
- <CheckPagePermissions permissions={pluginPermissions.updateRole}>
8
- <RolesEditPage />
9
- </CheckPagePermissions>
10
- );
11
-
12
- export default ProtectedRolesEditPage;
@@ -1,15 +0,0 @@
1
- import React from 'react';
2
- import { CheckPagePermissions } from '@strapi/helper-plugin';
3
- import pluginPermissions from '../../../permissions';
4
-
5
- import RolesListPage from '../ListPage';
6
-
7
- const ProtectedRolesListPage = () => {
8
- return (
9
- <CheckPagePermissions permissions={pluginPermissions.accessRoles}>
10
- <RolesListPage />
11
- </CheckPagePermissions>
12
- );
13
- };
14
-
15
- export default ProtectedRolesListPage;
@@ -1,27 +0,0 @@
1
- import React from 'react';
2
- import { Switch, Route } from 'react-router-dom';
3
- import { CheckPagePermissions, AnErrorOccurred } from '@strapi/helper-plugin';
4
- import pluginId from '../../pluginId';
5
- import pluginPermissions from '../../permissions';
6
- import ProtectedRolesListPage from './ProtectedListPage';
7
- import ProtectedRolesEditPage from './ProtectedEditPage';
8
- import ProtectedRolesCreatePage from './ProtectedCreatePage';
9
-
10
- const Roles = () => {
11
- return (
12
- <CheckPagePermissions permissions={pluginPermissions.accessRoles}>
13
- <Switch>
14
- <Route
15
- path={`/settings/${pluginId}/roles/new`}
16
- component={ProtectedRolesCreatePage}
17
- exact
18
- />
19
- <Route path={`/settings/${pluginId}/roles/:id`} component={ProtectedRolesEditPage} exact />
20
- <Route path={`/settings/${pluginId}/roles`} component={ProtectedRolesListPage} exact />
21
- <Route path="" component={AnErrorOccurred} />
22
- </Switch>
23
- </CheckPagePermissions>
24
- );
25
- };
26
-
27
- export default Roles;
@@ -1,5 +0,0 @@
1
- import pluginId from '../pluginId';
2
-
3
- const getRequestURL = (endPoint) => `/${pluginId}/${endPoint}`;
4
-
5
- export default getRequestURL;