@strapi/plugin-users-permissions 4.12.7 → 4.13.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/admin/src/components/Permissions/index.js +2 -4
  2. package/admin/src/index.js +7 -8
  3. package/admin/src/pages/AdvancedSettings/index.js +41 -24
  4. package/admin/src/pages/EmailTemplates/index.js +62 -47
  5. package/admin/src/pages/Providers/index.js +64 -58
  6. package/admin/src/{hooks → pages/Roles/hooks}/usePlugins.js +15 -8
  7. package/admin/src/pages/Roles/index.js +10 -7
  8. package/admin/src/pages/Roles/pages/CreatePage.js +190 -0
  9. package/admin/src/pages/Roles/pages/EditPage.js +211 -0
  10. package/admin/src/pages/Roles/{ListPage → pages/ListPage}/components/TableBody.js +41 -11
  11. package/admin/src/pages/Roles/{ListPage → pages/ListPage}/index.js +19 -15
  12. package/jest.config.front.js +1 -1
  13. package/package.json +4 -4
  14. package/server/bootstrap/index.js +35 -0
  15. package/server/controllers/auth.js +46 -13
  16. package/server/controllers/user.js +12 -1
  17. package/admin/src/hooks/index.js +0 -5
  18. package/admin/src/hooks/useFetchRole/index.js +0 -67
  19. package/admin/src/hooks/useFetchRole/reducer.js +0 -31
  20. package/admin/src/hooks/useForm/index.js +0 -68
  21. package/admin/src/hooks/useForm/reducer.js +0 -40
  22. package/admin/src/hooks/useRolesList/index.js +0 -65
  23. package/admin/src/hooks/useRolesList/init.js +0 -5
  24. package/admin/src/hooks/useRolesList/reducer.js +0 -31
  25. package/admin/src/pages/AdvancedSettings/utils/api.js +0 -16
  26. package/admin/src/pages/EmailTemplates/utils/api.js +0 -16
  27. package/admin/src/pages/Providers/reducer.js +0 -54
  28. package/admin/src/pages/Providers/utils/api.js +0 -24
  29. package/admin/src/pages/Providers/utils/createProvidersArray.js +0 -21
  30. package/admin/src/pages/Roles/CreatePage.js +0 -185
  31. package/admin/src/pages/Roles/EditPage.js +0 -197
  32. package/admin/src/pages/Roles/ProtectedCreatePage.js +0 -15
  33. package/admin/src/pages/Roles/ProtectedEditPage.js +0 -15
  34. package/admin/src/pages/Roles/ProtectedListPage.js +0 -17
  35. /package/admin/src/pages/Roles/{ListPage → pages/ListPage}/utils/api.js +0 -0
@@ -1,185 +0,0 @@
1
- import React, { useRef, useState } from 'react';
2
-
3
- import {
4
- Box,
5
- Button,
6
- ContentLayout,
7
- Flex,
8
- Grid,
9
- GridItem,
10
- HeaderLayout,
11
- Main,
12
- Textarea,
13
- TextInput,
14
- Typography,
15
- } from '@strapi/design-system';
16
- import {
17
- Form,
18
- SettingsPageTitle,
19
- useFetchClient,
20
- useNotification,
21
- useOverlayBlocker,
22
- useTracking,
23
- } from '@strapi/helper-plugin';
24
- import { Check } from '@strapi/icons';
25
- import { Formik } from 'formik';
26
- import { useIntl } from 'react-intl';
27
- import { useHistory } from 'react-router-dom';
28
-
29
- import UsersPermissions from '../../components/UsersPermissions';
30
- import { usePlugins } from '../../hooks';
31
- import pluginId from '../../pluginId';
32
- import getTrad from '../../utils/getTrad';
33
-
34
- import { createRoleSchema } from './constants';
35
-
36
- const CreatePage = () => {
37
- const { formatMessage } = useIntl();
38
- const [isSubmitting, setIsSubmitting] = useState(false);
39
- const toggleNotification = useNotification();
40
- const { goBack } = useHistory();
41
- const { lockApp, unlockApp } = useOverlayBlocker();
42
- const { isLoading: isLoadingPlugins, permissions, routes } = usePlugins();
43
- const { trackUsage } = useTracking();
44
- const permissionsRef = useRef();
45
- const { post } = useFetchClient();
46
-
47
- const handleCreateRoleSubmit = 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 post(`/${pluginId}/roles`, { ...data, ...permissions, users: [] });
55
- // Notify success
56
- trackUsage('didCreateRole');
57
- toggleNotification({
58
- type: 'success',
59
- message: {
60
- id: getTrad('Settings.roles.created'),
61
- defaultMessage: 'Role created',
62
- },
63
- });
64
- // Forcing redirecting since we don't have the id in the response
65
- goBack();
66
- } catch (err) {
67
- console.error(err);
68
- toggleNotification({
69
- type: 'warning',
70
- message: {
71
- id: 'notification.error',
72
- defaultMessage: 'An error occurred',
73
- },
74
- });
75
- }
76
- // Unset loading state
77
- setIsSubmitting(false);
78
- unlockApp();
79
- };
80
-
81
- return (
82
- <Main>
83
- <SettingsPageTitle name="Roles" />
84
- <Formik
85
- enableReinitialize
86
- initialValues={{ name: '', description: '' }}
87
- onSubmit={handleCreateRoleSubmit}
88
- validationSchema={createRoleSchema}
89
- >
90
- {({ handleSubmit, values, handleChange, errors }) => (
91
- <Form noValidate onSubmit={handleSubmit}>
92
- <HeaderLayout
93
- primaryAction={
94
- !isLoadingPlugins && (
95
- <Button type="submit" loading={isSubmitting} startIcon={<Check />}>
96
- {formatMessage({
97
- id: 'global.save',
98
- defaultMessage: 'Save',
99
- })}
100
- </Button>
101
- )
102
- }
103
- title={formatMessage({
104
- id: 'Settings.roles.create.title',
105
- defaultMessage: 'Create a role',
106
- })}
107
- subtitle={formatMessage({
108
- id: 'Settings.roles.create.description',
109
- defaultMessage: 'Define the rights given to the role',
110
- })}
111
- />
112
- <ContentLayout>
113
- <Flex direction="column" alignItems="stretch" gap={7}>
114
- <Box
115
- background="neutral0"
116
- hasRadius
117
- shadow="filterShadow"
118
- paddingTop={6}
119
- paddingBottom={6}
120
- paddingLeft={7}
121
- paddingRight={7}
122
- >
123
- <Flex direction="column" alignItems="stretch" gap={4}>
124
- <Typography variant="delta" as="h2">
125
- {formatMessage({
126
- id: getTrad('EditPage.form.roles'),
127
- defaultMessage: 'Role details',
128
- })}
129
- </Typography>
130
- <Grid gap={4}>
131
- <GridItem col={6}>
132
- <TextInput
133
- name="name"
134
- value={values.name || ''}
135
- onChange={handleChange}
136
- label={formatMessage({
137
- id: 'global.name',
138
- defaultMessage: 'Name',
139
- })}
140
- error={
141
- errors.name
142
- ? formatMessage({ id: errors.name, defaultMessage: 'Invalid value' })
143
- : null
144
- }
145
- />
146
- </GridItem>
147
- <GridItem col={6}>
148
- <Textarea
149
- id="description"
150
- value={values.description || ''}
151
- onChange={handleChange}
152
- label={formatMessage({
153
- id: 'global.description',
154
- defaultMessage: 'Description',
155
- })}
156
- error={
157
- errors.description
158
- ? formatMessage({
159
- id: errors.description,
160
- defaultMessage: 'Invalid value',
161
- })
162
- : null
163
- }
164
- />
165
- </GridItem>
166
- </Grid>
167
- </Flex>
168
- </Box>
169
- {!isLoadingPlugins && (
170
- <UsersPermissions
171
- ref={permissionsRef}
172
- permissions={permissions}
173
- routes={routes}
174
- />
175
- )}
176
- </Flex>
177
- </ContentLayout>
178
- </Form>
179
- )}
180
- </Formik>
181
- </Main>
182
- );
183
- };
184
-
185
- export default CreatePage;
@@ -1,197 +0,0 @@
1
- import React, { useRef, useState } from 'react';
2
-
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 {
17
- useFetchClient,
18
- useOverlayBlocker,
19
- SettingsPageTitle,
20
- LoadingIndicatorPage,
21
- Form,
22
- useNotification,
23
- Link,
24
- } from '@strapi/helper-plugin';
25
- import { ArrowLeft, Check } from '@strapi/icons';
26
- import { Formik } from 'formik';
27
- import { useIntl } from 'react-intl';
28
- import { useRouteMatch } from 'react-router-dom';
29
-
30
- import UsersPermissions from '../../components/UsersPermissions';
31
- import { usePlugins, useFetchRole } from '../../hooks';
32
- import pluginId from '../../pluginId';
33
- import getTrad from '../../utils/getTrad';
34
-
35
- import { createRoleSchema } from './constants';
36
-
37
- const EditPage = () => {
38
- const { formatMessage } = useIntl();
39
- const [isSubmitting, setIsSubmitting] = useState(false);
40
- const toggleNotification = useNotification();
41
- const { lockApp, unlockApp } = useOverlayBlocker();
42
- const {
43
- params: { id },
44
- } = useRouteMatch(`/settings/${pluginId}/roles/:id`);
45
- const { isLoading: isLoadingPlugins, routes } = usePlugins();
46
- const { role, onSubmitSucceeded, isLoading: isLoadingRole } = useFetchRole(id);
47
- const permissionsRef = useRef();
48
- const { put } = useFetchClient();
49
-
50
- const handleEditRoleSubmit = async (data) => {
51
- // Set loading state
52
- lockApp();
53
- setIsSubmitting(true);
54
- try {
55
- const permissions = permissionsRef.current.getPermissions();
56
- // Update role in Strapi
57
- await put(`/${pluginId}/roles/${id}`, { ...data, ...permissions, users: [] });
58
- // Notify success
59
- onSubmitSucceeded({ name: data.name, description: data.description });
60
- toggleNotification({
61
- type: 'success',
62
- message: {
63
- id: getTrad('Settings.roles.edited'),
64
- defaultMessage: 'Role edited',
65
- },
66
- });
67
- } catch (err) {
68
- console.error(err);
69
- toggleNotification({
70
- type: 'warning',
71
- message: {
72
- id: 'notification.error',
73
- defaultMessage: 'An error occurred',
74
- },
75
- });
76
- }
77
- // Unset loading state
78
- setIsSubmitting(false);
79
- unlockApp();
80
- };
81
-
82
- if (isLoadingRole) {
83
- return <LoadingIndicatorPage />;
84
- }
85
-
86
- return (
87
- <Main>
88
- <SettingsPageTitle name="Roles" />
89
- <Formik
90
- enableReinitialize
91
- initialValues={{ name: role.name, description: role.description }}
92
- onSubmit={handleEditRoleSubmit}
93
- validationSchema={createRoleSchema}
94
- >
95
- {({ handleSubmit, values, handleChange, errors }) => (
96
- <Form noValidate onSubmit={handleSubmit}>
97
- <HeaderLayout
98
- primaryAction={
99
- !isLoadingPlugins && (
100
- <Button
101
- disabled={role.code === 'strapi-super-admin'}
102
- type="submit"
103
- loading={isSubmitting}
104
- startIcon={<Check />}
105
- >
106
- {formatMessage({
107
- id: 'global.save',
108
- defaultMessage: 'Save',
109
- })}
110
- </Button>
111
- )
112
- }
113
- title={role.name}
114
- subtitle={role.description}
115
- navigationAction={
116
- <Link startIcon={<ArrowLeft />} to="/settings/users-permissions/roles">
117
- {formatMessage({
118
- id: 'global.back',
119
- defaultMessage: 'Back',
120
- })}
121
- </Link>
122
- }
123
- />
124
- <ContentLayout>
125
- <Flex direction="column" alignItems="stretch" gap={7}>
126
- <Box
127
- background="neutral0"
128
- hasRadius
129
- shadow="filterShadow"
130
- paddingTop={6}
131
- paddingBottom={6}
132
- paddingLeft={7}
133
- paddingRight={7}
134
- >
135
- <Flex direction="column" alignItems="stretch" gap={4}>
136
- <Typography variant="delta" as="h2">
137
- {formatMessage({
138
- id: getTrad('EditPage.form.roles'),
139
- defaultMessage: 'Role details',
140
- })}
141
- </Typography>
142
- <Grid gap={4}>
143
- <GridItem col={6}>
144
- <TextInput
145
- name="name"
146
- value={values.name || ''}
147
- onChange={handleChange}
148
- label={formatMessage({
149
- id: 'global.name',
150
- defaultMessage: 'Name',
151
- })}
152
- error={
153
- errors.name
154
- ? formatMessage({ id: errors.name, defaultMessage: 'Invalid value' })
155
- : null
156
- }
157
- />
158
- </GridItem>
159
- <GridItem col={6}>
160
- <Textarea
161
- id="description"
162
- value={values.description || ''}
163
- onChange={handleChange}
164
- label={formatMessage({
165
- id: 'global.description',
166
- defaultMessage: 'Description',
167
- })}
168
- error={
169
- errors.description
170
- ? formatMessage({
171
- id: errors.description,
172
- defaultMessage: 'Invalid value',
173
- })
174
- : null
175
- }
176
- />
177
- </GridItem>
178
- </Grid>
179
- </Flex>
180
- </Box>
181
- {!isLoadingPlugins && (
182
- <UsersPermissions
183
- ref={permissionsRef}
184
- permissions={role.permissions}
185
- routes={routes}
186
- />
187
- )}
188
- </Flex>
189
- </ContentLayout>
190
- </Form>
191
- )}
192
- </Formik>
193
- </Main>
194
- );
195
- };
196
-
197
- export default EditPage;
@@ -1,15 +0,0 @@
1
- import React from 'react';
2
-
3
- import { CheckPagePermissions } from '@strapi/helper-plugin';
4
-
5
- import { PERMISSIONS } from '../../constants';
6
-
7
- import RolesCreatePage from './CreatePage';
8
-
9
- const ProtectedRolesCreatePage = () => (
10
- <CheckPagePermissions permissions={PERMISSIONS.createRole}>
11
- <RolesCreatePage />
12
- </CheckPagePermissions>
13
- );
14
-
15
- export default ProtectedRolesCreatePage;
@@ -1,15 +0,0 @@
1
- import React from 'react';
2
-
3
- import { CheckPagePermissions } from '@strapi/helper-plugin';
4
-
5
- import { PERMISSIONS } from '../../constants';
6
-
7
- import RolesEditPage from './EditPage';
8
-
9
- const ProtectedRolesEditPage = () => (
10
- <CheckPagePermissions permissions={PERMISSIONS.updateRole}>
11
- <RolesEditPage />
12
- </CheckPagePermissions>
13
- );
14
-
15
- export default ProtectedRolesEditPage;
@@ -1,17 +0,0 @@
1
- import React from 'react';
2
-
3
- import { CheckPagePermissions } from '@strapi/helper-plugin';
4
-
5
- import { PERMISSIONS } from '../../constants';
6
-
7
- import RolesListPage from './ListPage';
8
-
9
- const ProtectedRolesListPage = () => {
10
- return (
11
- <CheckPagePermissions permissions={PERMISSIONS.accessRoles}>
12
- <RolesListPage />
13
- </CheckPagePermissions>
14
- );
15
- };
16
-
17
- export default ProtectedRolesListPage;