@strapi/admin 4.9.0-exp.90df253ba90fd6879eb56a720a1f80d04ff745b8 → 4.9.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 (165) hide show
  1. package/.eslintignore +4 -0
  2. package/.eslintrc.js +14 -0
  3. package/admin/src/components/LocalesProvider/__mocks__/useLocalesProvider.js +7 -0
  4. package/admin/src/content-manager/components/DynamicZone/utils/select.js +1 -1
  5. package/admin/src/content-manager/components/EditViewDataManagerProvider/reducer.js +3 -1
  6. package/admin/src/content-manager/components/EditViewDataManagerProvider/utils/findAllAndReplace.js +10 -3
  7. package/admin/src/content-manager/components/FieldComponent/utils/select.js +2 -1
  8. package/admin/src/content-manager/components/InputUID/endActionStyle.js +4 -13
  9. package/admin/src/content-manager/components/InputUID/index.js +94 -71
  10. package/admin/src/content-manager/components/Inputs/utils/getInputType.js +1 -1
  11. package/admin/src/content-manager/components/Inputs/utils/select.js +1 -1
  12. package/admin/src/content-manager/hooks/useContentTypeLayout/index.js +1 -2
  13. package/admin/src/content-manager/hooks/useFetchContentTypeLayout/utils/formatLayouts.js +4 -1
  14. package/admin/src/content-manager/pages/CollectionTypeRecursivePath/index.js +1 -2
  15. package/admin/src/content-manager/pages/EditSettingsView/init.js +3 -1
  16. package/admin/src/content-manager/pages/EditSettingsView/utils/createPossibleMainFieldsForModelsAndComponents.js +2 -4
  17. package/admin/src/content-manager/pages/EditView/DeleteLink/utils/select.js +1 -1
  18. package/admin/src/content-manager/pages/EditView/utils/createAttributesLayout.js +2 -1
  19. package/admin/src/content-manager/pages/EditView/utils/getFieldsActionMatchingPermissions.js +2 -1
  20. package/admin/src/content-manager/utils/checkIfAttributeIsDisplayable.js +1 -1
  21. package/admin/src/content-manager/utils/createDefaultForm.js +2 -2
  22. package/admin/src/content-manager/utils/formatLayoutToApi.js +2 -1
  23. package/admin/src/content-manager/utils/getFieldName.js +1 -1
  24. package/admin/src/content-manager/utils/mergeMetasWithSchema.js +1 -1
  25. package/admin/src/content-manager/utils/paths.js +1 -1
  26. package/admin/src/content-manager/utils/removePasswordFieldsFromData.js +1 -1
  27. package/admin/src/hooks/useConfigurations/__mocks__/index.js +7 -0
  28. package/admin/src/hooks/useRegenerate/index.js +12 -7
  29. package/admin/src/hooks/useSettingsForm/index.js +3 -3
  30. package/admin/src/hooks/useSettingsForm/reducer.js +3 -1
  31. package/admin/src/hooks/useSettingsMenu/reducer.js +1 -1
  32. package/admin/src/pages/AuthPage/components/Register/index.js +46 -38
  33. package/admin/src/pages/AuthPage/reducer.js +1 -1
  34. package/admin/src/pages/SettingsPage/components/Tokens/FormHead/index.js +4 -0
  35. package/admin/src/pages/SettingsPage/components/Tokens/Regenerate/index.js +5 -3
  36. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/CollapsableContentType/index.js +1 -1
  37. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/reducer.js +1 -1
  38. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/utils/transformPermissionsData.js +6 -8
  39. package/admin/src/pages/SettingsPage/pages/Roles/EditPage/components/ConditionsModal/utils/createDefaultConditionsForm.js +1 -1
  40. package/admin/src/pages/SettingsPage/pages/Roles/EditPage/components/ContentTypeCollapse/Collapse/utils/generateCheckboxesActions.js +2 -1
  41. package/admin/src/pages/SettingsPage/pages/Roles/EditPage/components/ContentTypeCollapse/CollapsePropertyMatrix/ActionRow/utils/getRowLabelCheckboxeState.js +2 -1
  42. package/admin/src/pages/SettingsPage/pages/Roles/EditPage/components/GlobalActions/utils/getRowLabelCheckboxesState.js +1 -1
  43. package/admin/src/pages/SettingsPage/pages/Roles/EditPage/components/Permissions/reducer.js +6 -1
  44. package/admin/src/pages/SettingsPage/pages/Roles/EditPage/components/Permissions/utils/createDefaultCTFormFromLayout.js +5 -1
  45. package/admin/src/pages/SettingsPage/pages/Roles/EditPage/components/Permissions/utils/createDefaultPluginsFormFromLayout.js +1 -2
  46. package/admin/src/pages/SettingsPage/pages/Roles/EditPage/components/Permissions/utils/formatContentTypesPermissionToAPI.js +2 -2
  47. package/admin/src/pages/SettingsPage/pages/Roles/EditPage/components/Permissions/utils/updateConditionsToFalse.js +4 -1
  48. package/admin/src/pages/SettingsPage/pages/Roles/EditPage/components/Permissions/utils/updateValues.js +1 -1
  49. package/admin/src/pages/SettingsPage/pages/Roles/EditPage/components/PluginsAndSettings/SubCategory/utils/formatActions.js +1 -1
  50. package/admin/src/pages/SettingsPage/pages/Roles/EditPage/components/utils/createArrayOfValues.js +2 -1
  51. package/admin/src/pages/SettingsPage/pages/Roles/ListPage/index.js +1 -1
  52. package/admin/src/pages/SettingsPage/pages/TransferTokens/EditView/index.js +47 -5
  53. package/admin/src/pages/SettingsPage/pages/TransferTokens/ListView/index.js +27 -5
  54. package/admin/src/pages/SettingsPage/pages/Users/ProtectedEditPage/index.js +2 -2
  55. package/admin/src/pages/SettingsPage/pages/Webhooks/EditView/utils/formatData.js +1 -7
  56. package/admin/src/permissions/index.js +1 -1
  57. package/admin/src/translations/en.json +1 -0
  58. package/admin/src/utils/getAttributesToDisplay.js +2 -4
  59. package/admin/src/utils/getExistingActions.js +1 -3
  60. package/admin/src/utils/sortLinks.js +1 -1
  61. package/build/1387.84b454d3.chunk.js +1 -0
  62. package/build/1657.45231968.chunk.js +168 -0
  63. package/build/3081.bcf9a12f.chunk.js +108 -0
  64. package/build/462.8fff7f3b.chunk.js +71 -0
  65. package/build/4628.20631dd1.chunk.js +1 -0
  66. package/build/5542.b8240e3f.chunk.js +70 -0
  67. package/build/5563.905daa13.chunk.js +79 -0
  68. package/build/6404.68405699.chunk.js +100 -0
  69. package/build/7259.b7d00cea.chunk.js +1 -0
  70. package/build/8694.6522968d.chunk.js +247 -0
  71. package/build/9347.058ddb22.chunk.js +1 -0
  72. package/build/Admin-authenticatedApp.31bf88ef.chunk.js +79 -0
  73. package/build/Admin_InternalErrorPage.15c6bf07.chunk.js +1 -0
  74. package/build/Admin_homePage.da2181fe.chunk.js +73 -0
  75. package/build/Admin_marketplace.d99044eb.chunk.js +31 -0
  76. package/build/Admin_pluginsPage.f6b52ee9.chunk.js +6 -0
  77. package/build/Admin_profilePage.9112cffc.chunk.js +15 -0
  78. package/build/Admin_settingsPage.cb63220f.chunk.js +79 -0
  79. package/build/Upload_ConfigureTheView.eaaec495.chunk.js +1 -0
  80. package/build/admin-app.8cde5b22.chunk.js +110 -0
  81. package/build/admin-edit-roles-page.4f1858e9.chunk.js +280 -0
  82. package/build/admin-edit-users.7e14d85f.chunk.js +10 -0
  83. package/build/admin-roles-list.97e198f9.chunk.js +31 -0
  84. package/build/admin-users.d02de059.chunk.js +34 -0
  85. package/build/api-tokens-create-page.97595e12.chunk.js +1 -0
  86. package/build/api-tokens-edit-page.cd36e30e.chunk.js +1 -0
  87. package/build/api-tokens-list-page.6757c7b9.chunk.js +16 -0
  88. package/build/audit-logs-settings-page.ca9a3c46.chunk.js +76 -0
  89. package/build/content-manager.de0ee3e5.chunk.js +1132 -0
  90. package/build/content-type-builder-list-view.9c2c020c.chunk.js +214 -0
  91. package/build/content-type-builder.ec5ac7ab.chunk.js +126 -0
  92. package/build/email-settings-page.1095e1ab.chunk.js +10 -0
  93. package/build/{en-json.01a88a30.chunk.js → en-json.b052667a.chunk.js} +1 -1
  94. package/build/{highlight.js.26ef649f.chunk.js → highlight.js.28a1547e.chunk.js} +2 -2
  95. package/build/i18n-settings-page.7d80aae0.chunk.js +60 -0
  96. package/build/index.html +1 -1
  97. package/build/main.d40f9ca1.js +2280 -0
  98. package/build/{runtime~main.a40b1b57.js → runtime~main.7cdc9956.js} +1 -1
  99. package/build/sso-settings-page.1dd4886e.chunk.js +1 -0
  100. package/build/transfer-tokens-create-page.ec2ca215.chunk.js +1 -0
  101. package/build/transfer-tokens-edit-page.22bf28e5.chunk.js +1 -0
  102. package/build/transfer-tokens-list-page.cf8c77f2.chunk.js +16 -0
  103. package/build/upload-settings.945fdcfa.chunk.js +13 -0
  104. package/build/upload-translation-fr-json.baab9911.chunk.js +1 -0
  105. package/build/{upload-translation-th-json.3847dae0.chunk.js → upload-translation-th-json.98d35574.chunk.js} +1 -1
  106. package/build/upload.a86b1054.chunk.js +33 -0
  107. package/build/users-advanced-settings-page.5b5a9baa.chunk.js +8 -0
  108. package/build/users-email-settings-page.e5506eb4.chunk.js +23 -0
  109. package/build/users-providers-settings-page.e32089c2.chunk.js +28 -0
  110. package/build/users-roles-settings-page.a5c5b0df.chunk.js +30 -0
  111. package/build/webhook-edit-page.213f0075.chunk.js +75 -0
  112. package/build/webhook-list-page.5beb2a5c.chunk.js +71 -0
  113. package/ee/server/bootstrap.js +3 -0
  114. package/ee/server/register.js +3 -2
  115. package/ee/server/services/audit-logs.js +75 -16
  116. package/ee/server/utils/persisted-tables.js +49 -0
  117. package/jest.config.front.js +1 -6
  118. package/package.json +21 -19
  119. package/server/middlewares/data-transfer.js +4 -1
  120. package/server/services/permission/permissions-manager/sanitize.js +2 -0
  121. package/webpack.config.js +1 -1
  122. package/build/2637.679b590b.chunk.js +0 -1
  123. package/build/4049.64715f20.chunk.js +0 -1
  124. package/build/5563.451e91ee.chunk.js +0 -30
  125. package/build/7112.2bf13da3.chunk.js +0 -14
  126. package/build/7259.7744297b.chunk.js +0 -1
  127. package/build/8469.853c822b.chunk.js +0 -1
  128. package/build/8580.b0dcf37c.chunk.js +0 -98
  129. package/build/9816.01ee964f.chunk.js +0 -2
  130. package/build/Admin-authenticatedApp.5aa08bf5.chunk.js +0 -79
  131. package/build/Admin_InternalErrorPage.4ad8b0df.chunk.js +0 -1
  132. package/build/Admin_homePage.1411fb7c.chunk.js +0 -68
  133. package/build/Admin_marketplace.0f6c8ee2.chunk.js +0 -22
  134. package/build/Admin_pluginsPage.15e3b0fd.chunk.js +0 -1
  135. package/build/Admin_profilePage.d2a8f9ab.chunk.js +0 -15
  136. package/build/Admin_settingsPage.489ec4eb.chunk.js +0 -9
  137. package/build/Upload_ConfigureTheView.34dde278.chunk.js +0 -1
  138. package/build/admin-app.4b313104.chunk.js +0 -112
  139. package/build/admin-edit-roles-page.3b196317.chunk.js +0 -216
  140. package/build/admin-edit-users.af3b0f15.chunk.js +0 -10
  141. package/build/admin-roles-list.0ad504a7.chunk.js +0 -2
  142. package/build/admin-users.af8c3123.chunk.js +0 -11
  143. package/build/api-tokens-create-page.2a6e22bd.chunk.js +0 -1
  144. package/build/api-tokens-edit-page.fa38cd63.chunk.js +0 -1
  145. package/build/api-tokens-list-page.93f24348.chunk.js +0 -16
  146. package/build/audit-logs-settings-page.7be97e82.chunk.js +0 -1
  147. package/build/content-manager.f530e141.chunk.js +0 -1139
  148. package/build/content-type-builder-list-view.cf38fe2f.chunk.js +0 -191
  149. package/build/content-type-builder.6ecd201d.chunk.js +0 -126
  150. package/build/email-settings-page.4bdbef9a.chunk.js +0 -3
  151. package/build/i18n-settings-page.2bb5be96.chunk.js +0 -1
  152. package/build/main.43b93ff3.js +0 -3843
  153. package/build/sso-settings-page.5a8588ef.chunk.js +0 -1
  154. package/build/transfer-tokens-create-page.a1f14bb1.chunk.js +0 -1
  155. package/build/transfer-tokens-edit-page.00ee1c74.chunk.js +0 -1
  156. package/build/transfer-tokens-list-page.ce37354b.chunk.js +0 -16
  157. package/build/upload-settings.0200561d.chunk.js +0 -1
  158. package/build/upload-translation-fr-json.84429734.chunk.js +0 -1
  159. package/build/upload.c7da1611.chunk.js +0 -13
  160. package/build/users-advanced-settings-page.c0cae03a.chunk.js +0 -1
  161. package/build/users-email-settings-page.a3c80419.chunk.js +0 -1
  162. package/build/users-providers-settings-page.5f86e45c.chunk.js +0 -1
  163. package/build/users-roles-settings-page.b02986df.chunk.js +0 -30
  164. package/build/webhook-edit-page.a2a2b7bb.chunk.js +0 -23
  165. package/build/webhook-list-page.029957a4.chunk.js +0 -1
@@ -1,7 +1,6 @@
1
1
  import React, { useState, useEffect } from 'react';
2
2
  import { useIntl } from 'react-intl';
3
3
  import styled from 'styled-components';
4
- import get from 'lodash/get';
5
4
  import omit from 'lodash/omit';
6
5
  import { useHistory } from 'react-router-dom';
7
6
  import PropTypes from 'prop-types';
@@ -14,6 +13,7 @@ import {
14
13
  useTracking,
15
14
  getYupInnerErrors,
16
15
  Link,
16
+ useAPIErrorHandler,
17
17
  } from '@strapi/helper-plugin';
18
18
  import {
19
19
  Box,
@@ -27,17 +27,10 @@ import {
27
27
  Typography,
28
28
  } from '@strapi/design-system';
29
29
  import { EyeStriked, Eye } from '@strapi/icons';
30
- import UnauthenticatedLayout, {
31
- Column,
32
- LayoutContent,
33
- } from '../../../../layouts/UnauthenticatedLayout';
30
+ import UnauthenticatedLayout, { LayoutContent } from '../../../../layouts/UnauthenticatedLayout';
34
31
  import Logo from '../../../../components/UnauthenticatedLogo';
35
32
  import FieldActionWrapper from '../FieldActionWrapper';
36
33
 
37
- const CenteredBox = styled(Box)`
38
- text-align: center;
39
- `;
40
-
41
34
  const A = styled.a`
42
35
  color: ${({ theme }) => theme.colors.primary600};
43
36
  `;
@@ -58,6 +51,8 @@ const Register = ({ authType, fieldsToDisable, noSignin, onSubmit, schema }) =>
58
51
  const { trackUsage } = useTracking();
59
52
  const { formatMessage } = useIntl();
60
53
  const query = useQuery();
54
+ const { formatAPIError } = useAPIErrorHandler();
55
+
61
56
  const registrationToken = query.get('registrationToken');
62
57
 
63
58
  useEffect(() => {
@@ -73,17 +68,17 @@ const Register = ({ authType, fieldsToDisable, noSignin, onSubmit, schema }) =>
73
68
  if (data) {
74
69
  setUserInfo(data);
75
70
  }
76
- } catch (err) {
77
- const errorMessage = get(err, ['response', 'data', 'message'], 'An error occurred');
71
+ } catch (error) {
72
+ const message = formatAPIError(error);
78
73
 
79
74
  toggleNotification({
80
75
  type: 'warning',
81
- message: errorMessage,
76
+ message,
82
77
  });
83
78
 
84
79
  // Redirect to the oops page in case of an invalid token
85
80
  // @alexandrebodin @JAB I am not sure it is the wanted behavior
86
- push(`/auth/oops?info=${encodeURIComponent(errorMessage)}`);
81
+ push(`/auth/oops?info=${encodeURIComponent(message)}`);
87
82
  }
88
83
  };
89
84
 
@@ -92,6 +87,20 @@ const Register = ({ authType, fieldsToDisable, noSignin, onSubmit, schema }) =>
92
87
  // eslint-disable-next-line react-hooks/exhaustive-deps
93
88
  }, [registrationToken]);
94
89
 
90
+ function normalizeData(data) {
91
+ return Object.entries(data).reduce((acc, [key, value]) => {
92
+ let normalizedvalue = value;
93
+
94
+ if (!['password', 'confirmPassword'].includes(key) && typeof value === 'string') {
95
+ normalizedvalue = normalizedvalue.trim();
96
+ }
97
+
98
+ acc[key] = normalizedvalue;
99
+
100
+ return acc;
101
+ }, {});
102
+ }
103
+
95
104
  return (
96
105
  <UnauthenticatedLayout>
97
106
  <LayoutContent>
@@ -107,8 +116,10 @@ const Register = ({ authType, fieldsToDisable, noSignin, onSubmit, schema }) =>
107
116
  news: false,
108
117
  }}
109
118
  onSubmit={async (data, formik) => {
119
+ const normalizedData = normalizeData(data);
120
+
110
121
  try {
111
- await schema.validate(data, { abortEarly: false });
122
+ await schema.validate(normalizedData, { abortEarly: false });
112
123
 
113
124
  if (submitCount > 0 && authType === 'register-admin') {
114
125
  trackUsage('didSubmitWithErrorsFirstAdmin', { count: submitCount.toString() });
@@ -117,11 +128,11 @@ const Register = ({ authType, fieldsToDisable, noSignin, onSubmit, schema }) =>
117
128
  if (registrationToken) {
118
129
  // We need to pass the registration token in the url param to the api in order to submit another admin user
119
130
  onSubmit(
120
- { userInfo: omit(data, ['registrationToken']), registrationToken },
131
+ { userInfo: omit(normalizedData, ['registrationToken']), registrationToken },
121
132
  formik
122
133
  );
123
134
  } else {
124
- onSubmit(data, formik);
135
+ onSubmit(normalizedData, formik);
125
136
  }
126
137
  } catch (err) {
127
138
  const errors = getYupInnerErrors(err);
@@ -138,27 +149,26 @@ const Register = ({ authType, fieldsToDisable, noSignin, onSubmit, schema }) =>
138
149
  return (
139
150
  <Form noValidate>
140
151
  <Main>
141
- <Column>
152
+ <Flex direction="column" alignItems="stretch" gap={3}>
142
153
  <Logo />
143
- <Box paddingTop={6} paddingBottom={1}>
144
- <Typography as="h1" variant="alpha">
145
- {formatMessage({
146
- id: 'Auth.form.welcome.title',
147
- defaultMessage: 'Welcome to Strapi!',
148
- })}
149
- </Typography>
150
- </Box>
151
- <CenteredBox paddingBottom={7}>
152
- <Typography variant="epsilon" textColor="neutral600">
153
- {formatMessage({
154
- id: 'Auth.form.register.subtitle',
155
- defaultMessage:
156
- 'Credentials are only used to authenticate in Strapi. All saved data will be stored in your database.',
157
- })}
158
- </Typography>
159
- </CenteredBox>
160
- </Column>
161
- <Flex direction="column" alignItems="stretch" gap={6}>
154
+
155
+ <Typography as="h1" variant="alpha" textAlign="center">
156
+ {formatMessage({
157
+ id: 'Auth.form.welcome.title',
158
+ defaultMessage: 'Welcome to Strapi!',
159
+ })}
160
+ </Typography>
161
+
162
+ <Typography variant="epsilon" textColor="neutral600" textAlign="center">
163
+ {formatMessage({
164
+ id: 'Auth.form.register.subtitle',
165
+ defaultMessage:
166
+ 'Credentials are only used to authenticate in Strapi. All saved data will be stored in your database.',
167
+ })}
168
+ </Typography>
169
+ </Flex>
170
+
171
+ <Flex direction="column" alignItems="stretch" gap={6} marginTop={7}>
162
172
  <Grid gap={4}>
163
173
  <GridItem col={6}>
164
174
  <TextInput
@@ -204,7 +214,6 @@ const Register = ({ authType, fieldsToDisable, noSignin, onSubmit, schema }) =>
204
214
  value={values.password}
205
215
  error={errors.password ? formatMessage(errors.password) : undefined}
206
216
  endAction={
207
- // eslint-disable-next-line react/jsx-wrap-multilines
208
217
  <FieldActionWrapper
209
218
  onClick={(e) => {
210
219
  e.preventDefault();
@@ -245,7 +254,6 @@ const Register = ({ authType, fieldsToDisable, noSignin, onSubmit, schema }) =>
245
254
  errors.confirmPassword ? formatMessage(errors.confirmPassword) : undefined
246
255
  }
247
256
  endAction={
248
- // eslint-disable-next-line react/jsx-wrap-multilines
249
257
  <FieldActionWrapper
250
258
  onClick={(e) => {
251
259
  e.preventDefault();
@@ -1,5 +1,5 @@
1
1
  import produce from 'immer';
2
- import { set } from 'lodash';
2
+ import set from 'lodash/set';
3
3
  /* eslint-disable consistent-return */
4
4
 
5
5
  const initialState = {
@@ -15,6 +15,7 @@ const FormHead = ({
15
15
  isSubmitting,
16
16
  backUrl,
17
17
  regenerateUrl,
18
+ onErrorRegenerate,
18
19
  }) => {
19
20
  const { formatMessage } = useIntl();
20
21
  const handleRegenerate = (newKey) => {
@@ -35,6 +36,7 @@ const FormHead = ({
35
36
  backUrl={regenerateUrl}
36
37
  onRegenerate={handleRegenerate}
37
38
  idToRegenerate={token?.id}
39
+ onError={onErrorRegenerate}
38
40
  />
39
41
  )}
40
42
  <Button
@@ -95,10 +97,12 @@ FormHead.propTypes = {
95
97
  label: PropTypes.string,
96
98
  }).isRequired,
97
99
  regenerateUrl: PropTypes.string.isRequired,
100
+ onErrorRegenerate: PropTypes.func,
98
101
  };
99
102
 
100
103
  FormHead.defaultProps = {
101
104
  token: undefined,
105
+ onErrorRegenerate: undefined,
102
106
  };
103
107
 
104
108
  export default FormHead;
@@ -6,13 +6,14 @@ import { Refresh } from '@strapi/icons';
6
6
  import { ConfirmDialog } from '@strapi/helper-plugin';
7
7
  import { useRegenerate } from '../../../../../hooks';
8
8
 
9
- export const Regenerate = ({ onRegenerate, idToRegenerate, backUrl }) => {
9
+ export const Regenerate = ({ onRegenerate, idToRegenerate, backUrl, onError }) => {
10
10
  const { formatMessage } = useIntl();
11
11
  const [showConfirmDialog, setShowConfirmDialog] = useState(false);
12
12
  const { regenerateData, isLoadingConfirmation } = useRegenerate(
13
13
  backUrl,
14
14
  idToRegenerate,
15
- onRegenerate
15
+ onRegenerate,
16
+ onError
16
17
  );
17
18
  const handleConfirmRegeneration = async () => {
18
19
  regenerateData();
@@ -62,12 +63,13 @@ export const Regenerate = ({ onRegenerate, idToRegenerate, backUrl }) => {
62
63
  );
63
64
  };
64
65
 
65
- Regenerate.defaultProps = { onRegenerate() {} };
66
+ Regenerate.defaultProps = { onRegenerate() {}, onError: undefined };
66
67
 
67
68
  Regenerate.propTypes = {
68
69
  onRegenerate: PropTypes.func,
69
70
  idToRegenerate: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
70
71
  backUrl: PropTypes.string.isRequired,
72
+ onError: PropTypes.func,
71
73
  };
72
74
 
73
75
  export default Regenerate;
@@ -1,5 +1,5 @@
1
1
  import React, { useState, useEffect } from 'react';
2
- import { capitalize } from 'lodash';
2
+ import capitalize from 'lodash/capitalize';
3
3
  import { useIntl } from 'react-intl';
4
4
  import {
5
5
  Accordion,
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable consistent-return */
2
2
  import produce from 'immer';
3
- import { pull } from 'lodash';
3
+ import pull from 'lodash/pull';
4
4
  import { transformPermissionsData } from './utils';
5
5
 
6
6
  export const initialState = {
@@ -1,5 +1,3 @@
1
- import { flatten } from 'lodash';
2
-
3
1
  const transformPermissionsData = (data) => {
4
2
  const layout = {
5
3
  allActionsIds: [],
@@ -9,11 +7,11 @@ const transformPermissionsData = (data) => {
9
7
  layout.permissions = Object.keys(data).map((apiId) => ({
10
8
  apiId,
11
9
  label: apiId.split('::')[1],
12
- controllers: flatten(
13
- Object.keys(data[apiId].controllers).map((controller) => ({
10
+ controllers: Object.keys(data[apiId].controllers)
11
+ .map((controller) => ({
14
12
  controller,
15
- actions: flatten(
16
- data[apiId].controllers[controller].map((action) => {
13
+ actions: data[apiId].controllers[controller]
14
+ .map((action) => {
17
15
  const actionId = `${apiId}.${controller}.${action}`;
18
16
 
19
17
  if (apiId.includes('api::')) {
@@ -25,9 +23,9 @@ const transformPermissionsData = (data) => {
25
23
  actionId,
26
24
  };
27
25
  })
28
- ),
26
+ .flat(),
29
27
  }))
30
- ),
28
+ .flat(),
31
29
  }));
32
30
 
33
31
  return layout;
@@ -1,4 +1,4 @@
1
- import { get } from 'lodash';
1
+ import get from 'lodash/get';
2
2
 
3
3
  const createConditionsForm = (conditions, valueObject) => {
4
4
  return conditions.reduce((acc, current) => {
@@ -1,4 +1,5 @@
1
- import { get, isEmpty } from 'lodash';
1
+ import get from 'lodash/get';
2
+ import isEmpty from 'lodash/isEmpty';
2
3
  import { createArrayOfValues, getCheckboxState } from '../../../utils';
3
4
 
4
5
  const generateCheckboxesActions = (availableActions, modifiedData, pathToData) => {
@@ -1,4 +1,5 @@
1
- import { get } from 'lodash';
1
+ import get from 'lodash/get';
2
+
2
3
  import { getCheckboxState } from '../../../../utils';
3
4
 
4
5
  /**
@@ -1,4 +1,4 @@
1
- import { get } from 'lodash';
1
+ import get from 'lodash/get';
2
2
  import { getCheckboxState, removeConditionKeyFromData } from '../../utils';
3
3
 
4
4
  const getActionsIds = (array) => array.map(({ actionId }) => actionId);
@@ -1,5 +1,10 @@
1
1
  import produce from 'immer';
2
- import { cloneDeep, has, isObject, get, set } from 'lodash';
2
+ import cloneDeep from 'lodash/cloneDeep';
3
+ import has from 'lodash/has';
4
+ import isObject from 'lodash/isObject';
5
+ import get from 'lodash/get';
6
+ import set from 'lodash/set';
7
+
3
8
  import updateConditionsToFalse from './utils/updateConditionsToFalse';
4
9
  import updateValues from './utils/updateValues';
5
10
 
@@ -1,4 +1,8 @@
1
- import { merge, get, isEmpty, set } from 'lodash';
1
+ import get from 'lodash/get';
2
+ import isEmpty from 'lodash/isEmpty';
3
+ import merge from 'lodash/merge';
4
+ import set from 'lodash/set';
5
+
2
6
  import findMatchingPermission from './findMatchingPermissions';
3
7
  /**
4
8
  * Creates the default condition form: { [conditionId]: false }
@@ -1,4 +1,3 @@
1
- import { get } from 'lodash';
2
1
  import { createDefaultConditionsForm } from './createDefaultCTFormFromLayout';
3
2
  import findMatchingPermission from './findMatchingPermissions';
4
3
 
@@ -12,7 +11,7 @@ const createSubCategoryForm = (actions, conditions, permissions) => {
12
11
  },
13
12
  conditions: createDefaultConditionsForm(
14
13
  conditions,
15
- get(foundMatchingPermission, 'conditions', [])
14
+ foundMatchingPermission?.conditions ?? []
16
15
  ),
17
16
  };
18
17
 
@@ -1,4 +1,4 @@
1
- import { has, isObject } from 'lodash';
1
+ import isObject from 'lodash/isObject';
2
2
  import { createArrayOfValues } from '../../utils';
3
3
  import { createConditionsArray } from './formatSettingsPermissionsToAPI';
4
4
 
@@ -77,7 +77,7 @@ const createSubjectPermissions = (subject, actions) => {
77
77
  return acc;
78
78
  }
79
79
 
80
- if (!has(permissions, 'properties.enabled')) {
80
+ if (!permissions?.properties?.enabled) {
81
81
  const createdPermissionsArray = createPermissionWithProperties(
82
82
  actionName,
83
83
  subject,
@@ -1,4 +1,7 @@
1
- import { isObject, has, omit } from 'lodash';
1
+ import isObject from 'lodash/isObject';
2
+ import has from 'lodash/has';
3
+ import omit from 'lodash/omit';
4
+
2
5
  import { createArrayOfValues } from '../../utils';
3
6
 
4
7
  /**
@@ -1,4 +1,4 @@
1
- import { isObject } from 'lodash';
1
+ import isObject from 'lodash/isObject';
2
2
 
3
3
  /**
4
4
  * Sets all the none object values of an object to the given one
@@ -1,4 +1,4 @@
1
- import { get } from 'lodash';
1
+ import get from 'lodash/get';
2
2
  import { createArrayOfValues } from '../../../utils';
3
3
 
4
4
  /**
@@ -1,4 +1,5 @@
1
- import { flattenDeep, isObject } from 'lodash';
1
+ import flattenDeep from 'lodash/flattenDeep';
2
+ import isObject from 'lodash/isObject';
2
3
 
3
4
  const createArrayOfValues = (obj) => {
4
5
  if (!isObject(obj)) {
@@ -26,7 +26,7 @@ import {
26
26
  Typography,
27
27
  VisuallyHidden,
28
28
  } from '@strapi/design-system';
29
- import { get } from 'lodash';
29
+ import get from 'lodash/get';
30
30
  import matchSorter from 'match-sorter';
31
31
  import { useIntl } from 'react-intl';
32
32
  import { useHistory } from 'react-router-dom';
@@ -13,6 +13,7 @@ import {
13
13
  useGuidedTour,
14
14
  useRBAC,
15
15
  useFetchClient,
16
+ useAPIErrorHandler,
16
17
  } from '@strapi/helper-plugin';
17
18
  import { ContentLayout, Main, Flex } from '@strapi/design-system';
18
19
  import { formatAPIErrors } from '../../../../../utils';
@@ -52,6 +53,8 @@ const TransferTokenCreateView = () => {
52
53
 
53
54
  const isCreating = id === 'create';
54
55
 
56
+ const { formatAPIError } = useAPIErrorHandler();
57
+
55
58
  useEffect(() => {
56
59
  trackUsageRef.current(isCreating ? 'didAddTokenFromList' : 'didEditTokenFromList', {
57
60
  tokenType: TRANSFER_TOKEN_TYPE,
@@ -73,11 +76,22 @@ const TransferTokenCreateView = () => {
73
76
  },
74
77
  {
75
78
  enabled: !isCreating && !transferToken,
76
- onError() {
77
- toggleNotification({
78
- type: 'warning',
79
- message: { id: 'notification.error', defaultMessage: 'An error occured' },
80
- });
79
+ onError(err) {
80
+ if (err.response.data.error.details?.code === 'INVALID_TOKEN_SALT') {
81
+ toggleNotification({
82
+ type: 'warning',
83
+ message: {
84
+ id: 'notification.error.invalid.configuration',
85
+ defaultMessage:
86
+ 'You have an invalid configuration, check your server log for more information.',
87
+ },
88
+ });
89
+ } else {
90
+ toggleNotification({
91
+ type: 'warning',
92
+ message: formatAPIError(err),
93
+ });
94
+ }
81
95
  },
82
96
  }
83
97
  );
@@ -145,6 +159,15 @@ const TransferTokenCreateView = () => {
145
159
  type: 'warning',
146
160
  message: err.response.data.message || 'notification.error.tokennamenotunique',
147
161
  });
162
+ } else if (err?.response?.data?.error?.details?.code === 'INVALID_TOKEN_SALT') {
163
+ toggleNotification({
164
+ type: 'warning',
165
+ message: {
166
+ id: 'notification.error.invalid.configuration',
167
+ defaultMessage:
168
+ 'You have an invalid configuration, check your server log for more information.',
169
+ },
170
+ });
148
171
  } else {
149
172
  toggleNotification({
150
173
  type: 'warning',
@@ -162,6 +185,24 @@ const TransferTokenCreateView = () => {
162
185
  return <LoadingView transferTokenName={transferToken?.name} />;
163
186
  }
164
187
 
188
+ const handleErrorRegenerate = (err) => {
189
+ if (err?.response?.data?.error?.details?.code === 'INVALID_TOKEN_SALT') {
190
+ toggleNotification({
191
+ type: 'warning',
192
+ message: {
193
+ id: 'notification.error.invalid.configuration',
194
+ defaultMessage:
195
+ 'You have an invalid configuration, check your server log for more information.',
196
+ },
197
+ });
198
+ } else {
199
+ toggleNotification({
200
+ type: 'warning',
201
+ message: formatAPIError(err),
202
+ });
203
+ }
204
+ };
205
+
165
206
  return (
166
207
  <Main>
167
208
  <SettingsPageTitle name="Transfer Tokens" />
@@ -194,6 +235,7 @@ const TransferTokenCreateView = () => {
194
235
  canRegenerate={canRegenerate}
195
236
  isSubmitting={isSubmitting}
196
237
  regenerateUrl="/admin/transfer/tokens/"
238
+ onErrorRegenerate={handleErrorRegenerate}
197
239
  />
198
240
  <ContentLayout>
199
241
  <Flex direction="column" alignItems="stretch" gap={6}>
@@ -77,11 +77,24 @@ const TransferTokenListView = () => {
77
77
  },
78
78
  {
79
79
  enabled: canRead,
80
- onError() {
81
- toggleNotification({
82
- type: 'warning',
83
- message: { id: 'notification.error', defaultMessage: 'An error occured' },
84
- });
80
+ onError(err) {
81
+ console.log('error', err);
82
+
83
+ if (err?.response?.data?.error?.details?.code === 'INVALID_TOKEN_SALT') {
84
+ toggleNotification({
85
+ type: 'warning',
86
+ message: {
87
+ id: 'notification.error.invalid.configuration',
88
+ defaultMessage:
89
+ 'You have an invalid configuration, check your server log for more information.',
90
+ },
91
+ });
92
+ } else {
93
+ toggleNotification({
94
+ type: 'warning',
95
+ message: { id: 'notification.error', defaultMessage: 'An error occured' },
96
+ });
97
+ }
85
98
  },
86
99
  }
87
100
  );
@@ -101,6 +114,15 @@ const TransferTokenListView = () => {
101
114
  onError(err) {
102
115
  if (err?.response?.data?.data) {
103
116
  toggleNotification({ type: 'warning', message: err.response.data.data });
117
+ } else if (err?.response?.data?.error?.details?.code === 'INVALID_TOKEN_SALT') {
118
+ toggleNotification({
119
+ type: 'warning',
120
+ message: {
121
+ id: 'notification.error.invalid.configuration',
122
+ defaultMessage:
123
+ 'You have an invalid configuration, check your server log for more information.',
124
+ },
125
+ });
104
126
  } else {
105
127
  toggleNotification({
106
128
  type: 'warning',
@@ -1,7 +1,7 @@
1
1
  import React, { useEffect, useMemo } from 'react';
2
2
  import { useRBAC, LoadingIndicatorPage, useNotification } from '@strapi/helper-plugin';
3
3
  import { Redirect, useLocation } from 'react-router-dom';
4
- import { get } from 'lodash';
4
+
5
5
  import adminPermissions from '../../../../../permissions';
6
6
  import EditPage from '../EditPage';
7
7
 
@@ -19,7 +19,7 @@ const ProtectedEditPage = () => {
19
19
  allowedActions: { canRead, canUpdate },
20
20
  } = useRBAC(permissions);
21
21
  const { state } = useLocation();
22
- const from = get(state, 'from', '/');
22
+ const from = state?.from ?? '/';
23
23
 
24
24
  useEffect(() => {
25
25
  if (!isLoading) {
@@ -1,11 +1,5 @@
1
- import { set } from 'lodash';
2
-
3
1
  const cleanData = (data) => {
4
- const webhooks = { ...data };
5
-
6
- set(webhooks, 'headers', unformatHeaders(data.headers));
7
-
8
- return webhooks;
2
+ return { ...data, headers: unformatHeaders(data.headers) };
9
3
  };
10
4
 
11
5
  const unformatHeaders = (headers) => {
@@ -1,4 +1,4 @@
1
- import { merge } from 'lodash';
1
+ import merge from 'lodash/merge';
2
2
  import customPermissions from 'ee_else_ce/permissions/customPermissions';
3
3
  import defaultPermissions from './defaultPermissions';
4
4
 
@@ -878,6 +878,7 @@
878
878
  "notification.success.transfertokencreated": "Transfer Token successfully created",
879
879
  "notification.success.transfertokenedited": "Transfer Token successfully edited",
880
880
  "notification.error.tokennamenotunique": "Name already assigned to another token",
881
+ "notification.error.invalid.configuration": "You have an invalid configuration, check your server log for more information.",
881
882
  "notification.version.update.message": "A new version of Strapi is available!",
882
883
  "notification.warning.title": "Warning:",
883
884
  "notification.warning.404": "404 - Not found",
@@ -1,13 +1,11 @@
1
- import { get } from 'lodash';
2
-
3
1
  const getAttributesToDisplay = (contentType) => {
4
- const timestamps = get(contentType, ['options', 'timestamps']);
2
+ const timestamps = contentType?.options?.timestamps;
5
3
 
6
4
  // Sometimes timestamps is false
7
5
  let timestampsArray = Array.isArray(timestamps) ? timestamps : [];
8
6
  const idsAttributes = ['id', '_id']; // For both SQL and mongo
9
7
  const unwritableAttributes = [...idsAttributes, ...timestampsArray, 'publishedAt'];
10
- const schemaAttributes = get(contentType, ['attributes'], {});
8
+ const schemaAttributes = contentType?.attributes ?? {};
11
9
 
12
10
  return Object.keys(schemaAttributes).reduce((acc, current) => {
13
11
  if (!unwritableAttributes.includes(current)) {
@@ -1,5 +1,3 @@
1
- import { get } from 'lodash';
2
-
3
1
  const getExistingActions = (permissions) => {
4
2
  return Array.from(
5
3
  new Set(
@@ -23,7 +21,7 @@ const getExistingActions = (permissions) => {
23
21
  ...acc,
24
22
  ...getActionsPermission([
25
23
  ...Object.values(current[1].attributes || {}),
26
- get(current[1], 'contentTypeActions', {}),
24
+ current[1]?.contentTypeActions ?? {},
27
25
  ]),
28
26
  ];
29
27
  }, [])
@@ -1,4 +1,4 @@
1
- import { sortBy } from 'lodash';
1
+ import sortBy from 'lodash/sortBy';
2
2
 
3
3
  const sortLinks = (links) => sortBy(links, (object) => object.name);
4
4