@strapi/admin 4.4.0-rc.0 → 4.5.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 (203) hide show
  1. package/admin/src/StrapiApp.js +12 -4
  2. package/admin/src/components/Providers/index.js +10 -14
  3. package/admin/src/content-manager/components/CollectionTypeFormWrapper/index.js +11 -1
  4. package/admin/src/content-manager/components/DynamicTable/CellContent/RelationMultiple/index.js +11 -7
  5. package/admin/src/content-manager/components/DynamicTable/CellContent/index.js +6 -5
  6. package/admin/src/content-manager/components/DynamicTable/TableRows/index.js +5 -0
  7. package/admin/src/content-manager/components/DynamicTable/index.js +1 -1
  8. package/admin/src/content-manager/components/EditViewDataManagerProvider/index.js +23 -17
  9. package/admin/src/content-manager/components/EditViewDataManagerProvider/reducer.js +123 -24
  10. package/admin/src/content-manager/components/EditViewDataManagerProvider/utils/cleanData.js +17 -1
  11. package/admin/src/content-manager/components/FieldTypeIcon/index.js +1 -31
  12. package/admin/src/content-manager/components/Inputs/index.js +22 -36
  13. package/admin/src/content-manager/components/RelationInput/RelationInput.js +364 -0
  14. package/admin/src/content-manager/components/{SelectWrapper → RelationInput/components}/Option.js +15 -25
  15. package/admin/src/content-manager/components/RelationInput/components/Relation.js +48 -0
  16. package/admin/src/content-manager/components/RelationInput/components/RelationItem.js +52 -0
  17. package/admin/src/content-manager/components/RelationInput/components/RelationList.js +52 -0
  18. package/admin/src/content-manager/components/RelationInput/constants.js +1 -0
  19. package/admin/src/content-manager/components/RelationInput/index.js +1 -0
  20. package/admin/src/content-manager/components/RelationInputDataManager/RelationInputDataManager.js +250 -0
  21. package/admin/src/content-manager/components/RelationInputDataManager/constants.js +8 -0
  22. package/admin/src/content-manager/components/RelationInputDataManager/index.js +1 -0
  23. package/admin/src/content-manager/components/{SelectWrapper → RelationInputDataManager}/utils/connect.js +0 -1
  24. package/admin/src/content-manager/components/RelationInputDataManager/utils/getRelationLink.js +5 -0
  25. package/admin/src/content-manager/components/{SelectWrapper → RelationInputDataManager}/utils/index.js +1 -0
  26. package/admin/src/content-manager/components/RelationInputDataManager/utils/normalizeRelations.js +58 -0
  27. package/admin/src/content-manager/components/{SelectWrapper → RelationInputDataManager}/utils/select.js +31 -1
  28. package/admin/src/content-manager/components/SingleTypeFormWrapper/index.js +19 -2
  29. package/admin/src/content-manager/hooks/useFetchContentTypeLayout/utils/formatLayouts.js +7 -69
  30. package/admin/src/content-manager/hooks/useRelation/index.js +1 -0
  31. package/admin/src/content-manager/hooks/useRelation/useRelation.js +73 -0
  32. package/admin/src/content-manager/pages/EditSettingsView/components/DisplayedFields.js +4 -4
  33. package/admin/src/content-manager/pages/EditSettingsView/components/FormModal.js +2 -7
  34. package/admin/src/content-manager/pages/EditSettingsView/index.js +22 -51
  35. package/admin/src/content-manager/pages/EditSettingsView/reducer.js +0 -25
  36. package/admin/src/content-manager/pages/EditView/Header/index.js +3 -90
  37. package/admin/src/content-manager/pages/EditView/Header/utils/index.js +0 -1
  38. package/admin/src/content-manager/pages/EditView/Header/utils/select.js +0 -2
  39. package/admin/src/content-manager/pages/EditView/index.js +93 -155
  40. package/admin/src/content-manager/pages/ListView/FieldPicker/index.js +0 -1
  41. package/admin/src/content-manager/pages/ListView/index.js +0 -1
  42. package/admin/src/content-manager/pages/ListViewLayoutManager/index.js +0 -1
  43. package/admin/src/content-manager/utils/formatLayoutToApi.js +1 -3
  44. package/admin/src/core/apis/index.js +0 -1
  45. package/admin/src/hooks/index.js +0 -1
  46. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/index.js +197 -215
  47. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/utils/schema.js +1 -2
  48. package/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/DynamicTable/DeleteButton/index.js +0 -1
  49. package/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/DynamicTable/UpdateButton/index.js +36 -3
  50. package/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/DynamicTable/index.js +11 -13
  51. package/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/index.js +2 -3
  52. package/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/utils/tableHeaders.js +8 -8
  53. package/admin/src/pages/SettingsPage/pages/ApiTokens/ProtectedEditView/index.js +1 -1
  54. package/admin/src/permissions/defaultPermissions.js +6 -2
  55. package/admin/src/translations/ar.json +0 -1
  56. package/admin/src/translations/ca.json +0 -9
  57. package/admin/src/translations/cs.json +0 -2
  58. package/admin/src/translations/de.json +0 -11
  59. package/admin/src/translations/dk.json +0 -11
  60. package/admin/src/translations/en.json +0 -28
  61. package/admin/src/translations/es.json +0 -11
  62. package/admin/src/translations/fr.json +0 -11
  63. package/admin/src/translations/gu.json +0 -11
  64. package/admin/src/translations/hi.json +0 -11
  65. package/admin/src/translations/hu.json +0 -10
  66. package/admin/src/translations/id.json +0 -10
  67. package/admin/src/translations/it.json +0 -10
  68. package/admin/src/translations/ja.json +0 -11
  69. package/admin/src/translations/ko.json +0 -11
  70. package/admin/src/translations/ml.json +0 -11
  71. package/admin/src/translations/ms.json +0 -2
  72. package/admin/src/translations/nl.json +0 -11
  73. package/admin/src/translations/pl.json +0 -11
  74. package/admin/src/translations/pt-BR.json +0 -11
  75. package/admin/src/translations/pt.json +0 -1
  76. package/admin/src/translations/ru.json +0 -10
  77. package/admin/src/translations/sa.json +0 -11
  78. package/admin/src/translations/sk.json +0 -10
  79. package/admin/src/translations/sv.json +0 -9
  80. package/admin/src/translations/th.json +0 -2
  81. package/admin/src/translations/tr.json +0 -1
  82. package/admin/src/translations/uk.json +0 -2
  83. package/admin/src/translations/vi.json +0 -1
  84. package/admin/src/translations/zh-Hans.json +0 -12
  85. package/admin/src/translations/zh.json +0 -11
  86. package/build/7098.40dcd7bf.chunk.js +1 -0
  87. package/build/8851.e4ac62f2.chunk.js +158 -0
  88. package/build/{8773.c06c24c0.chunk.js → 9311.7cc03f29.chunk.js} +291 -108
  89. package/build/{Admin-authenticatedApp.9dec5230.chunk.js → Admin-authenticatedApp.e39f36c9.chunk.js} +3 -3
  90. package/build/{Admin_homePage.6d5e3236.chunk.js → Admin_homePage.118926e0.chunk.js} +1 -1
  91. package/build/{Admin_profilePage.da32abbc.chunk.js → Admin_profilePage.9d50ac44.chunk.js} +1 -1
  92. package/build/{Admin_settingsPage.98e2a62b.chunk.js → Admin_settingsPage.98a711e5.chunk.js} +16 -16
  93. package/build/admin-app.4f7618a9.chunk.js +112 -0
  94. package/build/admin-edit-roles-page.554ba3fa.chunk.js +1 -0
  95. package/build/api-tokens-create-page.4c262d6e.chunk.js +1 -0
  96. package/build/api-tokens-edit-page.10a9d368.chunk.js +1 -0
  97. package/build/api-tokens-list-page.442c9f3c.chunk.js +15 -0
  98. package/build/{ar-json.d4cb26d9.chunk.js → ar-json.3489463d.chunk.js} +1 -1
  99. package/build/{ca-json.d16c1d28.chunk.js → ca-json.a16899ae.chunk.js} +1 -1
  100. package/build/content-manager.7d57c9d1.chunk.js +1200 -0
  101. package/build/content-type-builder-list-view.8cc534e0.chunk.js +194 -0
  102. package/build/content-type-builder-translation-en-json.201bfb78.chunk.js +1 -0
  103. package/build/content-type-builder.684df7a4.chunk.js +142 -0
  104. package/build/{cs-json.c8f28ba8.chunk.js → cs-json.ce49da5c.chunk.js} +1 -1
  105. package/build/{de-json.a9b514dc.chunk.js → de-json.aa6026b3.chunk.js} +1 -1
  106. package/build/{dk-json.09e8d145.chunk.js → dk-json.fac2bcfb.chunk.js} +1 -1
  107. package/build/en-json.0c69c7d7.chunk.js +1 -0
  108. package/build/{es-json.3a9c7c09.chunk.js → es-json.d672e181.chunk.js} +1 -1
  109. package/build/{fr-json.4ed1fc2c.chunk.js → fr-json.71a16175.chunk.js} +1 -1
  110. package/build/{gu-json.d8311297.chunk.js → gu-json.ca345cd1.chunk.js} +1 -1
  111. package/build/{hi-json.0edb8d29.chunk.js → hi-json.50c7e6d4.chunk.js} +1 -1
  112. package/build/{hu-json.7855529a.chunk.js → hu-json.e0521dcc.chunk.js} +1 -1
  113. package/build/{id-json.df9618f2.chunk.js → id-json.4b1ff8d6.chunk.js} +1 -1
  114. package/build/index.html +1 -1
  115. package/build/{it-json.a21bf078.chunk.js → it-json.86bac220.chunk.js} +1 -1
  116. package/build/{ja-json.7b0d9067.chunk.js → ja-json.4e44e36b.chunk.js} +1 -1
  117. package/build/{ko-json.983c1f8f.chunk.js → ko-json.1003756e.chunk.js} +1 -1
  118. package/build/main.b47db1a3.js +9337 -0
  119. package/build/{ml-json.8dd021c8.chunk.js → ml-json.c7774425.chunk.js} +1 -1
  120. package/build/{ms-json.836ed013.chunk.js → ms-json.ed51e902.chunk.js} +1 -1
  121. package/build/{nl-json.29d2eb37.chunk.js → nl-json.f58ea235.chunk.js} +1 -1
  122. package/build/{pl-json.1f04f00c.chunk.js → pl-json.fed96aba.chunk.js} +1 -1
  123. package/build/{pt-BR-json.b4bc8efe.chunk.js → pt-BR-json.073799ab.chunk.js} +1 -1
  124. package/build/{pt-json.c23020ab.chunk.js → pt-json.3161ca22.chunk.js} +1 -1
  125. package/build/{ru-json.7ab40ccf.chunk.js → ru-json.7ad2cbbf.chunk.js} +1 -1
  126. package/build/{runtime~main.4204f341.js → runtime~main.feeac6d3.js} +1 -1
  127. package/build/{sa-json.c5a9f4ea.chunk.js → sa-json.f0f704f0.chunk.js} +1 -1
  128. package/build/{sk-json.e4c24c4e.chunk.js → sk-json.a848961b.chunk.js} +1 -1
  129. package/build/sso-settings-page.445184e0.chunk.js +1 -0
  130. package/build/{sv-json.c3f471ae.chunk.js → sv-json.b038acbe.chunk.js} +1 -1
  131. package/build/{th-json.a59ffb32.chunk.js → th-json.72e8de3d.chunk.js} +1 -1
  132. package/build/{tr-json.276e59fe.chunk.js → tr-json.9c44ea0c.chunk.js} +1 -1
  133. package/build/{uk-json.5b5b9c27.chunk.js → uk-json.c4cd2e24.chunk.js} +1 -1
  134. package/build/{vi-json.bf3424be.chunk.js → vi-json.f7890025.chunk.js} +1 -1
  135. package/build/{webhook-edit-page.9e46fc3f.chunk.js → webhook-edit-page.d2ea3351.chunk.js} +1 -1
  136. package/build/{zh-Hans-json.9c99f8d4.chunk.js → zh-Hans-json.03d2bda1.chunk.js} +1 -1
  137. package/build/{zh-json.451a0271.chunk.js → zh-json.3d0cc664.chunk.js} +1 -1
  138. package/package.json +7 -8
  139. package/server/bootstrap.js +1 -19
  140. package/server/config/admin-actions.js +0 -20
  141. package/server/content-types/api-token.js +1 -25
  142. package/server/content-types/index.js +0 -1
  143. package/server/controllers/api-token.js +1 -24
  144. package/server/controllers/index.js +0 -1
  145. package/server/routes/api-tokens.js +0 -11
  146. package/server/routes/index.js +0 -2
  147. package/server/services/api-token.js +29 -310
  148. package/server/services/constants.js +0 -10
  149. package/server/services/permission/engine-hooks.js +82 -0
  150. package/server/services/permission/engine.js +226 -36
  151. package/server/services/permission.js +1 -4
  152. package/server/strategies/admin.js +1 -7
  153. package/server/strategies/api-token.js +11 -71
  154. package/server/validation/api-tokens.js +2 -12
  155. package/admin/src/content-manager/components/SelectMany/ListItem.js +0 -102
  156. package/admin/src/content-manager/components/SelectMany/index.js +0 -148
  157. package/admin/src/content-manager/components/SelectOne/SingleValue.js +0 -67
  158. package/admin/src/content-manager/components/SelectOne/index.js +0 -97
  159. package/admin/src/content-manager/components/SelectWrapper/Label.js +0 -60
  160. package/admin/src/content-manager/components/SelectWrapper/index.js +0 -356
  161. package/admin/src/content-manager/pages/EditSettingsView/components/RelationalFieldButton.js +0 -135
  162. package/admin/src/content-manager/pages/EditSettingsView/components/RelationalFields.js +0 -103
  163. package/admin/src/content-manager/pages/EditView/Header/utils/getDraftRelations.js +0 -62
  164. package/admin/src/contexts/ApiTokenPermissions/index.js +0 -24
  165. package/admin/src/core/apis/CustomFields.js +0 -80
  166. package/admin/src/hooks/useRegenerate/index.js +0 -34
  167. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/ActionBoundRoutes/index.js +0 -56
  168. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/BoundRoute/getMethodColor.js +0 -41
  169. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/BoundRoute/index.js +0 -72
  170. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/CollapsableContentType/CheckBoxWrapper.js +0 -30
  171. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/CollapsableContentType/index.js +0 -150
  172. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/ContenTypesSection/index.js +0 -37
  173. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/FormApiTokenContainer/index.js +0 -254
  174. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/FormBody/index.js +0 -77
  175. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/FormHead/index.js +0 -85
  176. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/Permissions/index.js +0 -40
  177. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/Regenerate/index.js +0 -68
  178. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/init.js +0 -13
  179. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/reducer.js +0 -72
  180. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/utils/getDateOfExpiration.js +0 -16
  181. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/utils/index.js +0 -5
  182. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/utils/transformPermissionsData.js +0 -36
  183. package/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/DynamicTable/DefaultButton/index.js +0 -63
  184. package/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/DynamicTable/ReadButton/index.js +0 -19
  185. package/build/1669.d1b29c28.chunk.js +0 -1
  186. package/build/4318.7d167b58.chunk.js +0 -30
  187. package/build/524.40377968.chunk.js +0 -644
  188. package/build/7379.d246dd38.chunk.js +0 -1
  189. package/build/admin-app.a61d5c2e.chunk.js +0 -112
  190. package/build/admin-edit-roles-page.4dd6bcb9.chunk.js +0 -1
  191. package/build/api-tokens-create-page.93dd0689.chunk.js +0 -1
  192. package/build/api-tokens-edit-page.b0adac81.chunk.js +0 -1
  193. package/build/api-tokens-list-page.bb36535f.chunk.js +0 -16
  194. package/build/content-manager.feb0d540.chunk.js +0 -1178
  195. package/build/content-type-builder-list-view.5b3cd768.chunk.js +0 -194
  196. package/build/content-type-builder-translation-en-json.f985c9c4.chunk.js +0 -1
  197. package/build/content-type-builder.a684b2e8.chunk.js +0 -145
  198. package/build/en-json.a9918c93.chunk.js +0 -1
  199. package/build/main.e4065f58.js +0 -9337
  200. package/build/sso-settings-page.9ceb0140.chunk.js +0 -1
  201. package/server/content-types/api-token-permission.js +0 -36
  202. package/server/controllers/content-api.js +0 -15
  203. package/server/routes/content-api.js +0 -20
@@ -1,254 +0,0 @@
1
- import React from 'react';
2
- import { useIntl } from 'react-intl';
3
- import { usePersistentState } from '@strapi/helper-plugin';
4
- import PropTypes from 'prop-types';
5
- import { Box } from '@strapi/design-system/Box';
6
- import { Grid, GridItem } from '@strapi/design-system/Grid';
7
- import { Select, Option } from '@strapi/design-system/Select';
8
- import { Stack } from '@strapi/design-system/Stack';
9
- import { Textarea } from '@strapi/design-system/Textarea';
10
- import { TextInput } from '@strapi/design-system/TextInput';
11
- import { Typography } from '@strapi/design-system/Typography';
12
- import { getDateOfExpiration } from '../../utils';
13
-
14
- const FormApiTokenContainer = ({
15
- errors,
16
- onChange,
17
- canEditInputs,
18
- isCreating,
19
- values,
20
- apiToken,
21
- onDispatch,
22
- setHasChangedPermissions,
23
- }) => {
24
- const { formatMessage } = useIntl();
25
- const [lang] = usePersistentState('strapi-admin-language', 'en');
26
-
27
- const handleChangeSelectApiTokenType = ({ target: { value } }) => {
28
- setHasChangedPermissions(false);
29
-
30
- if (value === 'full-access') {
31
- onDispatch({
32
- type: 'SELECT_ALL_ACTIONS',
33
- });
34
- }
35
- if (value === 'read-only') {
36
- onDispatch({
37
- type: 'ON_CHANGE_READ_ONLY',
38
- });
39
- }
40
- };
41
-
42
- return (
43
- <Box
44
- background="neutral0"
45
- hasRadius
46
- shadow="filterShadow"
47
- paddingTop={6}
48
- paddingBottom={6}
49
- paddingLeft={7}
50
- paddingRight={7}
51
- >
52
- <Stack spacing={4}>
53
- <Typography variant="delta" as="h2">
54
- {formatMessage({
55
- id: 'global.details',
56
- defaultMessage: 'Details',
57
- })}
58
- </Typography>
59
- <Grid gap={5}>
60
- <GridItem key="name" col={6} xs={12}>
61
- <TextInput
62
- name="name"
63
- error={
64
- errors.name
65
- ? formatMessage(
66
- errors.name?.id
67
- ? errors.name
68
- : { id: errors.name, defaultMessage: errors.name }
69
- )
70
- : null
71
- }
72
- label={formatMessage({
73
- id: 'Settings.apiTokens.form.name',
74
- defaultMessage: 'Name',
75
- })}
76
- onChange={onChange}
77
- value={values.name}
78
- disabled={!canEditInputs}
79
- required
80
- />
81
- </GridItem>
82
- <GridItem key="description" col={6} xs={12}>
83
- <Textarea
84
- label={formatMessage({
85
- id: 'Settings.apiTokens.form.description',
86
- defaultMessage: 'Description',
87
- })}
88
- name="description"
89
- error={
90
- errors.description
91
- ? formatMessage(
92
- errors.description?.id
93
- ? errors.description
94
- : {
95
- id: errors.description,
96
- defaultMessage: errors.description,
97
- }
98
- )
99
- : null
100
- }
101
- onChange={onChange}
102
- disabled={!canEditInputs}
103
- >
104
- {values.description}
105
- </Textarea>
106
- </GridItem>
107
- <GridItem key="lifespan" col={6} xs={12}>
108
- <Select
109
- name="lifespan"
110
- label={formatMessage({
111
- id: 'Settings.apiTokens.form.duration',
112
- defaultMessage: 'Token duration',
113
- })}
114
- value={values.lifespan}
115
- error={
116
- errors.lifespan
117
- ? formatMessage(
118
- errors.lifespan?.id
119
- ? errors.lifespan
120
- : { id: errors.lifespan, defaultMessage: errors.lifespan }
121
- )
122
- : null
123
- }
124
- onChange={(value) => {
125
- onChange({ target: { name: 'lifespan', value } });
126
- }}
127
- required
128
- disabled={!isCreating}
129
- placeholder="Select"
130
- >
131
- <Option value="604800000">
132
- {formatMessage({
133
- id: 'Settings.apiTokens.duration.7-days',
134
- defaultMessage: '7 days',
135
- })}
136
- </Option>
137
- <Option value="2592000000">
138
- {formatMessage({
139
- id: 'Settings.apiTokens.duration.30-days',
140
- defaultMessage: '30 days',
141
- })}
142
- </Option>
143
- <Option value="7776000000">
144
- {formatMessage({
145
- id: 'Settings.apiTokens.duration.90-days',
146
- defaultMessage: '90 days',
147
- })}
148
- </Option>
149
- <Option value={null}>
150
- {formatMessage({
151
- id: 'Settings.apiTokens.duration.unlimited',
152
- defaultMessage: 'Unlimited',
153
- })}
154
- </Option>
155
- </Select>
156
- <Typography variant="pi" textColor="neutral600">
157
- {!isCreating &&
158
- `${formatMessage({
159
- id: 'Settings.apiTokens.duration.expiration-date',
160
- defaultMessage: 'Expiration date',
161
- })}: ${getDateOfExpiration(
162
- apiToken?.createdAt,
163
- parseInt(values.lifespan, 10),
164
- lang
165
- )}`}
166
- </Typography>
167
- </GridItem>
168
-
169
- <GridItem key="type" col={6} xs={12}>
170
- <Select
171
- name="type"
172
- label={formatMessage({
173
- id: 'Settings.apiTokens.form.type',
174
- defaultMessage: 'Token type',
175
- })}
176
- value={values?.type}
177
- error={
178
- errors.type
179
- ? formatMessage(
180
- errors.type?.id
181
- ? errors.type
182
- : { id: errors.type, defaultMessage: errors.type }
183
- )
184
- : null
185
- }
186
- onChange={(value) => {
187
- handleChangeSelectApiTokenType({ target: { value } });
188
- onChange({ target: { name: 'type', value } });
189
- }}
190
- placeholder="Select"
191
- required
192
- disabled={!canEditInputs}
193
- >
194
- <Option value="read-only">
195
- {formatMessage({
196
- id: 'Settings.apiTokens.types.read-only',
197
- defaultMessage: 'Read-only',
198
- })}
199
- </Option>
200
- <Option value="full-access">
201
- {formatMessage({
202
- id: 'Settings.apiTokens.types.full-access',
203
- defaultMessage: 'Full access',
204
- })}
205
- </Option>
206
- <Option value="custom">
207
- {formatMessage({
208
- id: 'Settings.apiTokens.types.custom',
209
- defaultMessage: 'Custom',
210
- })}
211
- </Option>
212
- </Select>
213
- </GridItem>
214
- </Grid>
215
- </Stack>
216
- </Box>
217
- );
218
- };
219
-
220
- FormApiTokenContainer.propTypes = {
221
- errors: PropTypes.shape({
222
- name: PropTypes.string,
223
- description: PropTypes.string,
224
- lifespan: PropTypes.string,
225
- type: PropTypes.string,
226
- }),
227
- onChange: PropTypes.func.isRequired,
228
- canEditInputs: PropTypes.bool.isRequired,
229
- values: PropTypes.shape({
230
- name: PropTypes.string,
231
- description: PropTypes.string,
232
- lifespan: PropTypes.string,
233
- type: PropTypes.string,
234
- }).isRequired,
235
- isCreating: PropTypes.bool.isRequired,
236
- apiToken: PropTypes.shape({
237
- id: PropTypes.string,
238
- type: PropTypes.string,
239
- lifespan: PropTypes.number,
240
- name: PropTypes.string,
241
- accessKey: PropTypes.string,
242
- permissions: PropTypes.array,
243
- description: PropTypes.string,
244
- createdAt: PropTypes.string,
245
- }).isRequired,
246
- onDispatch: PropTypes.func.isRequired,
247
- setHasChangedPermissions: PropTypes.func.isRequired,
248
- };
249
-
250
- FormApiTokenContainer.defaultProps = {
251
- errors: {},
252
- };
253
-
254
- export default FormApiTokenContainer;
@@ -1,77 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { ContentLayout } from '@strapi/design-system/Layout';
4
- import { Stack } from '@strapi/design-system/Stack';
5
- import HeaderContentBox from '../ContentBox';
6
- import FormApiTokenContainer from '../FormApiTokenContainer';
7
- import Permissions from '../Permissions';
8
-
9
- const FormBody = ({
10
- apiToken,
11
- errors,
12
- onChange,
13
- canEditInputs,
14
- isCreating,
15
- values,
16
- onDispatch,
17
- setHasChangedPermissions,
18
- }) => {
19
- return (
20
- <ContentLayout>
21
- <Stack spacing={6}>
22
- {Boolean(apiToken?.name) && <HeaderContentBox apiToken={apiToken.accessKey} />}
23
- <FormApiTokenContainer
24
- errors={errors}
25
- onChange={onChange}
26
- canEditInputs={canEditInputs}
27
- isCreating={isCreating}
28
- values={values}
29
- apiToken={apiToken}
30
- onDispatch={onDispatch}
31
- setHasChangedPermissions={setHasChangedPermissions}
32
- />
33
- <Permissions
34
- disabled={
35
- !canEditInputs || values?.type === 'read-only' || values?.type === 'full-access'
36
- }
37
- />
38
- </Stack>
39
- </ContentLayout>
40
- );
41
- };
42
-
43
- FormBody.propTypes = {
44
- errors: PropTypes.shape({
45
- name: PropTypes.string,
46
- description: PropTypes.string,
47
- lifespan: PropTypes.string,
48
- type: PropTypes.string,
49
- }),
50
- apiToken: PropTypes.shape({
51
- id: PropTypes.string,
52
- type: PropTypes.string,
53
- lifespan: PropTypes.number,
54
- name: PropTypes.string,
55
- accessKey: PropTypes.string,
56
- permissions: PropTypes.array,
57
- description: PropTypes.string,
58
- createdAt: PropTypes.string,
59
- }).isRequired,
60
- onChange: PropTypes.func.isRequired,
61
- canEditInputs: PropTypes.bool.isRequired,
62
- isCreating: PropTypes.bool.isRequired,
63
- values: PropTypes.shape({
64
- name: PropTypes.string,
65
- description: PropTypes.string,
66
- lifespan: PropTypes.string,
67
- type: PropTypes.string,
68
- }).isRequired,
69
- onDispatch: PropTypes.func.isRequired,
70
- setHasChangedPermissions: PropTypes.func.isRequired,
71
- };
72
-
73
- FormBody.defaultProps = {
74
- errors: {},
75
- };
76
-
77
- export default FormBody;
@@ -1,85 +0,0 @@
1
- import React from 'react';
2
- import { useIntl } from 'react-intl';
3
- import { Link } from '@strapi/helper-plugin';
4
- import PropTypes from 'prop-types';
5
- import ArrowLeft from '@strapi/icons/ArrowLeft';
6
- import Check from '@strapi/icons/Check';
7
- import { Button } from '@strapi/design-system/Button';
8
- import { HeaderLayout } from '@strapi/design-system/Layout';
9
- import { Stack } from '@strapi/design-system/Stack';
10
- import Regenerate from '../Regenerate';
11
-
12
- const FormHead = ({ apiToken, setApiToken, canEditInputs, canRegenerate, isSubmitting }) => {
13
- const { formatMessage } = useIntl();
14
- const handleRegenerate = (newKey) => {
15
- setApiToken({
16
- ...apiToken,
17
- accessKey: newKey,
18
- });
19
- };
20
-
21
- return (
22
- <HeaderLayout
23
- title={
24
- apiToken?.name ||
25
- formatMessage({
26
- id: 'Settings.apiTokens.createPage.title',
27
- defaultMessage: 'Create API Token',
28
- })
29
- }
30
- primaryAction={
31
- canEditInputs ? (
32
- <Stack horizontal spacing={2}>
33
- {canRegenerate && apiToken?.id && (
34
- <Regenerate onRegenerate={handleRegenerate} idToRegenerate={apiToken?.id} />
35
- )}
36
- <Button
37
- disabled={isSubmitting}
38
- loading={isSubmitting}
39
- startIcon={<Check />}
40
- type="submit"
41
- size="S"
42
- >
43
- {formatMessage({
44
- id: 'global.save',
45
- defaultMessage: 'Save',
46
- })}
47
- </Button>
48
- </Stack>
49
- ) : (
50
- canRegenerate &&
51
- apiToken?.id && (
52
- <Regenerate onRegenerate={handleRegenerate} idToRegenerate={apiToken?.id} />
53
- )
54
- )
55
- }
56
- navigationAction={
57
- <Link startIcon={<ArrowLeft />} to="/settings/api-tokens">
58
- {formatMessage({
59
- id: 'global.back',
60
- defaultMessage: 'Back',
61
- })}
62
- </Link>
63
- }
64
- />
65
- );
66
- };
67
-
68
- FormHead.propTypes = {
69
- apiToken: PropTypes.shape({
70
- id: PropTypes.string,
71
- type: PropTypes.string,
72
- lifespan: PropTypes.number,
73
- name: PropTypes.string,
74
- accessKey: PropTypes.string,
75
- permissions: PropTypes.array,
76
- description: PropTypes.string,
77
- createdAt: PropTypes.string,
78
- }).isRequired,
79
- canEditInputs: PropTypes.bool.isRequired,
80
- canRegenerate: PropTypes.bool.isRequired,
81
- setApiToken: PropTypes.func.isRequired,
82
- isSubmitting: PropTypes.bool.isRequired,
83
- };
84
-
85
- export default FormHead;
@@ -1,40 +0,0 @@
1
- import React, { memo } 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 { Grid, GridItem } from '@strapi/design-system/Grid';
6
- import ContentTypesSection from '../ContenTypesSection';
7
- import ActionBoundRoutes from '../ActionBoundRoutes';
8
- import { useApiTokenPermissionsContext } from '../../../../../../../contexts/ApiTokenPermissions';
9
-
10
- const Permissions = ({ ...props }) => {
11
- const {
12
- value: { data },
13
- } = useApiTokenPermissionsContext();
14
- const { formatMessage } = useIntl();
15
-
16
- return (
17
- <Grid gap={0} shadow="filterShadow" hasRadius background="neutral0">
18
- <GridItem col={7} paddingTop={6} paddingBottom={6} paddingLeft={7} paddingRight={7}>
19
- <Stack spacing={2}>
20
- <Typography variant="delta" as="h2">
21
- {formatMessage({
22
- id: 'Settings.apiTokens.createPage.permissions.title',
23
- defaultMessage: 'Permissions',
24
- })}
25
- </Typography>
26
- <Typography as="p" textColor="neutral600">
27
- {formatMessage({
28
- id: 'Settings.apiTokens.createPage.permissions.description',
29
- defaultMessage: 'Only actions bound by a route are listed below.',
30
- })}
31
- </Typography>
32
- </Stack>
33
- {data?.permissions && <ContentTypesSection section={data?.permissions} {...props} />}
34
- </GridItem>
35
- <ActionBoundRoutes />
36
- </Grid>
37
- );
38
- };
39
-
40
- export default memo(Permissions);
@@ -1,68 +0,0 @@
1
- import React, { useState } from 'react';
2
- import PropTypes from 'prop-types';
3
- import { useIntl } from 'react-intl';
4
- import { Button } from '@strapi/design-system/Button';
5
- import Refresh from '@strapi/icons/Refresh';
6
- import { ConfirmDialog } from '@strapi/helper-plugin';
7
- import { useRegenerate } from '../../../../../../../hooks';
8
-
9
- export const Regenerate = ({ onRegenerate, idToRegenerate }) => {
10
- const { formatMessage } = useIntl();
11
- const [showConfirmDialog, setShowConfirmDialog] = useState(false);
12
- const { regenerateData, isLoadingConfirmation } = useRegenerate(idToRegenerate, onRegenerate);
13
- const handleConfirmRegeneration = async () => {
14
- regenerateData();
15
- setShowConfirmDialog(false);
16
- };
17
-
18
- return (
19
- <>
20
- <Button
21
- startIcon={<Refresh />}
22
- type="button"
23
- size="S"
24
- variant="tertiary"
25
- onClick={() => setShowConfirmDialog(true)}
26
- name="regenerate"
27
- >
28
- {formatMessage({
29
- id: 'Settings.apiTokens.regenerate',
30
- defaultMessage: 'Regenerate',
31
- })}
32
- </Button>
33
-
34
- <ConfirmDialog
35
- bodyText={{
36
- id: 'Settings.apiTokens.popUpWarning.message',
37
- defaultMessage: 'Are you sure you want to regenerate this token?',
38
- }}
39
- iconRightButton={<Refresh />}
40
- isConfirmButtonLoading={isLoadingConfirmation}
41
- isOpen={showConfirmDialog}
42
- onToggleDialog={() => setShowConfirmDialog(false)}
43
- onConfirm={handleConfirmRegeneration}
44
- leftButtonText={{
45
- id: 'Settings.apiTokens.Button.cancel',
46
- defaultMessage: 'Cancel',
47
- }}
48
- rightButtonText={{
49
- id: 'Settings.apiTokens.Button.regenerate',
50
- defaultMessage: 'Regenerate',
51
- }}
52
- title={{
53
- id: 'Settings.apiTokens.RegenerateDialog.title',
54
- defaultMessage: 'Regenerate token',
55
- }}
56
- />
57
- </>
58
- );
59
- };
60
-
61
- Regenerate.defaultProps = { onRegenerate() {} };
62
-
63
- Regenerate.propTypes = {
64
- onRegenerate: PropTypes.func,
65
- idToRegenerate: PropTypes.string.isRequired,
66
- };
67
-
68
- export default Regenerate;
@@ -1,13 +0,0 @@
1
- import { transformPermissionsData } from './utils';
2
-
3
- const init = (state, permissions = []) => {
4
- return {
5
- ...state,
6
- selectedAction: null,
7
- routes: [],
8
- selectedActions: [],
9
- data: transformPermissionsData(permissions),
10
- };
11
- };
12
-
13
- export default init;
@@ -1,72 +0,0 @@
1
- /* eslint-disable consistent-return */
2
- import produce from 'immer';
3
- import { pull } from 'lodash';
4
- import { transformPermissionsData } from './utils';
5
-
6
- export const initialState = {
7
- data: {},
8
- selectedActions: [],
9
- };
10
-
11
- const reducer = (state, action) =>
12
- produce(state, (draftState) => {
13
- switch (action.type) {
14
- case 'ON_CHANGE': {
15
- if (draftState.selectedActions.includes(action.value)) {
16
- pull(draftState.selectedActions, action.value);
17
- } else {
18
- draftState.selectedActions.push(action.value);
19
- }
20
- break;
21
- }
22
- case 'SELECT_ALL_IN_PERMISSION': {
23
- const areAllSelected = action.value.every((item) =>
24
- draftState.selectedActions.includes(item.actionId)
25
- );
26
-
27
- if (areAllSelected) {
28
- action.value.forEach((item) => {
29
- pull(draftState.selectedActions, item.actionId);
30
- });
31
- } else {
32
- action.value.forEach((item) => {
33
- draftState.selectedActions.push(item.actionId);
34
- });
35
- }
36
- break;
37
- }
38
-
39
- case 'SELECT_ALL_ACTIONS': {
40
- draftState.selectedActions = [...draftState.data.allActionsIds];
41
-
42
- break;
43
- }
44
- case 'ON_CHANGE_READ_ONLY': {
45
- const onlyReadOnlyActions = draftState.data.allActionsIds.filter(
46
- (actionId) => actionId.includes('find') || actionId.includes('findOne')
47
- );
48
- draftState.selectedActions = [...onlyReadOnlyActions];
49
- break;
50
- }
51
- case 'UPDATE_PERMISSIONS_LAYOUT': {
52
- draftState.data = transformPermissionsData(action.value);
53
- break;
54
- }
55
- case 'UPDATE_ROUTES': {
56
- draftState.routes = { ...action.value };
57
- break;
58
- }
59
- case 'UPDATE_PERMISSIONS': {
60
- draftState.selectedActions = [...action.value];
61
- break;
62
- }
63
- case 'SET_SELECTED_ACTION': {
64
- draftState.selectedAction = action.value;
65
- break;
66
- }
67
- default:
68
- return draftState;
69
- }
70
- });
71
-
72
- export default reducer;
@@ -1,16 +0,0 @@
1
- import { addDays, format } from 'date-fns';
2
- import * as locales from 'date-fns/locale';
3
-
4
- const getDateOfExpiration = (createdAt, duration, language = 'en') => {
5
- if (duration && typeof duration === 'number') {
6
- const durationInDays = duration / 24 / 60 / 60 / 1000;
7
-
8
- return format(addDays(new Date(createdAt), durationInDays), 'PPP', {
9
- locale: locales[language],
10
- });
11
- }
12
-
13
- return 'Unlimited';
14
- };
15
-
16
- export default getDateOfExpiration;
@@ -1,5 +0,0 @@
1
- import getDateOfExpiration from './getDateOfExpiration';
2
- import schema from './schema';
3
- import transformPermissionsData from './transformPermissionsData';
4
-
5
- export { getDateOfExpiration, schema, transformPermissionsData };
@@ -1,36 +0,0 @@
1
- import { flatten } from 'lodash';
2
-
3
- const transformPermissionsData = (data) => {
4
- const layout = {
5
- allActionsIds: [],
6
- permissions: [],
7
- };
8
-
9
- layout.permissions = Object.keys(data).map((apiId) => ({
10
- apiId,
11
- label: apiId.split('::')[1],
12
- controllers: flatten(
13
- Object.keys(data[apiId].controllers).map((controller) => ({
14
- controller,
15
- actions: flatten(
16
- data[apiId].controllers[controller].map((action) => {
17
- const actionId = `${apiId}.${controller}.${action}`;
18
-
19
- if (apiId.includes('api::')) {
20
- layout.allActionsIds.push(actionId);
21
- }
22
-
23
- return {
24
- action,
25
- actionId,
26
- };
27
- })
28
- ),
29
- }))
30
- ),
31
- }));
32
-
33
- return layout;
34
- };
35
-
36
- export default transformPermissionsData;