@strapi/plugin-users-permissions 4.3.4 → 4.4.0-alpha.0

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 (75) hide show
  1. package/admin/src/components/BoundRoute/getMethodColor.js +1 -1
  2. package/admin/src/components/BoundRoute/index.js +1 -1
  3. package/admin/src/components/FormModal/Input/index.js +1 -1
  4. package/admin/src/components/FormModal/index.js +7 -9
  5. package/admin/src/components/Permissions/PermissionRow/CheckboxWrapper.js +3 -3
  6. package/admin/src/components/Permissions/PermissionRow/SubCategory.js +10 -14
  7. package/admin/src/components/Permissions/PermissionRow/index.js +1 -1
  8. package/admin/src/components/Permissions/index.js +2 -2
  9. package/admin/src/components/Permissions/init.js +1 -1
  10. package/admin/src/components/Permissions/reducer.js +1 -1
  11. package/admin/src/components/Policies/index.js +1 -1
  12. package/admin/src/components/UsersPermissions/index.js +5 -5
  13. package/admin/src/components/UsersPermissions/reducer.js +1 -1
  14. package/admin/src/hooks/useFetchRole/index.js +3 -3
  15. package/admin/src/hooks/useFetchRole/reducer.js +1 -1
  16. package/admin/src/hooks/useForm/index.js +1 -1
  17. package/admin/src/hooks/useForm/reducer.js +1 -1
  18. package/admin/src/hooks/usePlugins/index.js +1 -1
  19. package/admin/src/hooks/usePlugins/reducer.js +1 -1
  20. package/admin/src/hooks/useRolesList/reducer.js +1 -1
  21. package/admin/src/index.js +5 -5
  22. package/admin/src/pages/AdvancedSettings/index.js +11 -10
  23. package/admin/src/pages/AdvancedSettings/utils/api.js +1 -1
  24. package/admin/src/pages/AdvancedSettings/utils/schema.js +2 -4
  25. package/admin/src/pages/EmailTemplates/index.js +8 -8
  26. package/admin/src/pages/EmailTemplates/utils/api.js +1 -1
  27. package/admin/src/pages/EmailTemplates/utils/schema.js +1 -4
  28. package/admin/src/pages/Providers/index.js +22 -22
  29. package/admin/src/pages/Providers/reducer.js +1 -1
  30. package/admin/src/pages/Providers/utils/api.js +2 -2
  31. package/admin/src/pages/Providers/utils/createProvidersArray.js +1 -1
  32. package/admin/src/pages/Roles/CreatePage/index.js +1 -1
  33. package/admin/src/pages/Roles/EditPage/index.js +1 -1
  34. package/admin/src/pages/Roles/ListPage/components/TableBody.js +5 -4
  35. package/admin/src/pages/Roles/ListPage/index.js +2 -2
  36. package/admin/src/utils/axiosInstance.js +4 -4
  37. package/admin/src/utils/cleanPermissions.js +1 -1
  38. package/admin/src/utils/formatPolicies.js +1 -1
  39. package/admin/src/utils/getRequestURL.js +1 -1
  40. package/admin/src/utils/getTrad.js +1 -1
  41. package/documentation/content-api.yaml +1 -1
  42. package/jest.config.front.js +1 -1
  43. package/package.json +12 -7
  44. package/server/bootstrap/grant-config.js +1 -1
  45. package/server/bootstrap/index.js +39 -39
  46. package/server/controllers/auth.js +2 -5
  47. package/server/controllers/content-manager-user.js +4 -12
  48. package/server/controllers/settings.js +1 -1
  49. package/server/controllers/user.js +2 -2
  50. package/server/controllers/validation/auth.js +3 -12
  51. package/server/controllers/validation/email-template.js +3 -2
  52. package/server/controllers/validation/user.js +4 -16
  53. package/server/graphql/mutations/auth/change-password.js +1 -4
  54. package/server/graphql/mutations/auth/forgot-password.js +1 -4
  55. package/server/graphql/mutations/auth/login.js +1 -4
  56. package/server/graphql/mutations/auth/register.js +1 -4
  57. package/server/graphql/mutations/auth/reset-password.js +1 -4
  58. package/server/graphql/mutations/crud/role/create-role.js +1 -4
  59. package/server/graphql/mutations/crud/role/delete-role.js +1 -4
  60. package/server/graphql/mutations/crud/role/update-role.js +1 -4
  61. package/server/graphql/mutations/crud/user/create-user.js +1 -4
  62. package/server/graphql/mutations/crud/user/delete-user.js +1 -4
  63. package/server/graphql/mutations/crud/user/update-user.js +1 -4
  64. package/server/graphql/mutations/index.js +1 -1
  65. package/server/graphql/types/index.js +1 -1
  66. package/server/middlewares/rateLimit.js +22 -25
  67. package/server/register.js +2 -4
  68. package/server/services/jwt.js +11 -9
  69. package/server/services/providers-registry.js +33 -42
  70. package/server/services/providers.js +6 -6
  71. package/server/services/role.js +7 -7
  72. package/server/services/user.js +1 -1
  73. package/server/services/users-permissions.js +12 -12
  74. package/server/strategies/users-permissions.js +3 -3
  75. package/server/utils/index.js +1 -1
@@ -53,26 +53,26 @@ export const ProvidersPage = () => {
53
53
  allowedActions: { canUpdate },
54
54
  } = useRBAC(updatePermissions);
55
55
 
56
- const { isLoading: isLoadingForData, data: modifiedData, isFetching } = useQuery(
57
- 'get-providers',
58
- () => fetchData(toggleNotification),
59
- {
60
- onSuccess: () => {
61
- notifyStatus(
62
- formatMessage({
63
- id: getTrad('Providers.data.loaded'),
64
- defaultMessage: 'Providers have been loaded',
65
- })
66
- );
67
- },
68
- initialData: {},
69
- }
70
- );
56
+ const {
57
+ isLoading: isLoadingForData,
58
+ data: modifiedData,
59
+ isFetching,
60
+ } = useQuery('get-providers', () => fetchData(toggleNotification), {
61
+ onSuccess() {
62
+ notifyStatus(
63
+ formatMessage({
64
+ id: getTrad('Providers.data.loaded'),
65
+ defaultMessage: 'Providers have been loaded',
66
+ })
67
+ );
68
+ },
69
+ initialData: {},
70
+ });
71
71
 
72
72
  const isLoading = isLoadingForData || isFetching;
73
73
 
74
74
  const submitMutation = useMutation(putProvider, {
75
- onSuccess: async () => {
75
+ async onSuccess() {
76
76
  await queryClient.invalidateQueries('get-providers');
77
77
  toggleNotification({
78
78
  type: 'info',
@@ -84,7 +84,7 @@ export const ProvidersPage = () => {
84
84
  handleToggleModal();
85
85
  unlockApp();
86
86
  },
87
- onError: () => {
87
+ onError() {
88
88
  toggleNotification({
89
89
  type: 'warning',
90
90
  message: { id: 'notification.error' },
@@ -104,7 +104,7 @@ export const ProvidersPage = () => {
104
104
  return false;
105
105
  }
106
106
 
107
- const providerToEdit = providers.find(obj => obj.name === providerToEditName);
107
+ const providerToEdit = providers.find((obj) => obj.name === providerToEditName);
108
108
 
109
109
  return has(providerToEdit, 'subdomain');
110
110
  }, [providers, providerToEditName]);
@@ -127,17 +127,17 @@ export const ProvidersPage = () => {
127
127
  }, [providerToEditName, isProviderWithSubdomain]);
128
128
 
129
129
  const handleToggleModal = () => {
130
- setIsOpen(prev => !prev);
130
+ setIsOpen((prev) => !prev);
131
131
  };
132
132
 
133
- const handleClickEdit = provider => {
133
+ const handleClickEdit = (provider) => {
134
134
  if (canUpdate) {
135
135
  setProviderToEditName(provider.name);
136
136
  handleToggleModal();
137
137
  }
138
138
  };
139
139
 
140
- const handleSubmit = async values => {
140
+ const handleSubmit = async (values) => {
141
141
  setIsSubmiting(true);
142
142
 
143
143
  lockApp();
@@ -196,7 +196,7 @@ export const ProvidersPage = () => {
196
196
  </Tr>
197
197
  </Thead>
198
198
  <Tbody>
199
- {providers.map(provider => (
199
+ {providers.map((provider) => (
200
200
  <Tr
201
201
  key={provider.name}
202
202
  {...onRowClick({
@@ -10,7 +10,7 @@ const initialState = {
10
10
 
11
11
  const reducer = (state, action) =>
12
12
  // eslint-disable-next-line consistent-return
13
- produce(state, draftState => {
13
+ produce(state, (draftState) => {
14
14
  switch (action.type) {
15
15
  case 'GET_DATA': {
16
16
  draftState.isLoading = true;
@@ -1,7 +1,7 @@
1
1
  import { getRequestURL, axiosInstance } from '../../../utils';
2
2
 
3
3
  // eslint-disable-next-line import/prefer-default-export
4
- export const fetchData = async toggleNotification => {
4
+ export const fetchData = async (toggleNotification) => {
5
5
  try {
6
6
  const { data } = await axiosInstance.get(getRequestURL('providers'));
7
7
 
@@ -16,6 +16,6 @@ export const fetchData = async toggleNotification => {
16
16
  }
17
17
  };
18
18
 
19
- export const putProvider = body => {
19
+ export const putProvider = (body) => {
20
20
  return axiosInstance.put(getRequestURL('providers'), body);
21
21
  };
@@ -1,6 +1,6 @@
1
1
  import { sortBy } from 'lodash';
2
2
 
3
- const createProvidersArray = data => {
3
+ const createProvidersArray = (data) => {
4
4
  return sortBy(
5
5
  Object.keys(data).reduce((acc, current) => {
6
6
  const { icon: iconName, enabled, subdomain } = data[current];
@@ -36,7 +36,7 @@ const EditPage = () => {
36
36
  const { trackUsage } = useTracking();
37
37
  const permissionsRef = useRef();
38
38
 
39
- const handleCreateRoleSubmit = async data => {
39
+ const handleCreateRoleSubmit = async (data) => {
40
40
  // Set loading state
41
41
  lockApp();
42
42
  setIsSubmitting(true);
@@ -40,7 +40,7 @@ const EditPage = () => {
40
40
  const { role, onSubmitSucceeded, isLoading: isLoadingRole } = useFetchRole(id);
41
41
  const permissionsRef = useRef();
42
42
 
43
- const handleEditRoleSubmit = async data => {
43
+ const handleEditRoleSubmit = async (data) => {
44
44
  // Set loading state
45
45
  lockApp();
46
46
  setIsSubmitting(true);
@@ -17,20 +17,21 @@ const TableBody = ({ sortedRoles, canDelete, permissions, setRoleToDelete, onDel
17
17
  const { push } = useHistory();
18
18
  const [showConfirmDelete, setShowConfirmDelete] = onDelete;
19
19
 
20
- const checkCanDeleteRole = role => canDelete && !['public', 'authenticated'].includes(role.type);
20
+ const checkCanDeleteRole = (role) =>
21
+ canDelete && !['public', 'authenticated'].includes(role.type);
21
22
 
22
- const handleClickDelete = id => {
23
+ const handleClickDelete = (id) => {
23
24
  setRoleToDelete(id);
24
25
  setShowConfirmDelete(!showConfirmDelete);
25
26
  };
26
27
 
27
- const handleClickEdit = id => {
28
+ const handleClickEdit = (id) => {
28
29
  push(`/settings/${pluginId}/roles/${id}`);
29
30
  };
30
31
 
31
32
  return (
32
33
  <Tbody>
33
- {sortedRoles?.map(role => (
34
+ {sortedRoles?.map((role) => (
34
35
  <Tr key={role.name} {...onRowClick({ fn: () => handleClickEdit(role.id) })}>
35
36
  <Td width="20%">
36
37
  <Typography>{role.name}</Typography>
@@ -97,8 +97,8 @@ const RoleListPage = () => {
97
97
  defaultMessage: 'Roles',
98
98
  });
99
99
 
100
- const deleteMutation = useMutation(id => deleteData(id, toggleNotification), {
101
- onSuccess: async () => {
100
+ const deleteMutation = useMutation((id) => deleteData(id, toggleNotification), {
101
+ async onSuccess() {
102
102
  await queryClient.invalidateQueries('get-roles');
103
103
  },
104
104
  });
@@ -6,7 +6,7 @@ const instance = axios.create({
6
6
  });
7
7
 
8
8
  instance.interceptors.request.use(
9
- async config => {
9
+ async (config) => {
10
10
  config.headers = {
11
11
  Authorization: `Bearer ${auth.getToken()}`,
12
12
  Accept: 'application/json',
@@ -15,14 +15,14 @@ instance.interceptors.request.use(
15
15
 
16
16
  return config;
17
17
  },
18
- error => {
18
+ (error) => {
19
19
  Promise.reject(error);
20
20
  }
21
21
  );
22
22
 
23
23
  instance.interceptors.response.use(
24
- response => response,
25
- error => {
24
+ (response) => response,
25
+ (error) => {
26
26
  // whatever you want to do with the error
27
27
  if (error.response?.status === 401) {
28
28
  auth.clearAppStorage();
@@ -1,6 +1,6 @@
1
1
  import { isEmpty } from 'lodash';
2
2
 
3
- const cleanPermissions = permissions =>
3
+ const cleanPermissions = (permissions) =>
4
4
  Object.keys(permissions).reduce((acc, current) => {
5
5
  const currentPermission = permissions[current].controllers;
6
6
  const cleanedControllers = Object.keys(currentPermission).reduce((acc2, curr) => {
@@ -1,4 +1,4 @@
1
- const formatPolicies = policies =>
1
+ const formatPolicies = (policies) =>
2
2
  policies.reduce((acc, current) => {
3
3
  acc.push({ label: current, value: current });
4
4
 
@@ -1,5 +1,5 @@
1
1
  import pluginId from '../pluginId';
2
2
 
3
- const getRequestURL = endPoint => `/${pluginId}/${endPoint}`;
3
+ const getRequestURL = (endPoint) => `/${pluginId}/${endPoint}`;
4
4
 
5
5
  export default getRequestURL;
@@ -1,5 +1,5 @@
1
1
  import pluginId from '../pluginId';
2
2
 
3
- const getTrad = id => `${pluginId}.${id}`;
3
+ const getTrad = (id) => `${pluginId}.${id}`;
4
4
 
5
5
  export default getTrad;
@@ -44,7 +44,7 @@ paths:
44
44
  password:
45
45
  type: string
46
46
  example:
47
- identier: foobar
47
+ identifier: foobar
48
48
  password: Test1234
49
49
  required: true
50
50
  responses:
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const baseConfig = require('../../../jest.base-config.front');
4
- const pkg = require('./package');
4
+ const pkg = require('./package.json');
5
5
 
6
6
  module.exports = {
7
7
  ...baseConfig,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/plugin-users-permissions",
3
- "version": "4.3.4",
3
+ "version": "4.4.0-alpha.0",
4
4
  "description": "Protect your API with a full-authentication process based on JWT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -27,26 +27,31 @@
27
27
  "test:front:watch:ce": "cross-env IS_EE=false jest --config ./jest.config.front.js --watchAll"
28
28
  },
29
29
  "dependencies": {
30
- "@strapi/helper-plugin": "4.3.4",
31
- "@strapi/utils": "4.3.4",
30
+ "@strapi/helper-plugin": "4.4.0-alpha.0",
31
+ "@strapi/utils": "4.4.0-alpha.0",
32
32
  "bcryptjs": "2.4.3",
33
33
  "grant-koa": "5.4.8",
34
34
  "jsonwebtoken": "^8.1.0",
35
+ "koa": "^2.13.4",
35
36
  "koa2-ratelimit": "^1.1.1",
36
37
  "lodash": "4.17.21",
37
38
  "purest": "4.0.2",
38
39
  "react": "^17.0.2",
39
40
  "react-dom": "^17.0.2",
40
- "react-intl": "5.20.2",
41
+ "react-intl": "5.25.1",
41
42
  "react-redux": "7.2.8",
42
43
  "react-router": "^5.2.0",
43
44
  "react-router-dom": "5.2.0",
44
- "redux-saga": "^0.16.0",
45
45
  "request": "^2.83.0",
46
46
  "url-join": "4.0.1"
47
47
  },
48
48
  "devDependencies": {
49
- "koa": "^2.13.4"
49
+ "@testing-library/dom": "8.17.1",
50
+ "@testing-library/react": "12.1.4",
51
+ "@testing-library/react-hooks": "8.0.1",
52
+ "@testing-library/user-event": "14.4.2",
53
+ "msw": "0.42.3",
54
+ "react-test-renderer": "^17.0.2"
50
55
  },
51
56
  "engines": {
52
57
  "node": ">=14.19.1 <=16.x.x",
@@ -59,5 +64,5 @@
59
64
  "required": true,
60
65
  "kind": "plugin"
61
66
  },
62
- "gitHead": "28a2a00db8234ffcf644661c4c8092aa82f8c119"
67
+ "gitHead": "fc78298ae4f9b247d636beda568734d5f8ed7b3e"
63
68
  }
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- module.exports = baseURL => ({
3
+ module.exports = (baseURL) => ({
4
4
  email: {
5
5
  enabled: true,
6
6
  icon: 'envelope',
@@ -15,42 +15,7 @@ const getGrantConfig = require('./grant-config');
15
15
 
16
16
  const usersPermissionsActions = require('./users-permissions-actions');
17
17
 
18
- module.exports = async ({ strapi }) => {
19
- const pluginStore = strapi.store({ type: 'plugin', name: 'users-permissions' });
20
-
21
- await initGrant(pluginStore);
22
- await initEmails(pluginStore);
23
- await initAdvancedOptions(pluginStore);
24
-
25
- await strapi.admin.services.permission.actionProvider.registerMany(
26
- usersPermissionsActions.actions
27
- );
28
-
29
- await getService('users-permissions').initialize();
30
-
31
- if (!strapi.config.get('plugin.users-permissions.jwtSecret')) {
32
- if (process.env.NODE_ENV !== 'development') {
33
- throw new Error(
34
- `Missing jwtSecret. Please, set configuration variable "jwtSecret" for the users-permissions plugin in config/plugins.js (ex: you can generate one using Node with \`crypto.randomBytes(16).toString('base64')\`).
35
- For security reasons, prefer storing the secret in an environment variable and read it in config/plugins.js. See https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/configurations/optional/environment.html#configuration-using-environment-variables.`
36
- );
37
- }
38
-
39
- const jwtSecret = crypto.randomBytes(16).toString('base64');
40
-
41
- strapi.config.set('plugin.users-permissions.jwtSecret', jwtSecret);
42
-
43
- if (!process.env.JWT_SECRET) {
44
- const envPath = process.env.ENV_PATH || '.env';
45
- strapi.fs.appendFile(envPath, `JWT_SECRET=${jwtSecret}\n`);
46
- strapi.log.info(
47
- `The Users & Permissions plugin automatically generated a jwt secret and stored it in ${envPath} under the name JWT_SECRET.`
48
- );
49
- }
50
- }
51
- };
52
-
53
- const initGrant = async pluginStore => {
18
+ const initGrant = async (pluginStore) => {
54
19
  const apiPrefix = strapi.config.get('api.rest.prefix');
55
20
  const baseURL = urljoin(strapi.config.server.url, apiPrefix, 'auth');
56
21
 
@@ -62,7 +27,7 @@ const initGrant = async pluginStore => {
62
27
  // or we have added/deleted provider here.
63
28
  if (!prevGrantConfig || !_.isEqual(_.keys(prevGrantConfig), _.keys(grantConfig))) {
64
29
  // merge with the previous provider config.
65
- _.keys(grantConfig).forEach(key => {
30
+ _.keys(grantConfig).forEach((key) => {
66
31
  if (key in prevGrantConfig) {
67
32
  grantConfig[key] = _.merge(grantConfig[key], prevGrantConfig[key]);
68
33
  }
@@ -71,7 +36,7 @@ const initGrant = async pluginStore => {
71
36
  }
72
37
  };
73
38
 
74
- const initEmails = async pluginStore => {
39
+ const initEmails = async (pluginStore) => {
75
40
  if (!(await pluginStore.get({ key: 'email' }))) {
76
41
  const value = {
77
42
  reset_password: {
@@ -117,7 +82,7 @@ const initEmails = async pluginStore => {
117
82
  }
118
83
  };
119
84
 
120
- const initAdvancedOptions = async pluginStore => {
85
+ const initAdvancedOptions = async (pluginStore) => {
121
86
  if (!(await pluginStore.get({ key: 'advanced' }))) {
122
87
  const value = {
123
88
  unique_email: true,
@@ -131,3 +96,38 @@ const initAdvancedOptions = async pluginStore => {
131
96
  await pluginStore.set({ key: 'advanced', value });
132
97
  }
133
98
  };
99
+
100
+ module.exports = async ({ strapi }) => {
101
+ const pluginStore = strapi.store({ type: 'plugin', name: 'users-permissions' });
102
+
103
+ await initGrant(pluginStore);
104
+ await initEmails(pluginStore);
105
+ await initAdvancedOptions(pluginStore);
106
+
107
+ await strapi.admin.services.permission.actionProvider.registerMany(
108
+ usersPermissionsActions.actions
109
+ );
110
+
111
+ await getService('users-permissions').initialize();
112
+
113
+ if (!strapi.config.get('plugin.users-permissions.jwtSecret')) {
114
+ if (process.env.NODE_ENV !== 'development') {
115
+ throw new Error(
116
+ `Missing jwtSecret. Please, set configuration variable "jwtSecret" for the users-permissions plugin in config/plugins.js (ex: you can generate one using Node with \`crypto.randomBytes(16).toString('base64')\`).
117
+ For security reasons, prefer storing the secret in an environment variable and read it in config/plugins.js. See https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/configurations/optional/environment.html#configuration-using-environment-variables.`
118
+ );
119
+ }
120
+
121
+ const jwtSecret = crypto.randomBytes(16).toString('base64');
122
+
123
+ strapi.config.set('plugin.users-permissions.jwtSecret', jwtSecret);
124
+
125
+ if (!process.env.JWT_SECRET) {
126
+ const envPath = process.env.ENV_PATH || '.env';
127
+ strapi.fs.appendFile(envPath, `JWT_SECRET=${jwtSecret}\n`);
128
+ strapi.log.info(
129
+ `The Users & Permissions plugin automatically generated a jwt secret and stored it in ${envPath} under the name JWT_SECRET.`
130
+ );
131
+ }
132
+ }
133
+ };
@@ -259,10 +259,7 @@ module.exports = {
259
259
  await getService('user').edit(user.id, { resetPasswordToken });
260
260
 
261
261
  // Send an email to the user.
262
- await strapi
263
- .plugin('email')
264
- .service('email')
265
- .send(emailToSend);
262
+ await strapi.plugin('email').service('email').send(emailToSend);
266
263
 
267
264
  ctx.send({ ok: true });
268
265
  },
@@ -326,7 +323,7 @@ module.exports = {
326
323
  }
327
324
  }
328
325
 
329
- let newUser = {
326
+ const newUser = {
330
327
  ...params,
331
328
  role: role.id,
332
329
  email: email.toLowerCase(),
@@ -2,12 +2,8 @@
2
2
 
3
3
  const _ = require('lodash');
4
4
  const { contentTypes: contentTypesUtils } = require('@strapi/utils');
5
- const {
6
- ApplicationError,
7
- ValidationError,
8
- NotFoundError,
9
- ForbiddenError,
10
- } = require('@strapi/utils').errors;
5
+ const { ApplicationError, ValidationError, NotFoundError, ForbiddenError } =
6
+ require('@strapi/utils').errors;
11
7
  const { validateCreateUserBody, validateUpdateUserBody } = require('./validation/user');
12
8
 
13
9
  const { UPDATED_BY_ATTRIBUTE, CREATED_BY_ATTRIBUTE } = contentTypesUtils.constants;
@@ -132,17 +128,13 @@ module.exports = {
132
128
 
133
129
  const { email, username, password } = body;
134
130
 
135
- let pm;
136
- let user;
137
-
138
- const { pm: permissionManager, entity } = await findEntityAndCheckPermissions(
131
+ const { pm, entity } = await findEntityAndCheckPermissions(
139
132
  userAbility,
140
133
  ACTIONS.edit,
141
134
  userModel,
142
135
  id
143
136
  );
144
- pm = permissionManager;
145
- user = entity;
137
+ const user = entity;
146
138
 
147
139
  await validateUpdateUserBody(ctx.request.body);
148
140
 
@@ -17,7 +17,7 @@ module.exports = {
17
17
 
18
18
  const emailTemplates = ctx.request.body['email-templates'];
19
19
 
20
- for (let key in emailTemplates) {
20
+ for (const key of Object.keys(emailTemplates)) {
21
21
  const template = emailTemplates[key].options.message;
22
22
 
23
23
  if (!isValidEmailTemplate(template)) {
@@ -121,7 +121,7 @@ module.exports = {
121
121
  ctx.request.body.email = ctx.request.body.email.toLowerCase();
122
122
  }
123
123
 
124
- let updateData = {
124
+ const updateData = {
125
125
  ...ctx.request.body,
126
126
  };
127
127
 
@@ -138,7 +138,7 @@ module.exports = {
138
138
  async find(ctx) {
139
139
  const users = await getService('user').fetchAll(ctx.query);
140
140
 
141
- ctx.body = await Promise.all(users.map(user => sanitizeOutput(user, ctx)));
141
+ ctx.body = await Promise.all(users.map((user) => sanitizeOutput(user, ctx)));
142
142
  },
143
143
 
144
144
  /**
@@ -8,19 +8,13 @@ const callbackSchema = yup.object({
8
8
  });
9
9
 
10
10
  const registerSchema = yup.object({
11
- email: yup
12
- .string()
13
- .email()
14
- .required(),
11
+ email: yup.string().email().required(),
15
12
  username: yup.string().required(),
16
13
  password: yup.string().required(),
17
14
  });
18
15
 
19
16
  const sendEmailConfirmationSchema = yup.object({
20
- email: yup
21
- .string()
22
- .email()
23
- .required(),
17
+ email: yup.string().email().required(),
24
18
  });
25
19
 
26
20
  const validateEmailConfirmationSchema = yup.object({
@@ -29,10 +23,7 @@ const validateEmailConfirmationSchema = yup.object({
29
23
 
30
24
  const forgotPasswordSchema = yup
31
25
  .object({
32
- email: yup
33
- .string()
34
- .email()
35
- .required(),
26
+ email: yup.string().email().required(),
36
27
  })
37
28
  .noUnknown();
38
29
 
@@ -19,6 +19,7 @@ const matchAll = (pattern, src) => {
19
19
  let match;
20
20
 
21
21
  const regexPatternWithGlobal = RegExp(pattern, 'g');
22
+ // eslint-disable-next-line no-cond-assign
22
23
  while ((match = regexPatternWithGlobal.exec(src))) {
23
24
  const [, group] = match;
24
25
 
@@ -27,8 +28,8 @@ const matchAll = (pattern, src) => {
27
28
  return matches;
28
29
  };
29
30
 
30
- const isValidEmailTemplate = template => {
31
- for (let reg of invalidPatternsRegexes) {
31
+ const isValidEmailTemplate = (template) => {
32
+ for (const reg of invalidPatternsRegexes) {
32
33
  if (reg.test(template)) {
33
34
  return false;
34
35
  }
@@ -7,26 +7,14 @@ const deleteRoleSchema = yup.object().shape({
7
7
  });
8
8
 
9
9
  const createUserBodySchema = yup.object().shape({
10
- email: yup
11
- .string()
12
- .email()
13
- .required(),
14
- username: yup
15
- .string()
16
- .min(1)
17
- .required(),
18
- password: yup
19
- .string()
20
- .min(1)
21
- .required(),
10
+ email: yup.string().email().required(),
11
+ username: yup.string().min(1).required(),
12
+ password: yup.string().min(1).required(),
22
13
  role: yup.strapiID(),
23
14
  });
24
15
 
25
16
  const updateUserBodySchema = yup.object().shape({
26
- email: yup
27
- .string()
28
- .email()
29
- .min(1),
17
+ email: yup.string().email().min(1),
30
18
  username: yup.string().min(1),
31
19
  password: yup.string().min(1),
32
20
  });
@@ -23,10 +23,7 @@ module.exports = ({ nexus, strapi }) => {
23
23
 
24
24
  koaContext.request.body = toPlainObject(args);
25
25
 
26
- await strapi
27
- .plugin('users-permissions')
28
- .controller('auth')
29
- .changePassword(koaContext);
26
+ await strapi.plugin('users-permissions').controller('auth').changePassword(koaContext);
30
27
 
31
28
  const output = koaContext.body;
32
29
 
@@ -21,10 +21,7 @@ module.exports = ({ nexus, strapi }) => {
21
21
 
22
22
  koaContext.request.body = toPlainObject(args);
23
23
 
24
- await strapi
25
- .plugin('users-permissions')
26
- .controller('auth')
27
- .forgotPassword(koaContext);
24
+ await strapi.plugin('users-permissions').controller('auth').forgotPassword(koaContext);
28
25
 
29
26
  const output = koaContext.body;
30
27
 
@@ -20,10 +20,7 @@ module.exports = ({ nexus, strapi }) => {
20
20
  koaContext.params = { provider: args.input.provider };
21
21
  koaContext.request.body = toPlainObject(args.input);
22
22
 
23
- await strapi
24
- .plugin('users-permissions')
25
- .controller('auth')
26
- .callback(koaContext);
23
+ await strapi.plugin('users-permissions').controller('auth').callback(koaContext);
27
24
 
28
25
  const output = koaContext.body;
29
26
 
@@ -21,10 +21,7 @@ module.exports = ({ nexus, strapi }) => {
21
21
 
22
22
  koaContext.request.body = toPlainObject(args.input);
23
23
 
24
- await strapi
25
- .plugin('users-permissions')
26
- .controller('auth')
27
- .register(koaContext);
24
+ await strapi.plugin('users-permissions').controller('auth').register(koaContext);
28
25
 
29
26
  const output = koaContext.body;
30
27