@strapi/plugin-users-permissions 4.13.0-beta.0 → 4.13.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/Permissions/index.js +2 -4
- package/admin/src/index.js +7 -8
- package/admin/src/pages/AdvancedSettings/index.js +41 -24
- package/admin/src/pages/EmailTemplates/index.js +62 -47
- package/admin/src/pages/Providers/index.js +64 -58
- package/admin/src/{hooks → pages/Roles/hooks}/usePlugins.js +15 -8
- package/admin/src/pages/Roles/index.js +10 -7
- package/admin/src/pages/Roles/pages/CreatePage.js +190 -0
- package/admin/src/pages/Roles/pages/EditPage.js +211 -0
- package/admin/src/pages/Roles/{ListPage → pages/ListPage}/components/TableBody.js +37 -10
- package/admin/src/pages/Roles/{ListPage → pages/ListPage}/index.js +19 -15
- package/jest.config.front.js +1 -1
- package/package.json +4 -4
- package/server/bootstrap/index.js +36 -0
- package/server/controllers/auth.js +46 -13
- package/server/controllers/user.js +12 -1
- package/admin/src/hooks/index.js +0 -5
- package/admin/src/hooks/useFetchRole/index.js +0 -67
- package/admin/src/hooks/useFetchRole/reducer.js +0 -31
- package/admin/src/hooks/useForm/index.js +0 -68
- package/admin/src/hooks/useForm/reducer.js +0 -40
- package/admin/src/hooks/useRolesList/index.js +0 -65
- package/admin/src/hooks/useRolesList/init.js +0 -5
- package/admin/src/hooks/useRolesList/reducer.js +0 -31
- package/admin/src/pages/AdvancedSettings/utils/api.js +0 -16
- package/admin/src/pages/EmailTemplates/utils/api.js +0 -16
- package/admin/src/pages/Providers/reducer.js +0 -54
- package/admin/src/pages/Providers/utils/api.js +0 -24
- package/admin/src/pages/Providers/utils/createProvidersArray.js +0 -21
- package/admin/src/pages/Roles/CreatePage.js +0 -185
- package/admin/src/pages/Roles/EditPage.js +0 -197
- package/admin/src/pages/Roles/ProtectedCreatePage.js +0 -15
- package/admin/src/pages/Roles/ProtectedEditPage.js +0 -15
- package/admin/src/pages/Roles/ProtectedListPage.js +0 -17
- /package/admin/src/pages/Roles/{ListPage → pages/ListPage}/utils/api.js +0 -0
|
@@ -9,7 +9,11 @@
|
|
|
9
9
|
/* eslint-disable no-useless-escape */
|
|
10
10
|
const crypto = require('crypto');
|
|
11
11
|
const _ = require('lodash');
|
|
12
|
+
const { concat, compact, isArray } = require('lodash/fp');
|
|
12
13
|
const utils = require('@strapi/utils');
|
|
14
|
+
const {
|
|
15
|
+
contentTypes: { getNonWritableAttributes },
|
|
16
|
+
} = require('@strapi/utils');
|
|
13
17
|
const { getService } = require('../utils');
|
|
14
18
|
const {
|
|
15
19
|
validateCallbackBody,
|
|
@@ -273,20 +277,49 @@ module.exports = {
|
|
|
273
277
|
throw new ApplicationError('Register action is currently disabled');
|
|
274
278
|
}
|
|
275
279
|
|
|
280
|
+
const { register } = strapi.config.get('plugin.users-permissions');
|
|
281
|
+
const alwaysAllowedKeys = ['username', 'password', 'email'];
|
|
282
|
+
const userModel = strapi.contentTypes['plugin::users-permissions.user'];
|
|
283
|
+
const { attributes } = userModel;
|
|
284
|
+
|
|
285
|
+
const nonWritable = getNonWritableAttributes(userModel);
|
|
286
|
+
|
|
287
|
+
const allowedKeys = compact(
|
|
288
|
+
concat(
|
|
289
|
+
alwaysAllowedKeys,
|
|
290
|
+
isArray(register?.allowedFields)
|
|
291
|
+
? // Note that we do not filter allowedFields in case a user explicitly chooses to allow a private or otherwise omitted field on registration
|
|
292
|
+
register.allowedFields // if null or undefined, compact will remove it
|
|
293
|
+
: // to prevent breaking changes, if allowedFields is not set in config, we only remove private and known dangerous user schema fields
|
|
294
|
+
// TODO V5: allowedFields defaults to [] when undefined and remove this case
|
|
295
|
+
Object.keys(attributes).filter(
|
|
296
|
+
(key) =>
|
|
297
|
+
!nonWritable.includes(key) &&
|
|
298
|
+
!attributes[key].private &&
|
|
299
|
+
![
|
|
300
|
+
// many of these are included in nonWritable, but we'll list them again to be safe and since we're removing this code in v5 anyway
|
|
301
|
+
// Strapi user schema fields
|
|
302
|
+
'confirmed',
|
|
303
|
+
'blocked',
|
|
304
|
+
'confirmationToken',
|
|
305
|
+
'resetPasswordToken',
|
|
306
|
+
'provider',
|
|
307
|
+
'id',
|
|
308
|
+
'role',
|
|
309
|
+
// other Strapi fields that might be added
|
|
310
|
+
'createdAt',
|
|
311
|
+
'updatedAt',
|
|
312
|
+
'createdBy',
|
|
313
|
+
'updatedBy',
|
|
314
|
+
'publishedAt', // d&p
|
|
315
|
+
'strapi_reviewWorkflows_stage', // review workflows
|
|
316
|
+
].includes(key)
|
|
317
|
+
)
|
|
318
|
+
)
|
|
319
|
+
);
|
|
320
|
+
|
|
276
321
|
const params = {
|
|
277
|
-
..._.
|
|
278
|
-
'confirmed',
|
|
279
|
-
'blocked',
|
|
280
|
-
'confirmationToken',
|
|
281
|
-
'resetPasswordToken',
|
|
282
|
-
'provider',
|
|
283
|
-
'id',
|
|
284
|
-
'createdAt',
|
|
285
|
-
'updatedAt',
|
|
286
|
-
'createdBy',
|
|
287
|
-
'updatedBy',
|
|
288
|
-
'role',
|
|
289
|
-
]),
|
|
322
|
+
..._.pick(ctx.request.body, allowedKeys),
|
|
290
323
|
provider: 'local',
|
|
291
324
|
};
|
|
292
325
|
|
|
@@ -11,7 +11,7 @@ const utils = require('@strapi/utils');
|
|
|
11
11
|
const { getService } = require('../utils');
|
|
12
12
|
const { validateCreateUserBody, validateUpdateUserBody } = require('./validation/user');
|
|
13
13
|
|
|
14
|
-
const { sanitize } = utils;
|
|
14
|
+
const { sanitize, validate } = utils;
|
|
15
15
|
const { ApplicationError, ValidationError, NotFoundError } = utils.errors;
|
|
16
16
|
|
|
17
17
|
const sanitizeOutput = async (user, ctx) => {
|
|
@@ -21,6 +21,13 @@ const sanitizeOutput = async (user, ctx) => {
|
|
|
21
21
|
return sanitize.contentAPI.output(user, schema, { auth });
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
+
const validateQuery = async (query, ctx) => {
|
|
25
|
+
const schema = strapi.getModel('plugin::users-permissions.user');
|
|
26
|
+
const { auth } = ctx.state;
|
|
27
|
+
|
|
28
|
+
return validate.contentAPI.query(query, schema, { auth });
|
|
29
|
+
};
|
|
30
|
+
|
|
24
31
|
const sanitizeQuery = async (query, ctx) => {
|
|
25
32
|
const schema = strapi.getModel('plugin::users-permissions.user');
|
|
26
33
|
const { auth } = ctx.state;
|
|
@@ -143,6 +150,7 @@ module.exports = {
|
|
|
143
150
|
* @return {Object|Array}
|
|
144
151
|
*/
|
|
145
152
|
async find(ctx) {
|
|
153
|
+
await validateQuery(ctx.query, ctx);
|
|
146
154
|
const sanitizedQuery = await sanitizeQuery(ctx.query, ctx);
|
|
147
155
|
const users = await getService('user').fetchAll(sanitizedQuery);
|
|
148
156
|
|
|
@@ -155,6 +163,7 @@ module.exports = {
|
|
|
155
163
|
*/
|
|
156
164
|
async findOne(ctx) {
|
|
157
165
|
const { id } = ctx.params;
|
|
166
|
+
await validateQuery(ctx.query, ctx);
|
|
158
167
|
const sanitizedQuery = await sanitizeQuery(ctx.query, ctx);
|
|
159
168
|
|
|
160
169
|
let data = await getService('user').fetch(id, sanitizedQuery);
|
|
@@ -171,6 +180,7 @@ module.exports = {
|
|
|
171
180
|
* @return {Number}
|
|
172
181
|
*/
|
|
173
182
|
async count(ctx) {
|
|
183
|
+
await validateQuery(ctx.query, ctx);
|
|
174
184
|
const sanitizedQuery = await sanitizeQuery(ctx.query, ctx);
|
|
175
185
|
|
|
176
186
|
ctx.body = await getService('user').count(sanitizedQuery);
|
|
@@ -201,6 +211,7 @@ module.exports = {
|
|
|
201
211
|
return ctx.unauthorized();
|
|
202
212
|
}
|
|
203
213
|
|
|
214
|
+
await validateQuery(query, ctx);
|
|
204
215
|
const sanitizedQuery = await sanitizeQuery(query, ctx);
|
|
205
216
|
const user = await getService('user').fetch(authUser.id, sanitizedQuery);
|
|
206
217
|
|
package/admin/src/hooks/index.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useReducer, useRef } from 'react';
|
|
2
|
-
|
|
3
|
-
import { useFetchClient, useNotification } from '@strapi/helper-plugin';
|
|
4
|
-
|
|
5
|
-
import pluginId from '../../pluginId';
|
|
6
|
-
|
|
7
|
-
import reducer, { initialState } from './reducer';
|
|
8
|
-
|
|
9
|
-
const useFetchRole = (id) => {
|
|
10
|
-
const [state, dispatch] = useReducer(reducer, initialState);
|
|
11
|
-
const toggleNotification = useNotification();
|
|
12
|
-
const isMounted = useRef(null);
|
|
13
|
-
const { get } = useFetchClient();
|
|
14
|
-
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
isMounted.current = true;
|
|
17
|
-
|
|
18
|
-
if (id) {
|
|
19
|
-
fetchRole(id);
|
|
20
|
-
} else {
|
|
21
|
-
dispatch({
|
|
22
|
-
type: 'GET_DATA_SUCCEEDED',
|
|
23
|
-
role: {},
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return () => (isMounted.current = false);
|
|
28
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
29
|
-
}, [id]);
|
|
30
|
-
|
|
31
|
-
const fetchRole = async (roleId) => {
|
|
32
|
-
try {
|
|
33
|
-
const {
|
|
34
|
-
data: { role },
|
|
35
|
-
} = await get(`/${pluginId}/roles/${roleId}`);
|
|
36
|
-
|
|
37
|
-
// Prevent updating state on an unmounted component
|
|
38
|
-
if (isMounted.current) {
|
|
39
|
-
dispatch({
|
|
40
|
-
type: 'GET_DATA_SUCCEEDED',
|
|
41
|
-
role,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
} catch (err) {
|
|
45
|
-
console.error(err);
|
|
46
|
-
|
|
47
|
-
dispatch({
|
|
48
|
-
type: 'GET_DATA_ERROR',
|
|
49
|
-
});
|
|
50
|
-
toggleNotification({
|
|
51
|
-
type: 'warning',
|
|
52
|
-
message: { id: 'notification.error' },
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const handleSubmitSucceeded = useCallback((data) => {
|
|
58
|
-
dispatch({
|
|
59
|
-
type: 'ON_SUBMIT_SUCCEEDED',
|
|
60
|
-
...data,
|
|
61
|
-
});
|
|
62
|
-
}, []);
|
|
63
|
-
|
|
64
|
-
return { ...state, onSubmitSucceeded: handleSubmitSucceeded };
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export default useFetchRole;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/* eslint-disable consistent-return */
|
|
2
|
-
import produce from 'immer';
|
|
3
|
-
|
|
4
|
-
export const initialState = {
|
|
5
|
-
role: {},
|
|
6
|
-
isLoading: true,
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const reducer = (state, action) =>
|
|
10
|
-
produce(state, (draftState) => {
|
|
11
|
-
switch (action.type) {
|
|
12
|
-
case 'GET_DATA_SUCCEEDED': {
|
|
13
|
-
draftState.role = action.role;
|
|
14
|
-
draftState.isLoading = false;
|
|
15
|
-
break;
|
|
16
|
-
}
|
|
17
|
-
case 'GET_DATA_ERROR': {
|
|
18
|
-
draftState.isLoading = false;
|
|
19
|
-
break;
|
|
20
|
-
}
|
|
21
|
-
case 'ON_SUBMIT_SUCCEEDED': {
|
|
22
|
-
draftState.role.name = action.name;
|
|
23
|
-
draftState.role.description = action.description;
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
default:
|
|
27
|
-
return draftState;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
export default reducer;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useReducer, useRef } from 'react';
|
|
2
|
-
|
|
3
|
-
import { useFetchClient, useNotification, useRBAC } from '@strapi/helper-plugin';
|
|
4
|
-
|
|
5
|
-
import reducer, { initialState } from './reducer';
|
|
6
|
-
|
|
7
|
-
const useUserForm = (endPoint, permissions) => {
|
|
8
|
-
const { isLoading: isLoadingForPermissions, allowedActions } = useRBAC(permissions);
|
|
9
|
-
const [{ isLoading, modifiedData }, dispatch] = useReducer(reducer, initialState);
|
|
10
|
-
const toggleNotification = useNotification();
|
|
11
|
-
const isMounted = useRef(true);
|
|
12
|
-
|
|
13
|
-
const { get } = useFetchClient();
|
|
14
|
-
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
const getData = async () => {
|
|
17
|
-
try {
|
|
18
|
-
dispatch({
|
|
19
|
-
type: 'GET_DATA',
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const { data } = await get(`/users-permissions/${endPoint}`);
|
|
23
|
-
|
|
24
|
-
dispatch({
|
|
25
|
-
type: 'GET_DATA_SUCCEEDED',
|
|
26
|
-
data,
|
|
27
|
-
});
|
|
28
|
-
} catch (err) {
|
|
29
|
-
// The user aborted the request
|
|
30
|
-
if (isMounted.current) {
|
|
31
|
-
dispatch({
|
|
32
|
-
type: 'GET_DATA_ERROR',
|
|
33
|
-
});
|
|
34
|
-
console.error(err);
|
|
35
|
-
toggleNotification({
|
|
36
|
-
type: 'warning',
|
|
37
|
-
message: { id: 'notification.error' },
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
if (!isLoadingForPermissions) {
|
|
44
|
-
getData();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return () => {
|
|
48
|
-
isMounted.current = false;
|
|
49
|
-
};
|
|
50
|
-
}, [isLoadingForPermissions, endPoint, get, toggleNotification]);
|
|
51
|
-
|
|
52
|
-
const dispatchSubmitSucceeded = useCallback((data) => {
|
|
53
|
-
dispatch({
|
|
54
|
-
type: 'ON_SUBMIT_SUCCEEDED',
|
|
55
|
-
data,
|
|
56
|
-
});
|
|
57
|
-
}, []);
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
allowedActions,
|
|
61
|
-
dispatchSubmitSucceeded,
|
|
62
|
-
isLoading,
|
|
63
|
-
isLoadingForPermissions,
|
|
64
|
-
modifiedData,
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export default useUserForm;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import produce from 'immer';
|
|
2
|
-
|
|
3
|
-
const initialState = {
|
|
4
|
-
isLoading: true,
|
|
5
|
-
modifiedData: {},
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
const reducer = (state, action) =>
|
|
9
|
-
// eslint-disable-next-line consistent-return
|
|
10
|
-
produce(state, (draftState) => {
|
|
11
|
-
switch (action.type) {
|
|
12
|
-
case 'GET_DATA': {
|
|
13
|
-
draftState.isLoading = true;
|
|
14
|
-
draftState.modifiedData = {};
|
|
15
|
-
|
|
16
|
-
break;
|
|
17
|
-
}
|
|
18
|
-
case 'GET_DATA_SUCCEEDED': {
|
|
19
|
-
draftState.isLoading = false;
|
|
20
|
-
draftState.modifiedData = action.data;
|
|
21
|
-
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
24
|
-
case 'GET_DATA_ERROR': {
|
|
25
|
-
draftState.isLoading = true;
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
case 'ON_SUBMIT_SUCCEEDED': {
|
|
29
|
-
draftState.modifiedData = action.data;
|
|
30
|
-
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
default: {
|
|
34
|
-
return draftState;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
export default reducer;
|
|
40
|
-
export { initialState };
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useReducer, useRef } from 'react';
|
|
2
|
-
|
|
3
|
-
import { useFetchClient, useNotification } from '@strapi/helper-plugin';
|
|
4
|
-
import get from 'lodash/get';
|
|
5
|
-
|
|
6
|
-
import pluginId from '../../pluginId';
|
|
7
|
-
|
|
8
|
-
import init from './init';
|
|
9
|
-
import reducer, { initialState } from './reducer';
|
|
10
|
-
|
|
11
|
-
const useRolesList = (shouldFetchData = true) => {
|
|
12
|
-
const [{ roles, isLoading }, dispatch] = useReducer(reducer, initialState, () =>
|
|
13
|
-
init(initialState, shouldFetchData)
|
|
14
|
-
);
|
|
15
|
-
const toggleNotification = useNotification();
|
|
16
|
-
|
|
17
|
-
const isMounted = useRef(true);
|
|
18
|
-
const fetchClient = useFetchClient();
|
|
19
|
-
|
|
20
|
-
const fetchRolesList = useCallback(async () => {
|
|
21
|
-
try {
|
|
22
|
-
dispatch({
|
|
23
|
-
type: 'GET_DATA',
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
const {
|
|
27
|
-
data: { roles },
|
|
28
|
-
} = await fetchClient.get(`/${pluginId}/roles`);
|
|
29
|
-
|
|
30
|
-
dispatch({
|
|
31
|
-
type: 'GET_DATA_SUCCEEDED',
|
|
32
|
-
data: roles,
|
|
33
|
-
});
|
|
34
|
-
} catch (err) {
|
|
35
|
-
const message = get(err, ['response', 'payload', 'message'], 'An error occured');
|
|
36
|
-
|
|
37
|
-
if (isMounted.current) {
|
|
38
|
-
dispatch({
|
|
39
|
-
type: 'GET_DATA_ERROR',
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
if (message !== 'Forbidden') {
|
|
43
|
-
toggleNotification({
|
|
44
|
-
type: 'warning',
|
|
45
|
-
message,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}, [fetchClient, toggleNotification]);
|
|
51
|
-
|
|
52
|
-
useEffect(() => {
|
|
53
|
-
if (shouldFetchData) {
|
|
54
|
-
fetchRolesList();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return () => {
|
|
58
|
-
isMounted.current = false;
|
|
59
|
-
};
|
|
60
|
-
}, [shouldFetchData, fetchRolesList]);
|
|
61
|
-
|
|
62
|
-
return { roles, isLoading, getData: fetchRolesList };
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export default useRolesList;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/* eslint-disable consistent-return */
|
|
2
|
-
import produce from 'immer';
|
|
3
|
-
|
|
4
|
-
export const initialState = {
|
|
5
|
-
roles: [],
|
|
6
|
-
isLoading: true,
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const reducer = (state, action) =>
|
|
10
|
-
produce(state, (draftState) => {
|
|
11
|
-
switch (action.type) {
|
|
12
|
-
case 'GET_DATA': {
|
|
13
|
-
draftState.isLoading = true;
|
|
14
|
-
draftState.roles = [];
|
|
15
|
-
break;
|
|
16
|
-
}
|
|
17
|
-
case 'GET_DATA_SUCCEEDED': {
|
|
18
|
-
draftState.roles = action.data;
|
|
19
|
-
draftState.isLoading = false;
|
|
20
|
-
break;
|
|
21
|
-
}
|
|
22
|
-
case 'GET_DATA_ERROR': {
|
|
23
|
-
draftState.isLoading = false;
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
default:
|
|
27
|
-
return draftState;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
export default reducer;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { getFetchClient } from '@strapi/helper-plugin';
|
|
2
|
-
|
|
3
|
-
const fetchData = async () => {
|
|
4
|
-
const { get } = getFetchClient();
|
|
5
|
-
const { data } = await get('/users-permissions/advanced');
|
|
6
|
-
|
|
7
|
-
return data;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
const putAdvancedSettings = (body) => {
|
|
11
|
-
const { put } = getFetchClient();
|
|
12
|
-
|
|
13
|
-
return put('/users-permissions/advanced', body);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export { fetchData, putAdvancedSettings };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { getFetchClient } from '@strapi/helper-plugin';
|
|
2
|
-
|
|
3
|
-
const fetchData = async () => {
|
|
4
|
-
const { get } = getFetchClient();
|
|
5
|
-
const { data } = await get('/users-permissions/email-templates');
|
|
6
|
-
|
|
7
|
-
return data;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
const putEmailTemplate = (body) => {
|
|
11
|
-
const { put } = getFetchClient();
|
|
12
|
-
|
|
13
|
-
return put('/users-permissions/email-templates', body);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export { fetchData, putEmailTemplate };
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import produce from 'immer';
|
|
2
|
-
import set from 'lodash/set';
|
|
3
|
-
|
|
4
|
-
const initialState = {
|
|
5
|
-
formErrors: {},
|
|
6
|
-
isLoading: true,
|
|
7
|
-
initialData: {},
|
|
8
|
-
modifiedData: {},
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const reducer = (state, action) =>
|
|
12
|
-
// eslint-disable-next-line consistent-return
|
|
13
|
-
produce(state, (draftState) => {
|
|
14
|
-
switch (action.type) {
|
|
15
|
-
case 'GET_DATA': {
|
|
16
|
-
draftState.isLoading = true;
|
|
17
|
-
draftState.initialData = {};
|
|
18
|
-
draftState.modifiedData = {};
|
|
19
|
-
|
|
20
|
-
break;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
case 'GET_DATA_SUCCEEDED': {
|
|
24
|
-
draftState.isLoading = false;
|
|
25
|
-
draftState.initialData = action.data;
|
|
26
|
-
draftState.modifiedData = action.data;
|
|
27
|
-
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
case 'GET_DATA_ERROR': {
|
|
31
|
-
draftState.isLoading = true;
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
case 'ON_CHANGE': {
|
|
35
|
-
set(draftState, ['modifiedData', ...action.keys.split('.')], action.value);
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
case 'RESET_FORM': {
|
|
39
|
-
draftState.modifiedData = state.initialData;
|
|
40
|
-
draftState.formErrors = {};
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
case 'SET_ERRORS': {
|
|
44
|
-
draftState.formErrors = action.errors;
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
default: {
|
|
48
|
-
return draftState;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
export default reducer;
|
|
54
|
-
export { initialState };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { getFetchClient } from '@strapi/helper-plugin';
|
|
2
|
-
|
|
3
|
-
// eslint-disable-next-line import/prefer-default-export
|
|
4
|
-
export const fetchData = async (toggleNotification) => {
|
|
5
|
-
try {
|
|
6
|
-
const { get } = getFetchClient();
|
|
7
|
-
const { data } = await get('/users-permissions/providers');
|
|
8
|
-
|
|
9
|
-
return data;
|
|
10
|
-
} catch (err) {
|
|
11
|
-
toggleNotification({
|
|
12
|
-
type: 'warning',
|
|
13
|
-
message: { id: 'notification.error' },
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
throw new Error('error');
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const putProvider = (body) => {
|
|
21
|
-
const { put } = getFetchClient();
|
|
22
|
-
|
|
23
|
-
return put('/users-permissions/providers', body);
|
|
24
|
-
};
|
|
@@ -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;
|