@strapi/admin 4.3.7 → 4.4.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/admin/src/contexts/ApiTokenPermissions/index.js +24 -0
- package/admin/src/hooks/index.js +1 -0
- package/admin/src/hooks/useRegenerate/index.js +34 -0
- package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/ActionBoundRoutes/index.js +56 -0
- package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/BoundRoute/getMethodColor.js +41 -0
- package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/BoundRoute/index.js +72 -0
- package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/CollapsableContentType/CheckBoxWrapper.js +30 -0
- package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/CollapsableContentType/index.js +150 -0
- package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/ContenTypesSection/index.js +37 -0
- package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/Permissions/index.js +40 -0
- package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/Regenerate/index.js +68 -0
- package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/index.js +452 -180
- package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/init.js +13 -0
- package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/reducer.js +55 -0
- package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/utils/getDateOfExpiration.js +16 -0
- package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/utils/index.js +5 -0
- package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/utils/schema.js +2 -1
- package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/utils/transformPermissionsData.js +36 -0
- package/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/DynamicTable/DefaultButton/index.js +63 -0
- package/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/DynamicTable/DeleteButton/index.js +1 -0
- package/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/DynamicTable/ReadButton/index.js +19 -0
- package/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/DynamicTable/UpdateButton/index.js +3 -36
- package/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/DynamicTable/index.js +13 -11
- package/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/index.js +3 -2
- package/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/utils/tableHeaders.js +8 -8
- package/admin/src/pages/SettingsPage/pages/ApiTokens/ProtectedEditView/index.js +1 -1
- package/admin/src/permissions/defaultPermissions.js +2 -6
- package/admin/src/translations/en.json +17 -0
- package/admin/src/translations/fr.json +32 -0
- package/build/4235.982b5799.chunk.js +30 -0
- package/build/7379.d246dd38.chunk.js +1 -0
- package/build/{Admin-authenticatedApp.0d299d1a.chunk.js → Admin-authenticatedApp.3a31a087.chunk.js} +1 -1
- package/build/{Admin_homePage.118926e0.chunk.js → Admin_homePage.6d5e3236.chunk.js} +1 -1
- package/build/{Admin_profilePage.8617313a.chunk.js → Admin_profilePage.83991a6c.chunk.js} +1 -1
- package/build/{Admin_settingsPage.98a711e5.chunk.js → Admin_settingsPage.fc9c607a.chunk.js} +16 -16
- package/build/admin-app.41b6472c.chunk.js +112 -0
- package/build/admin-edit-roles-page.4dd6bcb9.chunk.js +1 -0
- package/build/api-tokens-create-page.29cc87b6.chunk.js +1 -0
- package/build/api-tokens-edit-page.c294a88f.chunk.js +1 -0
- package/build/api-tokens-list-page.bb36535f.chunk.js +16 -0
- package/build/en-json.a9918c93.chunk.js +1 -0
- package/build/{fr-json.6d5a7e14.chunk.js → fr-json.4ed1fc2c.chunk.js} +1 -1
- package/build/index.html +1 -1
- package/build/{main.e73468bf.js → main.cdfda31e.js} +1 -1
- package/build/{runtime~main.edd06c9f.js → runtime~main.fa8f8898.js} +2 -2
- package/build/sso-settings-page.9ceb0140.chunk.js +1 -0
- package/build/{webhook-edit-page.d2ea3351.chunk.js → webhook-edit-page.9e46fc3f.chunk.js} +1 -1
- package/package.json +9 -8
- package/scripts/build.js +2 -4
- package/server/bootstrap.js +19 -1
- package/server/config/admin-actions.js +20 -0
- package/server/content-types/api-token-permission.js +36 -0
- package/server/content-types/api-token.js +25 -1
- package/server/content-types/index.js +1 -0
- package/server/controllers/api-token.js +24 -1
- package/server/controllers/content-api.js +15 -0
- package/server/controllers/index.js +1 -0
- package/server/routes/api-tokens.js +11 -0
- package/server/routes/content-api.js +20 -0
- package/server/routes/index.js +2 -0
- package/server/services/api-token.js +310 -29
- package/server/services/constants.js +10 -0
- package/server/services/permission/engine.js +36 -226
- package/server/services/permission/permissions-manager/query-builers.js +3 -2
- package/server/services/permission/queries.js +1 -1
- package/server/services/permission.js +4 -1
- package/server/strategies/admin.js +7 -1
- package/server/strategies/api-token.js +71 -11
- package/server/validation/api-tokens.js +12 -2
- package/server/validation/common-functions/check-fields-are-correctly-nested.js +1 -1
- package/build/admin-app.05edc328.chunk.js +0 -112
- package/build/admin-edit-roles-page.554ba3fa.chunk.js +0 -1
- package/build/api-tokens-create-page.4c262d6e.chunk.js +0 -1
- package/build/api-tokens-edit-page.10a9d368.chunk.js +0 -1
- package/build/api-tokens-list-page.442c9f3c.chunk.js +0 -15
- package/build/en-json.12bc5a14.chunk.js +0 -1
- package/build/sso-settings-page.445184e0.chunk.js +0 -1
- package/server/services/permission/engine-hooks.js +0 -82
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from 'react';
|
|
1
|
+
import React, { useEffect, useState, useRef, useReducer } from 'react';
|
|
2
2
|
import { useIntl } from 'react-intl';
|
|
3
3
|
import {
|
|
4
4
|
SettingsPageTitle,
|
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
useTracking,
|
|
10
10
|
useGuidedTour,
|
|
11
11
|
Link,
|
|
12
|
+
usePersistentState,
|
|
13
|
+
useRBAC,
|
|
12
14
|
} from '@strapi/helper-plugin';
|
|
13
15
|
import { HeaderLayout, ContentLayout } from '@strapi/design-system/Layout';
|
|
14
16
|
import { Main } from '@strapi/design-system/Main';
|
|
@@ -23,47 +25,132 @@ import { Grid, GridItem } from '@strapi/design-system/Grid';
|
|
|
23
25
|
import { TextInput } from '@strapi/design-system/TextInput';
|
|
24
26
|
import { Textarea } from '@strapi/design-system/Textarea';
|
|
25
27
|
import { Select, Option } from '@strapi/design-system/Select';
|
|
26
|
-
import get from 'lodash
|
|
28
|
+
import { get } from 'lodash';
|
|
27
29
|
import { useRouteMatch, useHistory } from 'react-router-dom';
|
|
28
30
|
import { useQuery } from 'react-query';
|
|
29
31
|
import { formatAPIErrors } from '../../../../../utils';
|
|
30
32
|
import { axiosInstance } from '../../../../../core/utils';
|
|
31
|
-
import schema from './utils
|
|
33
|
+
import { getDateOfExpiration, schema } from './utils';
|
|
32
34
|
import LoadingView from './components/LoadingView';
|
|
33
35
|
import HeaderContentBox from './components/ContentBox';
|
|
36
|
+
import Permissions from './components/Permissions';
|
|
37
|
+
import Regenerate from './components/Regenerate';
|
|
38
|
+
import adminPermissions from '../../../../../permissions';
|
|
39
|
+
import { ApiTokenPermissionsContextProvider } from '../../../../../contexts/ApiTokenPermissions';
|
|
40
|
+
import init from './init';
|
|
41
|
+
import reducer, { initialState } from './reducer';
|
|
42
|
+
|
|
43
|
+
const MSG_ERROR_NAME_TAKEN = 'Name already taken';
|
|
34
44
|
|
|
35
45
|
const ApiTokenCreateView = () => {
|
|
36
|
-
let apiToken;
|
|
37
46
|
useFocusWhenNavigate();
|
|
38
47
|
const { formatMessage } = useIntl();
|
|
39
48
|
const { lockApp, unlockApp } = useOverlayBlocker();
|
|
40
49
|
const toggleNotification = useNotification();
|
|
41
50
|
const history = useHistory();
|
|
51
|
+
const [apiToken, setApiToken] = useState(
|
|
52
|
+
history.location.state?.apiToken.accessKey
|
|
53
|
+
? {
|
|
54
|
+
...history.location.state.apiToken,
|
|
55
|
+
}
|
|
56
|
+
: null
|
|
57
|
+
);
|
|
42
58
|
const { trackUsage } = useTracking();
|
|
43
59
|
const trackUsageRef = useRef(trackUsage);
|
|
44
60
|
const { setCurrentStep } = useGuidedTour();
|
|
45
|
-
|
|
61
|
+
const {
|
|
62
|
+
allowedActions: { canCreate, canUpdate, canRegenerate },
|
|
63
|
+
} = useRBAC(adminPermissions.settings['api-tokens']);
|
|
64
|
+
const [lang] = usePersistentState('strapi-admin-language', 'en');
|
|
65
|
+
const [state, dispatch] = useReducer(reducer, initialState, (state) => init(state, {}));
|
|
46
66
|
const {
|
|
47
67
|
params: { id },
|
|
48
68
|
} = useRouteMatch('/settings/api-tokens/:id');
|
|
49
69
|
|
|
50
70
|
const isCreating = id === 'create';
|
|
51
71
|
|
|
72
|
+
useQuery(
|
|
73
|
+
'content-api-permissions',
|
|
74
|
+
async () => {
|
|
75
|
+
const [permissions, routes] = await Promise.all(
|
|
76
|
+
['/admin/content-api/permissions', '/admin/content-api/routes'].map(async (url) => {
|
|
77
|
+
const { data } = await axiosInstance.get(url);
|
|
78
|
+
|
|
79
|
+
return data.data;
|
|
80
|
+
})
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
dispatch({
|
|
84
|
+
type: 'UPDATE_PERMISSIONS_LAYOUT',
|
|
85
|
+
value: permissions,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
dispatch({
|
|
89
|
+
type: 'UPDATE_ROUTES',
|
|
90
|
+
value: routes,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
if (apiToken) {
|
|
94
|
+
if (apiToken?.type === 'read-only') {
|
|
95
|
+
dispatch({
|
|
96
|
+
type: 'ON_CHANGE_READ_ONLY',
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (apiToken?.type === 'full-access') {
|
|
100
|
+
dispatch({
|
|
101
|
+
type: 'SELECT_ALL_ACTIONS',
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
if (apiToken?.type === 'custom') {
|
|
105
|
+
dispatch({
|
|
106
|
+
type: 'UPDATE_PERMISSIONS',
|
|
107
|
+
value: apiToken?.permissions,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
onError() {
|
|
114
|
+
toggleNotification({
|
|
115
|
+
type: 'warning',
|
|
116
|
+
message: { id: 'notification.error', defaultMessage: 'An error occured' },
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
}
|
|
120
|
+
);
|
|
121
|
+
|
|
52
122
|
useEffect(() => {
|
|
53
123
|
trackUsageRef.current(isCreating ? 'didAddTokenFromList' : 'didEditTokenFromList');
|
|
54
124
|
}, [isCreating]);
|
|
55
125
|
|
|
56
|
-
|
|
57
|
-
apiToken = history.location.state.apiToken;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const { status, data } = useQuery(
|
|
126
|
+
const { status } = useQuery(
|
|
61
127
|
['api-token', id],
|
|
62
128
|
async () => {
|
|
63
129
|
const {
|
|
64
130
|
data: { data },
|
|
65
131
|
} = await axiosInstance.get(`/admin/api-tokens/${id}`);
|
|
66
132
|
|
|
133
|
+
setApiToken({
|
|
134
|
+
...data,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
if (data?.type === 'read-only') {
|
|
138
|
+
dispatch({
|
|
139
|
+
type: 'ON_CHANGE_READ_ONLY',
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
if (data?.type === 'full-access') {
|
|
143
|
+
dispatch({
|
|
144
|
+
type: 'SELECT_ALL_ACTIONS',
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
if (data?.type === 'custom') {
|
|
148
|
+
dispatch({
|
|
149
|
+
type: 'UPDATE_PERMISSIONS',
|
|
150
|
+
value: data?.permissions,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
67
154
|
return data;
|
|
68
155
|
},
|
|
69
156
|
{
|
|
@@ -77,10 +164,6 @@ const ApiTokenCreateView = () => {
|
|
|
77
164
|
}
|
|
78
165
|
);
|
|
79
166
|
|
|
80
|
-
if (data) {
|
|
81
|
-
apiToken = data;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
167
|
const handleSubmit = async (body, actions) => {
|
|
85
168
|
trackUsageRef.current(isCreating ? 'willCreateToken' : 'willEditToken');
|
|
86
169
|
lockApp();
|
|
@@ -89,37 +172,122 @@ const ApiTokenCreateView = () => {
|
|
|
89
172
|
const {
|
|
90
173
|
data: { data: response },
|
|
91
174
|
} = isCreating
|
|
92
|
-
? await axiosInstance.post(`/admin/api-tokens`,
|
|
93
|
-
|
|
175
|
+
? await axiosInstance.post(`/admin/api-tokens`, {
|
|
176
|
+
...body,
|
|
177
|
+
lifespan:
|
|
178
|
+
body.lifespan && parseInt(body.lifespan, 10)
|
|
179
|
+
? parseInt(body.lifespan, 10)
|
|
180
|
+
: body.lifespan,
|
|
181
|
+
permissions: body.type === 'custom' ? state.selectedActions : null,
|
|
182
|
+
})
|
|
183
|
+
: await axiosInstance.put(`/admin/api-tokens/${id}`, {
|
|
184
|
+
name: body.name,
|
|
185
|
+
description: body.description,
|
|
186
|
+
type: body.type,
|
|
187
|
+
permissions: body.type === 'custom' ? state.selectedActions : null,
|
|
188
|
+
});
|
|
94
189
|
|
|
95
|
-
|
|
190
|
+
if (isCreating) {
|
|
191
|
+
history.replace(`/settings/api-tokens/${response.id}`, { apiToken: response });
|
|
192
|
+
setCurrentStep('apiTokens.success');
|
|
193
|
+
}
|
|
194
|
+
unlockApp();
|
|
195
|
+
setApiToken({
|
|
196
|
+
...response,
|
|
197
|
+
});
|
|
96
198
|
|
|
97
199
|
toggleNotification({
|
|
98
200
|
type: 'success',
|
|
99
|
-
message:
|
|
201
|
+
message: isCreating
|
|
202
|
+
? formatMessage({
|
|
203
|
+
id: 'notification.success.tokencreated',
|
|
204
|
+
defaultMessage: 'API Token successfully created',
|
|
205
|
+
})
|
|
206
|
+
: formatMessage({
|
|
207
|
+
id: 'notification.success.tokenedited',
|
|
208
|
+
defaultMessage: 'API Token successfully edited',
|
|
209
|
+
}),
|
|
100
210
|
});
|
|
101
211
|
|
|
102
212
|
trackUsageRef.current(isCreating ? 'didCreateToken' : 'didEditToken', {
|
|
103
213
|
type: apiToken.type,
|
|
104
214
|
});
|
|
105
|
-
|
|
106
|
-
if (isCreating) {
|
|
107
|
-
history.replace(`/settings/api-tokens/${response.id}`, { apiToken: response });
|
|
108
|
-
setCurrentStep('apiTokens.success');
|
|
109
|
-
}
|
|
110
215
|
} catch (err) {
|
|
111
216
|
const errors = formatAPIErrors(err.response.data);
|
|
112
217
|
actions.setErrors(errors);
|
|
113
218
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
219
|
+
if (err?.response?.data?.error?.message === MSG_ERROR_NAME_TAKEN) {
|
|
220
|
+
toggleNotification({
|
|
221
|
+
type: 'warning',
|
|
222
|
+
message: get(err, 'response.data.message', 'notification.error.tokennamenotunique'),
|
|
223
|
+
});
|
|
224
|
+
} else {
|
|
225
|
+
toggleNotification({
|
|
226
|
+
type: 'warning',
|
|
227
|
+
message: get(err, 'response.data.message', 'notification.error'),
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
unlockApp();
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const [hasChangedPermissions, setHasChangedPermissions] = useState(false);
|
|
235
|
+
|
|
236
|
+
const handleChangeCheckbox = ({ target: { value } }) => {
|
|
237
|
+
setHasChangedPermissions(true);
|
|
238
|
+
dispatch({
|
|
239
|
+
type: 'ON_CHANGE',
|
|
240
|
+
value,
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
const handleChangeSelectAllCheckbox = ({ target: { value } }) => {
|
|
245
|
+
setHasChangedPermissions(true);
|
|
246
|
+
value.forEach((action) => {
|
|
247
|
+
dispatch({
|
|
248
|
+
type: 'ON_CHANGE',
|
|
249
|
+
value: action.actionId,
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
const handleChangeSelectApiTokenType = ({ target: { value } }) => {
|
|
255
|
+
setHasChangedPermissions(false);
|
|
256
|
+
|
|
257
|
+
if (value === 'full-access') {
|
|
258
|
+
dispatch({
|
|
259
|
+
type: 'SELECT_ALL_ACTIONS',
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
if (value === 'read-only') {
|
|
263
|
+
dispatch({
|
|
264
|
+
type: 'ON_CHANGE_READ_ONLY',
|
|
117
265
|
});
|
|
118
266
|
}
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
const setSelectedAction = ({ target: { value } }) => {
|
|
270
|
+
dispatch({
|
|
271
|
+
type: 'SET_SELECTED_ACTION',
|
|
272
|
+
value,
|
|
273
|
+
});
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
const handleRegenerate = (newKey) => {
|
|
277
|
+
setApiToken({
|
|
278
|
+
...apiToken,
|
|
279
|
+
accessKey: newKey,
|
|
280
|
+
});
|
|
281
|
+
};
|
|
119
282
|
|
|
120
|
-
|
|
283
|
+
const providerValue = {
|
|
284
|
+
...state,
|
|
285
|
+
onChange: handleChangeCheckbox,
|
|
286
|
+
onChangeSelectAll: handleChangeSelectAllCheckbox,
|
|
287
|
+
setSelectedAction,
|
|
121
288
|
};
|
|
122
289
|
|
|
290
|
+
const canEditInputs = (canUpdate && !isCreating) || (canCreate && isCreating);
|
|
123
291
|
const isLoading = !isCreating && !apiToken && status !== 'success';
|
|
124
292
|
|
|
125
293
|
if (isLoading) {
|
|
@@ -127,162 +295,266 @@ const ApiTokenCreateView = () => {
|
|
|
127
295
|
}
|
|
128
296
|
|
|
129
297
|
return (
|
|
130
|
-
<
|
|
131
|
-
<
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
navigationAction={
|
|
168
|
-
<Link startIcon={<ArrowLeft />} to="/settings/api-tokens">
|
|
169
|
-
{formatMessage({
|
|
170
|
-
id: 'global.back',
|
|
171
|
-
defaultMessage: 'Back',
|
|
172
|
-
})}
|
|
173
|
-
</Link>
|
|
174
|
-
}
|
|
175
|
-
/>
|
|
176
|
-
<ContentLayout>
|
|
177
|
-
<Stack spacing={6}>
|
|
178
|
-
{Boolean(apiToken?.name) && <HeaderContentBox apiToken={apiToken.accessKey} />}
|
|
179
|
-
<Box
|
|
180
|
-
background="neutral0"
|
|
181
|
-
hasRadius
|
|
182
|
-
shadow="filterShadow"
|
|
183
|
-
paddingTop={6}
|
|
184
|
-
paddingBottom={6}
|
|
185
|
-
paddingLeft={7}
|
|
186
|
-
paddingRight={7}
|
|
187
|
-
>
|
|
188
|
-
<Stack spacing={4}>
|
|
189
|
-
<Typography variant="delta" as="h2">
|
|
190
|
-
{formatMessage({
|
|
191
|
-
id: 'global.details',
|
|
192
|
-
defaultMessage: 'Details',
|
|
193
|
-
})}
|
|
194
|
-
</Typography>
|
|
195
|
-
<Grid gap={5}>
|
|
196
|
-
<GridItem key="name" col={6} xs={12}>
|
|
197
|
-
<TextInput
|
|
198
|
-
name="name"
|
|
199
|
-
error={
|
|
200
|
-
errors.name
|
|
201
|
-
? formatMessage(
|
|
202
|
-
errors.name?.id
|
|
203
|
-
? errors.name
|
|
204
|
-
: { id: errors.name, defaultMessage: errors.name }
|
|
205
|
-
)
|
|
206
|
-
: null
|
|
207
|
-
}
|
|
208
|
-
label={formatMessage({
|
|
209
|
-
id: 'Settings.apiTokens.form.name',
|
|
210
|
-
defaultMessage: 'Name',
|
|
211
|
-
})}
|
|
212
|
-
onChange={handleChange}
|
|
213
|
-
value={values.name}
|
|
214
|
-
required
|
|
298
|
+
<ApiTokenPermissionsContextProvider value={providerValue}>
|
|
299
|
+
<Main>
|
|
300
|
+
<SettingsPageTitle name="API Tokens" />
|
|
301
|
+
<Formik
|
|
302
|
+
validationSchema={schema}
|
|
303
|
+
validateOnChange={false}
|
|
304
|
+
initialValues={{
|
|
305
|
+
name: apiToken?.name || '',
|
|
306
|
+
description: apiToken?.description || '',
|
|
307
|
+
type: apiToken?.type,
|
|
308
|
+
lifespan: apiToken?.lifespan ? apiToken.lifespan.toString() : apiToken?.lifespan,
|
|
309
|
+
}}
|
|
310
|
+
enableReinitialize
|
|
311
|
+
onSubmit={(body, actions) => handleSubmit(body, actions)}
|
|
312
|
+
>
|
|
313
|
+
{({ errors, handleChange, isSubmitting, values, setFieldValue }) => {
|
|
314
|
+
if (hasChangedPermissions && values?.type !== 'custom') {
|
|
315
|
+
setFieldValue('type', 'custom');
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return (
|
|
319
|
+
<Form>
|
|
320
|
+
<HeaderLayout
|
|
321
|
+
title={
|
|
322
|
+
apiToken?.name ||
|
|
323
|
+
formatMessage({
|
|
324
|
+
id: 'Settings.apiTokens.createPage.title',
|
|
325
|
+
defaultMessage: 'Create API Token',
|
|
326
|
+
})
|
|
327
|
+
}
|
|
328
|
+
primaryAction={
|
|
329
|
+
canEditInputs ? (
|
|
330
|
+
<Stack horizontal spacing={2}>
|
|
331
|
+
{canRegenerate && apiToken?.id && (
|
|
332
|
+
<Regenerate
|
|
333
|
+
onRegenerate={handleRegenerate}
|
|
334
|
+
idToRegenerate={apiToken?.id}
|
|
215
335
|
/>
|
|
216
|
-
|
|
217
|
-
<
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
336
|
+
)}
|
|
337
|
+
<Button
|
|
338
|
+
disabled={isSubmitting}
|
|
339
|
+
loading={isSubmitting}
|
|
340
|
+
startIcon={<Check />}
|
|
341
|
+
type="submit"
|
|
342
|
+
size="S"
|
|
343
|
+
>
|
|
344
|
+
{formatMessage({
|
|
345
|
+
id: 'global.save',
|
|
346
|
+
defaultMessage: 'Save',
|
|
347
|
+
})}
|
|
348
|
+
</Button>
|
|
349
|
+
</Stack>
|
|
350
|
+
) : (
|
|
351
|
+
canRegenerate &&
|
|
352
|
+
apiToken?.id && (
|
|
353
|
+
<Regenerate onRegenerate={handleRegenerate} idToRegenerate={apiToken?.id} />
|
|
354
|
+
)
|
|
355
|
+
)
|
|
356
|
+
}
|
|
357
|
+
navigationAction={
|
|
358
|
+
<Link startIcon={<ArrowLeft />} to="/settings/api-tokens">
|
|
359
|
+
{formatMessage({
|
|
360
|
+
id: 'global.back',
|
|
361
|
+
defaultMessage: 'Back',
|
|
362
|
+
})}
|
|
363
|
+
</Link>
|
|
364
|
+
}
|
|
365
|
+
/>
|
|
366
|
+
<ContentLayout>
|
|
367
|
+
<Stack spacing={6}>
|
|
368
|
+
{Boolean(apiToken?.name) && <HeaderContentBox apiToken={apiToken.accessKey} />}
|
|
369
|
+
<Box
|
|
370
|
+
background="neutral0"
|
|
371
|
+
hasRadius
|
|
372
|
+
shadow="filterShadow"
|
|
373
|
+
paddingTop={6}
|
|
374
|
+
paddingBottom={6}
|
|
375
|
+
paddingLeft={7}
|
|
376
|
+
paddingRight={7}
|
|
377
|
+
>
|
|
378
|
+
<Stack spacing={4}>
|
|
379
|
+
<Typography variant="delta" as="h2">
|
|
380
|
+
{formatMessage({
|
|
381
|
+
id: 'global.details',
|
|
382
|
+
defaultMessage: 'Details',
|
|
383
|
+
})}
|
|
384
|
+
</Typography>
|
|
385
|
+
<Grid gap={5}>
|
|
386
|
+
<GridItem key="name" col={6} xs={12}>
|
|
387
|
+
<TextInput
|
|
388
|
+
name="name"
|
|
389
|
+
error={
|
|
390
|
+
errors.name
|
|
391
|
+
? formatMessage(
|
|
392
|
+
errors.name?.id
|
|
393
|
+
? errors.name
|
|
394
|
+
: { id: errors.name, defaultMessage: errors.name }
|
|
395
|
+
)
|
|
396
|
+
: null
|
|
397
|
+
}
|
|
398
|
+
label={formatMessage({
|
|
399
|
+
id: 'Settings.apiTokens.form.name',
|
|
400
|
+
defaultMessage: 'Name',
|
|
401
|
+
})}
|
|
402
|
+
onChange={handleChange}
|
|
403
|
+
value={values.name}
|
|
404
|
+
disabled={!canEditInputs}
|
|
405
|
+
required
|
|
406
|
+
/>
|
|
407
|
+
</GridItem>
|
|
408
|
+
<GridItem key="description" col={6} xs={12}>
|
|
409
|
+
<Textarea
|
|
410
|
+
label={formatMessage({
|
|
411
|
+
id: 'Settings.apiTokens.form.description',
|
|
412
|
+
defaultMessage: 'Description',
|
|
266
413
|
})}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
414
|
+
name="description"
|
|
415
|
+
error={
|
|
416
|
+
errors.description
|
|
417
|
+
? formatMessage(
|
|
418
|
+
errors.description?.id
|
|
419
|
+
? errors.description
|
|
420
|
+
: {
|
|
421
|
+
id: errors.description,
|
|
422
|
+
defaultMessage: errors.description,
|
|
423
|
+
}
|
|
424
|
+
)
|
|
425
|
+
: null
|
|
426
|
+
}
|
|
427
|
+
onChange={handleChange}
|
|
428
|
+
disabled={!canEditInputs}
|
|
429
|
+
>
|
|
430
|
+
{values.description}
|
|
431
|
+
</Textarea>
|
|
432
|
+
</GridItem>
|
|
433
|
+
<GridItem key="lifespan" col={6} xs={12}>
|
|
434
|
+
<Select
|
|
435
|
+
name="lifespan"
|
|
436
|
+
label={formatMessage({
|
|
437
|
+
id: 'Settings.apiTokens.form.duration',
|
|
438
|
+
defaultMessage: 'Token duration',
|
|
439
|
+
})}
|
|
440
|
+
value={values.lifespan}
|
|
441
|
+
error={
|
|
442
|
+
errors.lifespan
|
|
443
|
+
? formatMessage(
|
|
444
|
+
errors.lifespan?.id
|
|
445
|
+
? errors.lifespan
|
|
446
|
+
: { id: errors.lifespan, defaultMessage: errors.lifespan }
|
|
447
|
+
)
|
|
448
|
+
: null
|
|
449
|
+
}
|
|
450
|
+
onChange={(value) => {
|
|
451
|
+
handleChange({ target: { name: 'lifespan', value } });
|
|
452
|
+
}}
|
|
453
|
+
required
|
|
454
|
+
disabled={!isCreating}
|
|
455
|
+
placeholder="Select"
|
|
456
|
+
>
|
|
457
|
+
<Option value="604800000">
|
|
458
|
+
{formatMessage({
|
|
459
|
+
id: 'Settings.apiTokens.duration.7-days',
|
|
460
|
+
defaultMessage: '7 days',
|
|
461
|
+
})}
|
|
462
|
+
</Option>
|
|
463
|
+
<Option value="2592000000">
|
|
464
|
+
{formatMessage({
|
|
465
|
+
id: 'Settings.apiTokens.duration.30-days',
|
|
466
|
+
defaultMessage: '30 days',
|
|
467
|
+
})}
|
|
468
|
+
</Option>
|
|
469
|
+
<Option value="7776000000">
|
|
470
|
+
{formatMessage({
|
|
471
|
+
id: 'Settings.apiTokens.duration.90-days',
|
|
472
|
+
defaultMessage: '90 days',
|
|
473
|
+
})}
|
|
474
|
+
</Option>
|
|
475
|
+
<Option value={null}>
|
|
476
|
+
{formatMessage({
|
|
477
|
+
id: 'Settings.apiTokens.duration.unlimited',
|
|
478
|
+
defaultMessage: 'Unlimited',
|
|
479
|
+
})}
|
|
480
|
+
</Option>
|
|
481
|
+
</Select>
|
|
482
|
+
<Typography variant="pi" textColor="neutral600">
|
|
483
|
+
{!isCreating &&
|
|
484
|
+
`${formatMessage({
|
|
485
|
+
id: 'Settings.apiTokens.duration.expiration-date',
|
|
486
|
+
defaultMessage: 'Expiration date',
|
|
487
|
+
})}: ${getDateOfExpiration(
|
|
488
|
+
apiToken?.createdAt,
|
|
489
|
+
parseInt(values.lifespan, 10),
|
|
490
|
+
lang
|
|
491
|
+
)}`}
|
|
492
|
+
</Typography>
|
|
493
|
+
</GridItem>
|
|
494
|
+
|
|
495
|
+
<GridItem key="type" col={6} xs={12}>
|
|
496
|
+
<Select
|
|
497
|
+
name="type"
|
|
498
|
+
label={formatMessage({
|
|
499
|
+
id: 'Settings.apiTokens.form.type',
|
|
500
|
+
defaultMessage: 'Token type',
|
|
272
501
|
})}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
502
|
+
value={values?.type}
|
|
503
|
+
error={
|
|
504
|
+
errors.type
|
|
505
|
+
? formatMessage(
|
|
506
|
+
errors.type?.id
|
|
507
|
+
? errors.type
|
|
508
|
+
: { id: errors.type, defaultMessage: errors.type }
|
|
509
|
+
)
|
|
510
|
+
: null
|
|
511
|
+
}
|
|
512
|
+
onChange={(value) => {
|
|
513
|
+
handleChangeSelectApiTokenType({ target: { value } });
|
|
514
|
+
handleChange({ target: { name: 'type', value } });
|
|
515
|
+
}}
|
|
516
|
+
placeholder="Select"
|
|
517
|
+
required
|
|
518
|
+
disabled={!canEditInputs}
|
|
519
|
+
>
|
|
520
|
+
<Option value="read-only">
|
|
521
|
+
{formatMessage({
|
|
522
|
+
id: 'Settings.apiTokens.types.read-only',
|
|
523
|
+
defaultMessage: 'Read-only',
|
|
524
|
+
})}
|
|
525
|
+
</Option>
|
|
526
|
+
<Option value="full-access">
|
|
527
|
+
{formatMessage({
|
|
528
|
+
id: 'Settings.apiTokens.types.full-access',
|
|
529
|
+
defaultMessage: 'Full access',
|
|
530
|
+
})}
|
|
531
|
+
</Option>
|
|
532
|
+
<Option value="custom">
|
|
533
|
+
{formatMessage({
|
|
534
|
+
id: 'Settings.apiTokens.types.custom',
|
|
535
|
+
defaultMessage: 'Custom',
|
|
536
|
+
})}
|
|
537
|
+
</Option>
|
|
538
|
+
</Select>
|
|
539
|
+
</GridItem>
|
|
540
|
+
</Grid>
|
|
541
|
+
</Stack>
|
|
542
|
+
</Box>
|
|
543
|
+
<Permissions
|
|
544
|
+
disabled={
|
|
545
|
+
!canEditInputs ||
|
|
546
|
+
values?.type === 'read-only' ||
|
|
547
|
+
values?.type === 'full-access'
|
|
548
|
+
}
|
|
549
|
+
/>
|
|
550
|
+
</Stack>
|
|
551
|
+
</ContentLayout>
|
|
552
|
+
</Form>
|
|
553
|
+
);
|
|
554
|
+
}}
|
|
555
|
+
</Formik>
|
|
556
|
+
</Main>
|
|
557
|
+
</ApiTokenPermissionsContextProvider>
|
|
286
558
|
);
|
|
287
559
|
};
|
|
288
560
|
|