@strapi/plugin-users-permissions 4.12.6 → 4.12.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/admin/src/components/Permissions/index.js +4 -2
- package/admin/src/hooks/index.js +5 -0
- package/admin/src/hooks/useFetchRole/index.js +67 -0
- package/admin/src/hooks/useFetchRole/reducer.js +31 -0
- package/admin/src/hooks/useForm/index.js +68 -0
- package/admin/src/hooks/useForm/reducer.js +40 -0
- package/admin/src/{pages/Roles/hooks → hooks}/usePlugins.js +8 -15
- package/admin/src/hooks/useRolesList/index.js +65 -0
- package/admin/src/hooks/useRolesList/init.js +5 -0
- package/admin/src/hooks/useRolesList/reducer.js +31 -0
- package/admin/src/index.js +8 -7
- package/admin/src/pages/AdvancedSettings/index.js +24 -41
- package/admin/src/pages/AdvancedSettings/utils/api.js +16 -0
- package/admin/src/pages/EmailTemplates/index.js +47 -62
- package/admin/src/pages/EmailTemplates/utils/api.js +16 -0
- package/admin/src/pages/Providers/index.js +58 -64
- package/admin/src/pages/Providers/reducer.js +54 -0
- package/admin/src/pages/Providers/utils/api.js +24 -0
- package/admin/src/pages/Providers/utils/createProvidersArray.js +21 -0
- package/admin/src/pages/Roles/CreatePage.js +185 -0
- package/admin/src/pages/Roles/EditPage.js +197 -0
- package/admin/src/pages/Roles/{pages/ListPage → ListPage}/components/TableBody.js +11 -41
- package/admin/src/pages/Roles/{pages/ListPage → ListPage}/index.js +15 -19
- package/admin/src/pages/Roles/ProtectedCreatePage.js +15 -0
- package/admin/src/pages/Roles/ProtectedEditPage.js +15 -0
- package/admin/src/pages/Roles/ProtectedListPage.js +17 -0
- package/admin/src/pages/Roles/index.js +7 -10
- package/jest.config.front.js +1 -1
- package/package.json +4 -4
- package/admin/src/pages/Roles/pages/CreatePage.js +0 -190
- package/admin/src/pages/Roles/pages/EditPage.js +0 -211
- /package/admin/src/pages/Roles/{pages/ListPage → ListPage}/utils/api.js +0 -0
|
@@ -0,0 +1,197 @@
|
|
|
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,39 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { Flex, IconButton,
|
|
4
|
-
import { CheckPermissions, onRowClick,
|
|
3
|
+
import { Flex, IconButton, Tbody, Td, Tr, Typography } from '@strapi/design-system';
|
|
4
|
+
import { CheckPermissions, onRowClick, stopPropagation } from '@strapi/helper-plugin';
|
|
5
5
|
import { Pencil, Trash } from '@strapi/icons';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
7
|
import { useIntl } from 'react-intl';
|
|
8
8
|
import { useHistory } from 'react-router-dom';
|
|
9
|
-
import styled from 'styled-components';
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
align-items: center;
|
|
13
|
-
height: ${pxToRem(32)};
|
|
14
|
-
display: flex;
|
|
15
|
-
justify-content: center;
|
|
16
|
-
padding: ${({ theme }) => `${theme.spaces[2]}}`};
|
|
17
|
-
width: ${pxToRem(32)};
|
|
18
|
-
|
|
19
|
-
svg {
|
|
20
|
-
height: ${pxToRem(12)};
|
|
21
|
-
width: ${pxToRem(12)};
|
|
22
|
-
|
|
23
|
-
path {
|
|
24
|
-
fill: ${({ theme }) => theme.colors.neutral500};
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
&:hover,
|
|
29
|
-
&:focus {
|
|
30
|
-
svg {
|
|
31
|
-
path {
|
|
32
|
-
fill: ${({ theme }) => theme.colors.neutral800};
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
`;
|
|
10
|
+
import pluginId from '../../../../pluginId';
|
|
37
11
|
|
|
38
12
|
const TableBody = ({ sortedRoles, canDelete, permissions, setRoleToDelete, onDelete }) => {
|
|
39
13
|
const { formatMessage } = useIntl();
|
|
@@ -49,7 +23,7 @@ const TableBody = ({ sortedRoles, canDelete, permissions, setRoleToDelete, onDel
|
|
|
49
23
|
};
|
|
50
24
|
|
|
51
25
|
const handleClickEdit = (id) => {
|
|
52
|
-
push(`/settings/
|
|
26
|
+
push(`/settings/${pluginId}/roles/${id}`);
|
|
53
27
|
};
|
|
54
28
|
|
|
55
29
|
return (
|
|
@@ -65,10 +39,7 @@ const TableBody = ({ sortedRoles, canDelete, permissions, setRoleToDelete, onDel
|
|
|
65
39
|
<Td width="30%">
|
|
66
40
|
<Typography>
|
|
67
41
|
{formatMessage(
|
|
68
|
-
{
|
|
69
|
-
id: 'Roles.RoleRow.user-count',
|
|
70
|
-
defaultMessage: '{number, plural, =0 {# user} one {# user} other {# users}}',
|
|
71
|
-
},
|
|
42
|
+
{ id: 'Roles.RoleRow.user-count', defaultMessage: '{number, plural, =0 {# user} one {# user} other {# users}}' },
|
|
72
43
|
{ number: role.nb_users }
|
|
73
44
|
)}
|
|
74
45
|
</Typography>
|
|
@@ -76,17 +47,16 @@ const TableBody = ({ sortedRoles, canDelete, permissions, setRoleToDelete, onDel
|
|
|
76
47
|
<Td>
|
|
77
48
|
<Flex justifyContent="end" {...stopPropagation}>
|
|
78
49
|
<CheckPermissions permissions={permissions.updateRole}>
|
|
79
|
-
<
|
|
80
|
-
|
|
81
|
-
|
|
50
|
+
<IconButton
|
|
51
|
+
onClick={() => handleClickEdit(role.id)}
|
|
52
|
+
noBorder
|
|
53
|
+
icon={<Pencil />}
|
|
54
|
+
label={formatMessage(
|
|
82
55
|
{ id: 'app.component.table.edit', defaultMessage: 'Edit {target}' },
|
|
83
56
|
{ target: `${role.name}` }
|
|
84
57
|
)}
|
|
85
|
-
|
|
86
|
-
<Pencil />
|
|
87
|
-
</EditLink>
|
|
58
|
+
/>
|
|
88
59
|
</CheckPermissions>
|
|
89
|
-
|
|
90
60
|
{checkCanDeleteRole(role) && (
|
|
91
61
|
<CheckPermissions permissions={permissions.deleteRole}>
|
|
92
62
|
<IconButton
|
|
@@ -2,6 +2,7 @@ import React, { useState } from 'react';
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
ActionLayout,
|
|
5
|
+
Button,
|
|
5
6
|
ContentLayout,
|
|
6
7
|
HeaderLayout,
|
|
7
8
|
Layout,
|
|
@@ -15,11 +16,9 @@ import {
|
|
|
15
16
|
VisuallyHidden,
|
|
16
17
|
} from '@strapi/design-system';
|
|
17
18
|
import {
|
|
18
|
-
CheckPagePermissions,
|
|
19
19
|
CheckPermissions,
|
|
20
20
|
ConfirmDialog,
|
|
21
21
|
EmptyStateLayout,
|
|
22
|
-
LinkButton,
|
|
23
22
|
LoadingIndicatorPage,
|
|
24
23
|
NoPermissions,
|
|
25
24
|
SearchURLQuery,
|
|
@@ -35,16 +34,19 @@ import {
|
|
|
35
34
|
import { Plus } from '@strapi/icons';
|
|
36
35
|
import { useIntl } from 'react-intl';
|
|
37
36
|
import { useMutation, useQuery } from 'react-query';
|
|
37
|
+
import { useHistory } from 'react-router-dom';
|
|
38
38
|
|
|
39
|
-
import { PERMISSIONS } from '
|
|
40
|
-
import
|
|
39
|
+
import { PERMISSIONS } from '../../../constants';
|
|
40
|
+
import pluginId from '../../../pluginId';
|
|
41
|
+
import { getTrad } from '../../../utils';
|
|
41
42
|
|
|
42
43
|
import TableBody from './components/TableBody';
|
|
43
44
|
import { deleteData, fetchData } from './utils/api';
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
const RoleListPage = () => {
|
|
46
47
|
const { trackUsage } = useTracking();
|
|
47
48
|
const { formatMessage, locale } = useIntl();
|
|
49
|
+
const { push } = useHistory();
|
|
48
50
|
const toggleNotification = useNotification();
|
|
49
51
|
const { notifyStatus } = useNotifyAT();
|
|
50
52
|
const [{ query }] = useQueryParams();
|
|
@@ -87,6 +89,11 @@ export const RolesListPage = () => {
|
|
|
87
89
|
|
|
88
90
|
const isLoading = isLoadingForData || isFetching;
|
|
89
91
|
|
|
92
|
+
const handleNewRoleClick = () => {
|
|
93
|
+
trackUsage('willCreateRole');
|
|
94
|
+
push(`/settings/${pluginId}/roles/new`);
|
|
95
|
+
};
|
|
96
|
+
|
|
90
97
|
const handleShowConfirmDelete = () => {
|
|
91
98
|
setShowConfirmDelete(!showConfirmDelete);
|
|
92
99
|
};
|
|
@@ -146,17 +153,12 @@ export const RolesListPage = () => {
|
|
|
146
153
|
})}
|
|
147
154
|
primaryAction={
|
|
148
155
|
<CheckPermissions permissions={PERMISSIONS.createRole}>
|
|
149
|
-
<
|
|
150
|
-
to="/settings/users-permissions/roles/new"
|
|
151
|
-
onClick={() => trackUsage('willCreateRole')}
|
|
152
|
-
startIcon={<Plus />}
|
|
153
|
-
size="S"
|
|
154
|
-
>
|
|
156
|
+
<Button onClick={handleNewRoleClick} startIcon={<Plus />} size="S">
|
|
155
157
|
{formatMessage({
|
|
156
158
|
id: getTrad('List.button.roles'),
|
|
157
159
|
defaultMessage: 'Add new role',
|
|
158
160
|
})}
|
|
159
|
-
</
|
|
161
|
+
</Button>
|
|
160
162
|
</CheckPermissions>
|
|
161
163
|
}
|
|
162
164
|
/>
|
|
@@ -233,10 +235,4 @@ export const RolesListPage = () => {
|
|
|
233
235
|
);
|
|
234
236
|
};
|
|
235
237
|
|
|
236
|
-
export
|
|
237
|
-
return (
|
|
238
|
-
<CheckPagePermissions permissions={PERMISSIONS.accessRoles}>
|
|
239
|
-
<RolesListPage />
|
|
240
|
-
</CheckPagePermissions>
|
|
241
|
-
);
|
|
242
|
-
};
|
|
238
|
+
export default RoleListPage;
|
|
@@ -0,0 +1,15 @@
|
|
|
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;
|
|
@@ -0,0 +1,15 @@
|
|
|
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;
|
|
@@ -0,0 +1,17 @@
|
|
|
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;
|
|
@@ -4,26 +4,23 @@ import { AnErrorOccurred, CheckPagePermissions } from '@strapi/helper-plugin';
|
|
|
4
4
|
import { Route, Switch } from 'react-router-dom';
|
|
5
5
|
|
|
6
6
|
import { PERMISSIONS } from '../../constants';
|
|
7
|
+
import pluginId from '../../pluginId';
|
|
7
8
|
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
9
|
+
import ProtectedRolesCreatePage from './ProtectedCreatePage';
|
|
10
|
+
import ProtectedRolesEditPage from './ProtectedEditPage';
|
|
11
|
+
import ProtectedRolesListPage from './ProtectedListPage';
|
|
11
12
|
|
|
12
13
|
const Roles = () => {
|
|
13
14
|
return (
|
|
14
15
|
<CheckPagePermissions permissions={PERMISSIONS.accessRoles}>
|
|
15
16
|
<Switch>
|
|
16
17
|
<Route
|
|
17
|
-
path=
|
|
18
|
+
path={`/settings/${pluginId}/roles/new`}
|
|
18
19
|
component={ProtectedRolesCreatePage}
|
|
19
20
|
exact
|
|
20
21
|
/>
|
|
21
|
-
<Route
|
|
22
|
-
|
|
23
|
-
component={ProtectedRolesEditPage}
|
|
24
|
-
exact
|
|
25
|
-
/>
|
|
26
|
-
<Route path="/settings/users-permissions/roles" component={ProtectedRolesListPage} exact />
|
|
22
|
+
<Route path={`/settings/${pluginId}/roles/:id`} component={ProtectedRolesEditPage} exact />
|
|
23
|
+
<Route path={`/settings/${pluginId}/roles`} component={ProtectedRolesListPage} exact />
|
|
27
24
|
<Route path="" component={AnErrorOccurred} />
|
|
28
25
|
</Switch>
|
|
29
26
|
</CheckPagePermissions>
|
package/jest.config.front.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/plugin-users-permissions",
|
|
3
|
-
"version": "4.12.
|
|
3
|
+
"version": "4.12.7",
|
|
4
4
|
"description": "Protect your API with a full-authentication process based on JWT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@strapi/design-system": "1.9.0",
|
|
33
|
-
"@strapi/helper-plugin": "4.12.
|
|
33
|
+
"@strapi/helper-plugin": "4.12.7",
|
|
34
34
|
"@strapi/icons": "1.9.0",
|
|
35
|
-
"@strapi/utils": "4.12.
|
|
35
|
+
"@strapi/utils": "4.12.7",
|
|
36
36
|
"bcryptjs": "2.4.3",
|
|
37
37
|
"formik": "2.4.0",
|
|
38
38
|
"grant-koa": "5.4.8",
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"required": true,
|
|
78
78
|
"kind": "plugin"
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "fefc4a24acc60a59c00049e67a99ec1069be2add"
|
|
81
81
|
}
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
Button,
|
|
5
|
-
ContentLayout,
|
|
6
|
-
Flex,
|
|
7
|
-
Grid,
|
|
8
|
-
GridItem,
|
|
9
|
-
HeaderLayout,
|
|
10
|
-
Main,
|
|
11
|
-
Textarea,
|
|
12
|
-
TextInput,
|
|
13
|
-
Typography,
|
|
14
|
-
} from '@strapi/design-system';
|
|
15
|
-
import {
|
|
16
|
-
CheckPagePermissions,
|
|
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 { useMutation } from 'react-query';
|
|
28
|
-
import { useHistory } from 'react-router-dom';
|
|
29
|
-
|
|
30
|
-
import UsersPermissions from '../../../components/UsersPermissions';
|
|
31
|
-
import { PERMISSIONS } from '../../../constants';
|
|
32
|
-
import getTrad from '../../../utils/getTrad';
|
|
33
|
-
import { createRoleSchema } from '../constants';
|
|
34
|
-
import { usePlugins } from '../hooks/usePlugins';
|
|
35
|
-
|
|
36
|
-
export const CreatePage = () => {
|
|
37
|
-
const { formatMessage } = useIntl();
|
|
38
|
-
const toggleNotification = useNotification();
|
|
39
|
-
const { goBack } = useHistory();
|
|
40
|
-
const { lockApp, unlockApp } = useOverlayBlocker();
|
|
41
|
-
const { isLoading: isLoadingPlugins, permissions, routes } = usePlugins();
|
|
42
|
-
const { trackUsage } = useTracking();
|
|
43
|
-
const permissionsRef = React.useRef();
|
|
44
|
-
const { post } = useFetchClient();
|
|
45
|
-
const mutation = useMutation((body) => post(`/users-permissions/roles`, body), {
|
|
46
|
-
onError() {
|
|
47
|
-
toggleNotification({
|
|
48
|
-
type: 'warning',
|
|
49
|
-
message: {
|
|
50
|
-
id: 'notification.error',
|
|
51
|
-
defaultMessage: 'An error occurred',
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
onSuccess() {
|
|
57
|
-
trackUsage('didCreateRole');
|
|
58
|
-
|
|
59
|
-
toggleNotification({
|
|
60
|
-
type: 'success',
|
|
61
|
-
message: {
|
|
62
|
-
id: getTrad('Settings.roles.created'),
|
|
63
|
-
defaultMessage: 'Role created',
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// Forcing redirecting since we don't have the id in the response
|
|
68
|
-
goBack();
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
const handleCreateRoleSubmit = async (data) => {
|
|
73
|
-
lockApp();
|
|
74
|
-
|
|
75
|
-
// TODO: refactor. Child -> parent component communication is evil;
|
|
76
|
-
// We should either move the provider one level up or move the state
|
|
77
|
-
// straight into redux.
|
|
78
|
-
const permissions = permissionsRef.current.getPermissions();
|
|
79
|
-
|
|
80
|
-
await mutation.mutate({ ...data, ...permissions, users: [] });
|
|
81
|
-
|
|
82
|
-
unlockApp();
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
return (
|
|
86
|
-
<Main>
|
|
87
|
-
{/* TODO: This needs to be translated */}
|
|
88
|
-
<SettingsPageTitle name="Roles" />
|
|
89
|
-
<Formik
|
|
90
|
-
enableReinitialize
|
|
91
|
-
initialValues={{ name: '', description: '' }}
|
|
92
|
-
onSubmit={handleCreateRoleSubmit}
|
|
93
|
-
validationSchema={createRoleSchema}
|
|
94
|
-
>
|
|
95
|
-
{({ handleSubmit, values, handleChange, errors }) => (
|
|
96
|
-
<Form noValidate onSubmit={handleSubmit}>
|
|
97
|
-
<HeaderLayout
|
|
98
|
-
primaryAction={
|
|
99
|
-
!isLoadingPlugins && (
|
|
100
|
-
<Button type="submit" loading={mutation.isLoading} startIcon={<Check />}>
|
|
101
|
-
{formatMessage({
|
|
102
|
-
id: 'global.save',
|
|
103
|
-
defaultMessage: 'Save',
|
|
104
|
-
})}
|
|
105
|
-
</Button>
|
|
106
|
-
)
|
|
107
|
-
}
|
|
108
|
-
title={formatMessage({
|
|
109
|
-
id: 'Settings.roles.create.title',
|
|
110
|
-
defaultMessage: 'Create a role',
|
|
111
|
-
})}
|
|
112
|
-
subtitle={formatMessage({
|
|
113
|
-
id: 'Settings.roles.create.description',
|
|
114
|
-
defaultMessage: 'Define the rights given to the role',
|
|
115
|
-
})}
|
|
116
|
-
/>
|
|
117
|
-
<ContentLayout>
|
|
118
|
-
<Flex
|
|
119
|
-
background="neutral0"
|
|
120
|
-
direction="column"
|
|
121
|
-
alignItems="stretch"
|
|
122
|
-
gap={7}
|
|
123
|
-
hasRadius
|
|
124
|
-
paddingTop={6}
|
|
125
|
-
paddingBottom={6}
|
|
126
|
-
paddingLeft={7}
|
|
127
|
-
paddingRight={7}
|
|
128
|
-
shadow="filterShadow"
|
|
129
|
-
>
|
|
130
|
-
<Flex direction="column" alignItems="stretch">
|
|
131
|
-
<Typography variant="delta" as="h2">
|
|
132
|
-
{formatMessage({
|
|
133
|
-
id: getTrad('EditPage.form.roles'),
|
|
134
|
-
defaultMessage: 'Role details',
|
|
135
|
-
})}
|
|
136
|
-
</Typography>
|
|
137
|
-
|
|
138
|
-
<Grid gap={4}>
|
|
139
|
-
<GridItem col={6}>
|
|
140
|
-
<TextInput
|
|
141
|
-
name="name"
|
|
142
|
-
value={values.name || ''}
|
|
143
|
-
onChange={handleChange}
|
|
144
|
-
label={formatMessage({
|
|
145
|
-
id: 'global.name',
|
|
146
|
-
defaultMessage: 'Name',
|
|
147
|
-
})}
|
|
148
|
-
error={errors?.name ? formatMessage({ id: errors.name }) : false}
|
|
149
|
-
required
|
|
150
|
-
/>
|
|
151
|
-
</GridItem>
|
|
152
|
-
<GridItem col={6}>
|
|
153
|
-
<Textarea
|
|
154
|
-
id="description"
|
|
155
|
-
value={values.description || ''}
|
|
156
|
-
onChange={handleChange}
|
|
157
|
-
label={formatMessage({
|
|
158
|
-
id: 'global.description',
|
|
159
|
-
defaultMessage: 'Description',
|
|
160
|
-
})}
|
|
161
|
-
error={
|
|
162
|
-
errors?.description ? formatMessage({ id: errors.description }) : false
|
|
163
|
-
}
|
|
164
|
-
required
|
|
165
|
-
/>
|
|
166
|
-
</GridItem>
|
|
167
|
-
</Grid>
|
|
168
|
-
</Flex>
|
|
169
|
-
|
|
170
|
-
{!isLoadingPlugins && (
|
|
171
|
-
<UsersPermissions
|
|
172
|
-
ref={permissionsRef}
|
|
173
|
-
permissions={permissions}
|
|
174
|
-
routes={routes}
|
|
175
|
-
/>
|
|
176
|
-
)}
|
|
177
|
-
</Flex>
|
|
178
|
-
</ContentLayout>
|
|
179
|
-
</Form>
|
|
180
|
-
)}
|
|
181
|
-
</Formik>
|
|
182
|
-
</Main>
|
|
183
|
-
);
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
export const ProtectedRolesCreatePage = () => (
|
|
187
|
-
<CheckPagePermissions permissions={PERMISSIONS.createRole}>
|
|
188
|
-
<CreatePage />
|
|
189
|
-
</CheckPagePermissions>
|
|
190
|
-
);
|