@strapi/plugin-users-permissions 4.0.0-next.7 → 4.0.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.
- package/admin/src/components/BoundRoute/getMethodColor.js +41 -0
- package/admin/src/components/BoundRoute/index.js +40 -24
- package/admin/src/components/FormModal/Input/index.js +121 -0
- package/admin/src/components/FormModal/index.js +123 -0
- package/admin/src/components/Permissions/PermissionRow/CheckboxWrapper.js +19 -26
- package/admin/src/components/Permissions/PermissionRow/SubCategory.js +118 -0
- package/admin/src/components/Permissions/PermissionRow/index.js +9 -48
- package/admin/src/components/Permissions/index.js +36 -24
- package/admin/src/components/Permissions/init.js +1 -6
- package/admin/src/components/Policies/index.js +46 -47
- package/admin/src/components/UsersPermissions/index.js +29 -26
- package/admin/src/components/UsersPermissions/init.js +1 -2
- package/admin/src/hooks/useFetchRole/index.js +17 -7
- package/admin/src/hooks/useForm/index.js +3 -29
- package/admin/src/hooks/useForm/reducer.js +2 -21
- package/admin/src/hooks/usePlugins/index.js +12 -21
- package/admin/src/hooks/usePlugins/reducer.js +0 -3
- package/admin/src/index.js +29 -34
- package/admin/src/pages/AdvancedSettings/index.js +210 -193
- package/admin/src/pages/AdvancedSettings/utils/api.js +13 -0
- package/admin/src/pages/AdvancedSettings/utils/layout.js +96 -0
- package/admin/src/pages/AdvancedSettings/utils/schema.js +21 -0
- package/admin/src/pages/EmailTemplates/components/EmailForm.js +173 -0
- package/admin/src/pages/EmailTemplates/components/EmailTable.js +116 -0
- package/admin/src/pages/EmailTemplates/index.js +125 -198
- package/admin/src/pages/EmailTemplates/utils/api.js +13 -0
- package/admin/src/pages/Providers/index.js +208 -216
- package/admin/src/pages/Providers/utils/api.js +21 -0
- package/admin/src/pages/Providers/utils/forms.js +168 -126
- package/admin/src/pages/Roles/CreatePage/index.js +155 -147
- package/admin/src/pages/Roles/EditPage/index.js +162 -134
- package/admin/src/pages/Roles/ListPage/components/TableBody.js +96 -0
- package/admin/src/pages/Roles/ListPage/index.js +176 -156
- package/admin/src/pages/Roles/ListPage/utils/api.js +28 -0
- package/admin/src/pages/Roles/index.js +14 -8
- package/admin/src/translations/ar.json +0 -8
- package/admin/src/translations/cs.json +0 -8
- package/admin/src/translations/de.json +0 -8
- package/admin/src/translations/dk.json +0 -8
- package/admin/src/translations/en.json +33 -12
- package/admin/src/translations/es.json +0 -8
- package/admin/src/translations/fr.json +0 -8
- package/admin/src/translations/id.json +0 -8
- package/admin/src/translations/it.json +0 -8
- package/admin/src/translations/ja.json +0 -8
- package/admin/src/translations/ko.json +93 -54
- package/admin/src/translations/ms.json +0 -8
- package/admin/src/translations/nl.json +0 -8
- package/admin/src/translations/pl.json +0 -8
- package/admin/src/translations/pt-BR.json +0 -8
- package/admin/src/translations/pt.json +0 -8
- package/admin/src/translations/ru.json +0 -8
- package/admin/src/translations/sk.json +0 -8
- package/admin/src/translations/sv.json +0 -8
- package/admin/src/translations/th.json +0 -8
- package/admin/src/translations/tr.json +0 -8
- package/admin/src/translations/uk.json +0 -8
- package/admin/src/translations/vi.json +0 -8
- package/admin/src/translations/zh-Hans.json +5 -14
- package/admin/src/translations/zh.json +0 -8
- package/admin/src/utils/axiosInstance.js +36 -0
- package/admin/src/utils/formatPluginName.js +26 -0
- package/admin/src/utils/index.js +1 -0
- package/documentation/1.0.0/overrides/users-permissions-Role.json +6 -6
- package/documentation/1.0.0/overrides/users-permissions-User.json +7 -7
- package/jest.config.front.js +10 -0
- package/package.json +35 -32
- package/server/bootstrap/index.js +20 -25
- package/server/config.js +3 -3
- package/server/content-types/index.js +3 -3
- package/server/content-types/permission/index.js +30 -3
- package/server/content-types/role/index.js +47 -3
- package/server/content-types/user/index.js +65 -4
- package/server/controllers/auth.js +85 -237
- package/server/controllers/content-manager-user.js +183 -0
- package/server/controllers/index.js +12 -6
- package/server/controllers/permissions.js +26 -0
- package/server/controllers/role.js +77 -0
- package/server/controllers/settings.js +85 -0
- package/server/controllers/user.js +119 -45
- package/server/controllers/validation/auth.js +29 -0
- package/server/controllers/validation/user.js +38 -0
- package/server/graphql/index.js +44 -0
- package/server/graphql/mutations/auth/email-confirmation.js +39 -0
- package/server/graphql/mutations/auth/forgot-password.js +38 -0
- package/server/graphql/mutations/auth/login.js +38 -0
- package/server/graphql/mutations/auth/register.js +39 -0
- package/server/graphql/mutations/auth/reset-password.js +41 -0
- package/server/graphql/mutations/crud/role/create-role.js +37 -0
- package/server/graphql/mutations/crud/role/delete-role.js +28 -0
- package/server/graphql/mutations/crud/role/update-role.js +38 -0
- package/server/graphql/mutations/crud/user/create-user.js +48 -0
- package/server/graphql/mutations/crud/user/delete-user.js +42 -0
- package/server/graphql/mutations/crud/user/update-user.js +49 -0
- package/server/graphql/mutations/index.js +42 -0
- package/server/graphql/queries/index.js +13 -0
- package/server/graphql/queries/me.js +17 -0
- package/server/graphql/resolvers-configs.js +37 -0
- package/server/graphql/types/create-role-payload.js +11 -0
- package/server/graphql/types/delete-role-payload.js +11 -0
- package/server/graphql/types/index.js +21 -0
- package/server/graphql/types/login-input.js +13 -0
- package/server/graphql/types/login-payload.js +12 -0
- package/server/graphql/types/me-role.js +14 -0
- package/server/graphql/types/me.js +16 -0
- package/server/graphql/types/password-payload.js +11 -0
- package/server/graphql/types/register-input.js +13 -0
- package/server/graphql/types/update-role-payload.js +11 -0
- package/server/graphql/utils.js +27 -0
- package/server/index.js +21 -0
- package/server/middlewares/index.js +2 -2
- package/server/{policies → middlewares}/rateLimit.js +3 -7
- package/server/register.js +11 -0
- package/server/routes/admin/index.js +10 -0
- package/server/routes/admin/permissions.js +20 -0
- package/server/routes/admin/role.js +79 -0
- package/server/routes/admin/settings.js +95 -0
- package/server/routes/content-api/auth.js +73 -0
- package/server/routes/content-api/index.js +11 -0
- package/server/routes/content-api/permissions.js +9 -0
- package/server/routes/content-api/role.js +29 -0
- package/server/routes/content-api/user.js +61 -0
- package/server/routes/index.js +4 -3
- package/server/services/index.js +10 -8
- package/server/services/jwt.js +9 -17
- package/server/services/providers.js +32 -33
- package/server/services/role.js +177 -0
- package/server/services/user.js +9 -15
- package/server/services/users-permissions.js +140 -338
- package/server/strategies/users-permissions.js +123 -0
- package/server/utils/index.d.ts +2 -0
- package/strapi-admin.js +3 -0
- package/strapi-server.js +1 -19
- package/admin/src/assets/images/logo.svg +0 -1
- package/admin/src/components/BaselineAlignement/index.js +0 -33
- package/admin/src/components/Bloc/index.js +0 -10
- package/admin/src/components/BoundRoute/Components.js +0 -78
- package/admin/src/components/ContainerFluid/index.js +0 -13
- package/admin/src/components/FormBloc/index.js +0 -61
- package/admin/src/components/IntlInput/index.js +0 -38
- package/admin/src/components/ListBaselineAlignment/index.js +0 -8
- package/admin/src/components/ListRow/Components.js +0 -74
- package/admin/src/components/ListRow/index.js +0 -35
- package/admin/src/components/ModalForm/Wrapper.js +0 -12
- package/admin/src/components/ModalForm/index.js +0 -59
- package/admin/src/components/Permissions/ListWrapper.js +0 -9
- package/admin/src/components/Permissions/PermissionRow/BaselineAlignment.js +0 -7
- package/admin/src/components/Permissions/PermissionRow/RowStyle.js +0 -28
- package/admin/src/components/Permissions/PermissionRow/SubCategory/ConditionsButtonWrapper.js +0 -13
- package/admin/src/components/Permissions/PermissionRow/SubCategory/PolicyWrapper.js +0 -8
- package/admin/src/components/Permissions/PermissionRow/SubCategory/SubCategoryWrapper.js +0 -26
- package/admin/src/components/Permissions/PermissionRow/SubCategory/index.js +0 -116
- package/admin/src/components/Policies/Components.js +0 -26
- package/admin/src/components/PrefixedIcon/index.js +0 -27
- package/admin/src/components/Roles/EmptyRole/BaselineAlignment.js +0 -7
- package/admin/src/components/Roles/EmptyRole/index.js +0 -27
- package/admin/src/components/Roles/RoleListWrapper/index.js +0 -17
- package/admin/src/components/Roles/RoleRow/RoleDescription.js +0 -9
- package/admin/src/components/Roles/RoleRow/index.js +0 -45
- package/admin/src/components/Roles/index.js +0 -3
- package/admin/src/components/SizedInput/index.js +0 -24
- package/admin/src/pages/AdvancedSettings/reducer.js +0 -65
- package/admin/src/pages/AdvancedSettings/utils/form.js +0 -52
- package/admin/src/pages/EmailTemplates/CustomTextInput.js +0 -105
- package/admin/src/pages/EmailTemplates/Wrapper.js +0 -36
- package/admin/src/pages/EmailTemplates/reducer.js +0 -58
- package/admin/src/pages/EmailTemplates/utils/forms.js +0 -81
- package/admin/src/pages/Roles/ListPage/BaselineAlignment.js +0 -8
- package/server/content-types/permission/schema.json +0 -48
- package/server/content-types/role/schema.json +0 -46
- package/server/content-types/user/schema.json +0 -66
- package/server/controllers/user/admin.js +0 -230
- package/server/controllers/user/api.js +0 -174
- package/server/controllers/users-permissions.js +0 -271
- package/server/middlewares/users-permissions.js +0 -36
- package/server/policies/index.js +0 -11
- package/server/policies/isAuthenticated.js +0 -9
- package/server/policies/permissions.js +0 -94
- package/server/routes/routes.json +0 -381
- package/server/schema.graphql.js +0 -317
|
@@ -1,44 +1,56 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import {
|
|
1
|
+
import React, { useReducer } from 'react';
|
|
2
|
+
import { Accordion, AccordionToggle, AccordionContent } from '@strapi/design-system/Accordion';
|
|
3
|
+
import { useIntl } from 'react-intl';
|
|
4
|
+
import { Box } from '@strapi/design-system/Box';
|
|
5
|
+
import { Stack } from '@strapi/design-system/Stack';
|
|
3
6
|
import { useUsersPermissions } from '../../contexts/UsersPermissionsContext';
|
|
4
|
-
import
|
|
7
|
+
import formatPluginName from '../../utils/formatPluginName';
|
|
5
8
|
import PermissionRow from './PermissionRow';
|
|
6
9
|
import init from './init';
|
|
7
10
|
import { initialState, reducer } from './reducer';
|
|
8
11
|
|
|
9
12
|
const Permissions = () => {
|
|
10
13
|
const { modifiedData } = useUsersPermissions();
|
|
14
|
+
const { formatMessage } = useIntl();
|
|
11
15
|
const [{ collapses }, dispatch] = useReducer(reducer, initialState, state =>
|
|
12
16
|
init(state, modifiedData)
|
|
13
17
|
);
|
|
14
18
|
|
|
15
|
-
const
|
|
19
|
+
const handleToggle = index =>
|
|
16
20
|
dispatch({
|
|
17
21
|
type: 'TOGGLE_COLLAPSE',
|
|
18
22
|
index,
|
|
19
23
|
});
|
|
20
|
-
}, []);
|
|
21
24
|
|
|
22
25
|
return (
|
|
23
|
-
<
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
26
|
+
<Stack size={1}>
|
|
27
|
+
{collapses.map((collapse, index) => (
|
|
28
|
+
<Accordion
|
|
29
|
+
expanded={collapse.isOpen}
|
|
30
|
+
toggle={() => handleToggle(index)}
|
|
31
|
+
key={collapse.name}
|
|
32
|
+
variant={index % 2 === 0 ? 'secondary' : undefined}
|
|
33
|
+
>
|
|
34
|
+
<AccordionToggle
|
|
35
|
+
title={formatPluginName(collapse.name)}
|
|
36
|
+
description={formatMessage(
|
|
37
|
+
{
|
|
38
|
+
id: 'users-permissions.Plugin.permissions.plugins.description',
|
|
39
|
+
defaultMessage: 'Define all allowed actions for the {name} plugin.',
|
|
40
|
+
},
|
|
41
|
+
{ name: collapse.name }
|
|
42
|
+
)}
|
|
43
|
+
variant={index % 2 ? 'primary' : 'secondary'}
|
|
44
|
+
/>
|
|
45
|
+
<AccordionContent>
|
|
46
|
+
<Box>
|
|
47
|
+
<PermissionRow permissions={modifiedData[collapse.name]} name={collapse.name} />
|
|
48
|
+
</Box>
|
|
49
|
+
</AccordionContent>
|
|
50
|
+
</Accordion>
|
|
51
|
+
))}
|
|
52
|
+
</Stack>
|
|
41
53
|
);
|
|
42
54
|
};
|
|
43
55
|
|
|
44
|
-
export default
|
|
56
|
+
export default Permissions;
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
const init = (initialState, permissions) => {
|
|
2
2
|
const collapses = Object.keys(permissions)
|
|
3
3
|
.sort()
|
|
4
|
-
.
|
|
5
|
-
return acc.concat({
|
|
6
|
-
name: current,
|
|
7
|
-
isOpen: index === 0,
|
|
8
|
-
});
|
|
9
|
-
}, []);
|
|
4
|
+
.map(name => ({ name, isOpen: false }));
|
|
10
5
|
|
|
11
6
|
return { ...initialState, collapses };
|
|
12
7
|
};
|
|
@@ -1,60 +1,59 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useIntl } from 'react-intl';
|
|
3
|
+
import { Typography } from '@strapi/design-system/Typography';
|
|
4
|
+
import { Stack } from '@strapi/design-system/Stack';
|
|
5
|
+
import { GridItem } from '@strapi/design-system/Grid';
|
|
6
|
+
import { get, isEmpty, without } from 'lodash';
|
|
6
7
|
import { useUsersPermissions } from '../../contexts/UsersPermissionsContext';
|
|
7
8
|
import BoundRoute from '../BoundRoute';
|
|
8
|
-
import SizedInput from '../SizedInput';
|
|
9
|
-
import { Header, Wrapper, Sticky } from './Components';
|
|
10
9
|
|
|
11
10
|
const Policies = () => {
|
|
12
|
-
const {
|
|
13
|
-
const
|
|
14
|
-
|
|
11
|
+
const { formatMessage } = useIntl();
|
|
12
|
+
const { selectedAction, routes } = useUsersPermissions();
|
|
13
|
+
|
|
15
14
|
const path = without(selectedAction.split('.'), 'controllers');
|
|
16
15
|
const controllerRoutes = get(routes, path[0]);
|
|
16
|
+
const pathResolved = path.slice(1).join('.');
|
|
17
|
+
|
|
17
18
|
const displayedRoutes = isEmpty(controllerRoutes)
|
|
18
19
|
? []
|
|
19
|
-
: controllerRoutes.filter(o =>
|
|
20
|
-
|
|
21
|
-
const inputName = `${selectedAction}.policy`;
|
|
22
|
-
|
|
23
|
-
const value = useMemo(() => {
|
|
24
|
-
return get(modifiedData, inputName, '');
|
|
25
|
-
}, [inputName, modifiedData]);
|
|
20
|
+
: controllerRoutes.filter(o => o.handler.endsWith(pathResolved));
|
|
26
21
|
|
|
27
22
|
return (
|
|
28
|
-
<
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
23
|
+
<GridItem
|
|
24
|
+
col={5}
|
|
25
|
+
background="neutral150"
|
|
26
|
+
paddingTop={6}
|
|
27
|
+
paddingBottom={6}
|
|
28
|
+
paddingLeft={7}
|
|
29
|
+
paddingRight={7}
|
|
30
|
+
style={{ minHeight: '100%' }}
|
|
31
|
+
>
|
|
32
|
+
{selectedAction ? (
|
|
33
|
+
<Stack size={2}>
|
|
34
|
+
{displayedRoutes.map((route, key) => (
|
|
35
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
36
|
+
<BoundRoute key={key} route={route} />
|
|
37
|
+
))}
|
|
38
|
+
</Stack>
|
|
39
|
+
) : (
|
|
40
|
+
<Stack size={2}>
|
|
41
|
+
<Typography variant="delta" as="h3">
|
|
42
|
+
{formatMessage({
|
|
43
|
+
id: 'users-permissions.Policies.header.title',
|
|
44
|
+
defaultMessage: 'Advanced settings',
|
|
45
|
+
})}
|
|
46
|
+
</Typography>
|
|
47
|
+
<Typography as="p" textColor="neutral600">
|
|
48
|
+
{formatMessage({
|
|
49
|
+
id: 'users-permissions.Policies.header.hint',
|
|
50
|
+
defaultMessage:
|
|
51
|
+
"Select the application's actions or the plugin's actions and click on the cog icon to display the bound route",
|
|
52
|
+
})}
|
|
53
|
+
</Typography>
|
|
54
|
+
</Stack>
|
|
55
|
+
)}
|
|
56
|
+
</GridItem>
|
|
58
57
|
);
|
|
59
58
|
};
|
|
60
59
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import React, { memo, useReducer,
|
|
1
|
+
import React, { memo, useReducer, forwardRef, useImperativeHandle } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import {
|
|
3
|
+
import { Typography } from '@strapi/design-system/Typography';
|
|
4
|
+
import { Stack } from '@strapi/design-system/Stack';
|
|
5
|
+
import { Grid, GridItem } from '@strapi/design-system/Grid';
|
|
4
6
|
import { useIntl } from 'react-intl';
|
|
5
|
-
|
|
6
|
-
import FormCard from '../FormBloc';
|
|
7
7
|
import getTrad from '../../utils/getTrad';
|
|
8
8
|
import Policies from '../Policies';
|
|
9
9
|
import Permissions from '../Permissions';
|
|
@@ -11,10 +11,10 @@ import reducer, { initialState } from './reducer';
|
|
|
11
11
|
import { UsersPermissionsProvider } from '../../contexts/UsersPermissionsContext';
|
|
12
12
|
import init from './init';
|
|
13
13
|
|
|
14
|
-
const UsersPermissions = forwardRef(({ permissions, routes
|
|
14
|
+
const UsersPermissions = forwardRef(({ permissions, routes }, ref) => {
|
|
15
15
|
const { formatMessage } = useIntl();
|
|
16
16
|
const [state, dispatch] = useReducer(reducer, initialState, state =>
|
|
17
|
-
init(state, permissions, routes
|
|
17
|
+
init(state, permissions, routes)
|
|
18
18
|
);
|
|
19
19
|
|
|
20
20
|
useImperativeHandle(ref, () => ({
|
|
@@ -31,28 +31,25 @@ const UsersPermissions = forwardRef(({ permissions, routes, policies }, ref) =>
|
|
|
31
31
|
},
|
|
32
32
|
}));
|
|
33
33
|
|
|
34
|
-
const handleChange =
|
|
34
|
+
const handleChange = ({ target: { name, value } }) =>
|
|
35
35
|
dispatch({
|
|
36
36
|
type: 'ON_CHANGE',
|
|
37
37
|
keys: name.split('.'),
|
|
38
38
|
value: value === 'empty__string_value' ? '' : value,
|
|
39
39
|
});
|
|
40
|
-
}, []);
|
|
41
40
|
|
|
42
|
-
const handleChangeSelectAll =
|
|
41
|
+
const handleChangeSelectAll = ({ target: { name, value } }) =>
|
|
43
42
|
dispatch({
|
|
44
43
|
type: 'ON_CHANGE_SELECT_ALL',
|
|
45
44
|
keys: name.split('.'),
|
|
46
45
|
value,
|
|
47
46
|
});
|
|
48
|
-
}, []);
|
|
49
47
|
|
|
50
|
-
const handleSelectedAction =
|
|
48
|
+
const handleSelectedAction = actionToSelect =>
|
|
51
49
|
dispatch({
|
|
52
50
|
type: 'SELECT_ACTION',
|
|
53
51
|
actionToSelect,
|
|
54
52
|
});
|
|
55
|
-
}, []);
|
|
56
53
|
|
|
57
54
|
const providerValue = {
|
|
58
55
|
...state,
|
|
@@ -63,21 +60,28 @@ const UsersPermissions = forwardRef(({ permissions, routes, policies }, ref) =>
|
|
|
63
60
|
|
|
64
61
|
return (
|
|
65
62
|
<UsersPermissionsProvider value={providerValue}>
|
|
66
|
-
<
|
|
67
|
-
<
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
63
|
+
<Grid gap={0} shadow="filterShadow" hasRadius background="neutral0">
|
|
64
|
+
<GridItem col={7} paddingTop={6} paddingBottom={6} paddingLeft={7} paddingRight={7}>
|
|
65
|
+
<Stack size={6}>
|
|
66
|
+
<Stack size={2}>
|
|
67
|
+
<Typography variant="delta" as="h2">
|
|
68
|
+
{formatMessage({
|
|
69
|
+
id: getTrad('Plugins.header.title'),
|
|
70
|
+
defaultMessage: 'Permissions',
|
|
71
|
+
})}
|
|
72
|
+
</Typography>
|
|
73
|
+
<Typography as="p" textColor="neutral600">
|
|
74
|
+
{formatMessage({
|
|
75
|
+
id: getTrad('Plugins.header.description'),
|
|
76
|
+
defaultMessage: 'Only actions bound by a route are listed below.',
|
|
77
|
+
})}
|
|
78
|
+
</Typography>
|
|
79
|
+
</Stack>
|
|
76
80
|
<Permissions />
|
|
77
|
-
</
|
|
78
|
-
</
|
|
81
|
+
</Stack>
|
|
82
|
+
</GridItem>
|
|
79
83
|
<Policies />
|
|
80
|
-
</
|
|
84
|
+
</Grid>
|
|
81
85
|
</UsersPermissionsProvider>
|
|
82
86
|
);
|
|
83
87
|
});
|
|
@@ -85,7 +89,6 @@ const UsersPermissions = forwardRef(({ permissions, routes, policies }, ref) =>
|
|
|
85
89
|
UsersPermissions.propTypes = {
|
|
86
90
|
permissions: PropTypes.object.isRequired,
|
|
87
91
|
routes: PropTypes.object.isRequired,
|
|
88
|
-
policies: PropTypes.array.isRequired,
|
|
89
92
|
};
|
|
90
93
|
|
|
91
94
|
export default memo(UsersPermissions);
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { useCallback, useReducer, useEffect } from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import { useCallback, useReducer, useEffect, useRef } from 'react';
|
|
2
|
+
import { useNotification } from '@strapi/helper-plugin';
|
|
3
3
|
import reducer, { initialState } from './reducer';
|
|
4
|
+
import axiosIntance from '../../utils/axiosInstance';
|
|
4
5
|
import pluginId from '../../pluginId';
|
|
5
6
|
|
|
6
7
|
const useFetchRole = id => {
|
|
7
8
|
const [state, dispatch] = useReducer(reducer, initialState);
|
|
8
9
|
const toggleNotification = useNotification();
|
|
10
|
+
const isMounted = useRef(null);
|
|
9
11
|
|
|
10
12
|
useEffect(() => {
|
|
13
|
+
isMounted.current = true;
|
|
14
|
+
|
|
11
15
|
if (id) {
|
|
12
16
|
fetchRole(id);
|
|
13
17
|
} else {
|
|
@@ -17,17 +21,23 @@ const useFetchRole = id => {
|
|
|
17
21
|
});
|
|
18
22
|
}
|
|
19
23
|
|
|
24
|
+
return () => (isMounted.current = false);
|
|
20
25
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
21
26
|
}, [id]);
|
|
22
27
|
|
|
23
28
|
const fetchRole = async roleId => {
|
|
24
29
|
try {
|
|
25
|
-
const {
|
|
30
|
+
const {
|
|
31
|
+
data: { role },
|
|
32
|
+
} = await axiosIntance.get(`/${pluginId}/roles/${roleId}`);
|
|
26
33
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
// Prevent updating state on an unmounted component
|
|
35
|
+
if (isMounted.current) {
|
|
36
|
+
dispatch({
|
|
37
|
+
type: 'GET_DATA_SUCCEEDED',
|
|
38
|
+
role,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
31
41
|
} catch (err) {
|
|
32
42
|
console.error(err);
|
|
33
43
|
|
|
@@ -5,10 +5,7 @@ import reducer, { initialState } from './reducer';
|
|
|
5
5
|
|
|
6
6
|
const useUserForm = (endPoint, permissions) => {
|
|
7
7
|
const { isLoading: isLoadingForPermissions, allowedActions } = useRBAC(permissions);
|
|
8
|
-
const [{
|
|
9
|
-
reducer,
|
|
10
|
-
initialState
|
|
11
|
-
);
|
|
8
|
+
const [{ isLoading, modifiedData }, dispatch] = useReducer(reducer, initialState);
|
|
12
9
|
const toggleNotification = useNotification();
|
|
13
10
|
const isMounted = useRef(true);
|
|
14
11
|
|
|
@@ -54,39 +51,16 @@ const useUserForm = (endPoint, permissions) => {
|
|
|
54
51
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
55
52
|
}, [isLoadingForPermissions, endPoint]);
|
|
56
53
|
|
|
57
|
-
const
|
|
58
|
-
dispatch({
|
|
59
|
-
type: 'ON_CHANGE',
|
|
60
|
-
keys: name,
|
|
61
|
-
value,
|
|
62
|
-
});
|
|
63
|
-
}, []);
|
|
64
|
-
|
|
65
|
-
const dispatchResetForm = useCallback(() => {
|
|
66
|
-
dispatch({
|
|
67
|
-
type: 'RESET_FORM',
|
|
68
|
-
});
|
|
69
|
-
}, []);
|
|
70
|
-
|
|
71
|
-
const dispatchSetFormErrors = useCallback(errors => {
|
|
72
|
-
dispatch({ type: 'SET_ERRORS', errors });
|
|
73
|
-
}, []);
|
|
74
|
-
|
|
75
|
-
const dispatchSubmitSucceeded = useCallback(() => {
|
|
54
|
+
const dispatchSubmitSucceeded = useCallback(data => {
|
|
76
55
|
dispatch({
|
|
77
56
|
type: 'ON_SUBMIT_SUCCEEDED',
|
|
57
|
+
data,
|
|
78
58
|
});
|
|
79
59
|
}, []);
|
|
80
60
|
|
|
81
61
|
return {
|
|
82
62
|
allowedActions,
|
|
83
|
-
dispatch,
|
|
84
|
-
dispatchResetForm,
|
|
85
|
-
dispatchSetFormErrors,
|
|
86
63
|
dispatchSubmitSucceeded,
|
|
87
|
-
formErrors,
|
|
88
|
-
handleChange,
|
|
89
|
-
initialData,
|
|
90
64
|
isLoading,
|
|
91
65
|
isLoadingForPermissions,
|
|
92
66
|
modifiedData,
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import produce from 'immer';
|
|
2
|
-
import { set } from 'lodash';
|
|
3
2
|
|
|
4
3
|
const initialState = {
|
|
5
|
-
formErrors: {},
|
|
6
4
|
isLoading: true,
|
|
7
|
-
initialData: {},
|
|
8
5
|
modifiedData: {},
|
|
9
6
|
};
|
|
10
7
|
|
|
@@ -14,15 +11,12 @@ const reducer = (state, action) =>
|
|
|
14
11
|
switch (action.type) {
|
|
15
12
|
case 'GET_DATA': {
|
|
16
13
|
draftState.isLoading = true;
|
|
17
|
-
draftState.initialData = {};
|
|
18
14
|
draftState.modifiedData = {};
|
|
19
15
|
|
|
20
16
|
break;
|
|
21
17
|
}
|
|
22
|
-
|
|
23
18
|
case 'GET_DATA_SUCCEEDED': {
|
|
24
19
|
draftState.isLoading = false;
|
|
25
|
-
draftState.initialData = action.data;
|
|
26
20
|
draftState.modifiedData = action.data;
|
|
27
21
|
|
|
28
22
|
break;
|
|
@@ -31,22 +25,9 @@ const reducer = (state, action) =>
|
|
|
31
25
|
draftState.isLoading = true;
|
|
32
26
|
break;
|
|
33
27
|
}
|
|
34
|
-
case 'ON_CHANGE': {
|
|
35
|
-
set(draftState, ['modifiedData', ...action.keys.split('.')], action.value);
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
28
|
case 'ON_SUBMIT_SUCCEEDED': {
|
|
39
|
-
draftState.
|
|
40
|
-
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
case 'RESET_FORM': {
|
|
44
|
-
draftState.modifiedData = state.initialData;
|
|
45
|
-
draftState.formErrors = {};
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
case 'SET_ERRORS': {
|
|
49
|
-
draftState.formErrors = action.errors;
|
|
29
|
+
draftState.modifiedData = action.data;
|
|
30
|
+
|
|
50
31
|
break;
|
|
51
32
|
}
|
|
52
33
|
default: {
|
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
import { useCallback, useEffect, useReducer } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import { useIntl } from 'react-intl';
|
|
2
|
+
import { useNotification } from '@strapi/helper-plugin';
|
|
4
3
|
import { get } from 'lodash';
|
|
5
4
|
import init from './init';
|
|
6
5
|
import pluginId from '../../pluginId';
|
|
7
|
-
import { cleanPermissions
|
|
6
|
+
import { cleanPermissions } from '../../utils';
|
|
7
|
+
import axiosInstance from '../../utils/axiosInstance';
|
|
8
8
|
import reducer, { initialState } from './reducer';
|
|
9
9
|
|
|
10
10
|
const usePlugins = (shouldFetchData = true) => {
|
|
11
|
-
const { formatMessage } = useIntl();
|
|
12
11
|
const toggleNotification = useNotification();
|
|
13
|
-
const [{ permissions, routes,
|
|
14
|
-
|
|
15
|
-
initialState,
|
|
16
|
-
() => init(initialState, shouldFetchData)
|
|
12
|
+
const [{ permissions, routes, isLoading }, dispatch] = useReducer(reducer, initialState, () =>
|
|
13
|
+
init(initialState, shouldFetchData)
|
|
17
14
|
);
|
|
18
15
|
|
|
19
16
|
const fetchPlugins = useCallback(async () => {
|
|
@@ -22,23 +19,18 @@ const usePlugins = (shouldFetchData = true) => {
|
|
|
22
19
|
type: 'GET_DATA',
|
|
23
20
|
});
|
|
24
21
|
|
|
25
|
-
const [{ permissions }, { routes }
|
|
26
|
-
[`/${pluginId}/permissions`, `/${pluginId}/routes
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
const [{ permissions }, { routes }] = await Promise.all(
|
|
23
|
+
[`/${pluginId}/permissions`, `/${pluginId}/routes`].map(async endpoint => {
|
|
24
|
+
const res = await axiosInstance.get(endpoint);
|
|
25
|
+
|
|
26
|
+
return res.data;
|
|
27
|
+
})
|
|
29
28
|
);
|
|
30
29
|
|
|
31
30
|
dispatch({
|
|
32
31
|
type: 'GET_DATA_SUCCEEDED',
|
|
33
32
|
permissions: cleanPermissions(permissions),
|
|
34
33
|
routes,
|
|
35
|
-
policies: [
|
|
36
|
-
{
|
|
37
|
-
label: formatMessage({ id: getTrad('Policies.InputSelect.empty') }),
|
|
38
|
-
value: 'empty__string_value',
|
|
39
|
-
},
|
|
40
|
-
...formatPolicies(policies),
|
|
41
|
-
],
|
|
42
34
|
});
|
|
43
35
|
} catch (err) {
|
|
44
36
|
const message = get(err, ['response', 'payload', 'message'], 'An error occured');
|
|
@@ -54,7 +46,7 @@ const usePlugins = (shouldFetchData = true) => {
|
|
|
54
46
|
});
|
|
55
47
|
}
|
|
56
48
|
}
|
|
57
|
-
}, [
|
|
49
|
+
}, [toggleNotification]);
|
|
58
50
|
|
|
59
51
|
useEffect(() => {
|
|
60
52
|
if (shouldFetchData) {
|
|
@@ -65,7 +57,6 @@ const usePlugins = (shouldFetchData = true) => {
|
|
|
65
57
|
return {
|
|
66
58
|
permissions,
|
|
67
59
|
routes,
|
|
68
|
-
policies,
|
|
69
60
|
getData: fetchPlugins,
|
|
70
61
|
isLoading,
|
|
71
62
|
};
|
|
@@ -4,7 +4,6 @@ import produce from 'immer';
|
|
|
4
4
|
export const initialState = {
|
|
5
5
|
permissions: {},
|
|
6
6
|
routes: {},
|
|
7
|
-
policies: [],
|
|
8
7
|
isLoading: true,
|
|
9
8
|
};
|
|
10
9
|
|
|
@@ -15,13 +14,11 @@ const reducer = (state, action) =>
|
|
|
15
14
|
draftState.isLoading = true;
|
|
16
15
|
draftState.permissions = {};
|
|
17
16
|
draftState.routes = {};
|
|
18
|
-
draftState.policies = [];
|
|
19
17
|
break;
|
|
20
18
|
}
|
|
21
19
|
case 'GET_DATA_SUCCEEDED': {
|
|
22
20
|
draftState.permissions = action.permissions;
|
|
23
21
|
draftState.routes = action.routes;
|
|
24
|
-
draftState.policies = action.policies;
|
|
25
22
|
draftState.isLoading = false;
|
|
26
23
|
break;
|
|
27
24
|
}
|