@webiny/app-security-access-management 0.0.0-mt-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/LICENSE +21 -0
- package/README.md +115 -0
- package/components/GroupAutocomplete/graphql.d.ts +1 -0
- package/components/GroupAutocomplete/graphql.js +6 -0
- package/components/GroupAutocomplete/index.d.ts +2 -0
- package/components/GroupAutocomplete/index.js +16 -0
- package/components/NotAuthorizedError/NotAuthorizedError.d.ts +2 -0
- package/components/NotAuthorizedError/NotAuthorizedError.js +50 -0
- package/components/NotAuthorizedError/SecureRouteError.svg +1 -0
- package/components/NotAuthorizedError/index.d.ts +1 -0
- package/components/NotAuthorizedError/index.js +1 -0
- package/index.d.ts +2 -0
- package/index.js +4 -0
- package/package.json +70 -0
- package/plugins/constants.d.ts +4 -0
- package/plugins/constants.js +6 -0
- package/plugins/index.d.ts +3 -0
- package/plugins/index.js +8 -0
- package/plugins/installation.d.ts +3 -0
- package/plugins/installation.js +99 -0
- package/plugins/menus.d.ts +4 -0
- package/plugins/menus.js +61 -0
- package/plugins/permissionRenderer/SecurityPermissions.d.ts +5 -0
- package/plugins/permissionRenderer/SecurityPermissions.js +176 -0
- package/plugins/permissionRenderer/index.d.ts +3 -0
- package/plugins/permissionRenderer/index.js +21 -0
- package/plugins/routes.d.ts +3 -0
- package/plugins/routes.js +38 -0
- package/plugins/secureRouteError.d.ts +7 -0
- package/plugins/secureRouteError.js +10 -0
- package/ui/elements/GroupAutocompleteElement.d.ts +5 -0
- package/ui/elements/GroupAutocompleteElement.js +35 -0
- package/ui/views/ApiKeys/ApiKeyForm.d.ts +3 -0
- package/ui/views/ApiKeys/ApiKeyForm.js +244 -0
- package/ui/views/ApiKeys/ApiKeys.d.ts +3 -0
- package/ui/views/ApiKeys/ApiKeys.js +12 -0
- package/ui/views/ApiKeys/ApiKeysDataList.d.ts +3 -0
- package/ui/views/ApiKeys/ApiKeysDataList.js +209 -0
- package/ui/views/ApiKeys/graphql.d.ts +5 -0
- package/ui/views/ApiKeys/graphql.js +11 -0
- package/ui/views/ApiKeys/index.d.ts +1 -0
- package/ui/views/ApiKeys/index.js +1 -0
- package/ui/views/ApiKeys/utils.d.ts +1 -0
- package/ui/views/ApiKeys/utils.js +5 -0
- package/ui/views/Groups/Groups.d.ts +3 -0
- package/ui/views/Groups/Groups.js +12 -0
- package/ui/views/Groups/GroupsDataList.d.ts +3 -0
- package/ui/views/Groups/GroupsDataList.js +215 -0
- package/ui/views/Groups/GroupsForm.d.ts +3 -0
- package/ui/views/Groups/GroupsForm.js +234 -0
- package/ui/views/Groups/graphql.d.ts +5 -0
- package/ui/views/Groups/graphql.js +11 -0
- package/ui/views/Groups/index.d.ts +1 -0
- package/ui/views/Groups/index.js +1 -0
- package/ui/views/utils.d.ts +2 -0
- package/ui/views/utils.js +27 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
|
|
2
|
+
|
|
3
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13;
|
|
4
|
+
|
|
5
|
+
import React, { Fragment, useCallback, useMemo } from "react";
|
|
6
|
+
import { Grid, Cell } from "@webiny/ui/Grid";
|
|
7
|
+
import { Select } from "@webiny/ui/Select";
|
|
8
|
+
import { i18n } from "@webiny/app/i18n";
|
|
9
|
+
import { PermissionInfo, gridNoPaddingClass } from "@webiny/app-admin/components/Permissions";
|
|
10
|
+
import { Form } from "@webiny/form";
|
|
11
|
+
import { Elevation } from "@webiny/ui/Elevation";
|
|
12
|
+
import { Typography } from "@webiny/ui/Typography";
|
|
13
|
+
var t = i18n.ns("app-security-admin-users/plugins/permissionRenderer");
|
|
14
|
+
var SECURITY = "security";
|
|
15
|
+
var SECURITY_FULL_ACCESS = "".concat(SECURITY, ".*");
|
|
16
|
+
var SECURITY_GROUP_ACCESS = "".concat(SECURITY, ".group");
|
|
17
|
+
var SECURITY_API_KEY_ACCESS = "".concat(SECURITY, ".apiKey");
|
|
18
|
+
var FULL_ACCESS = "full";
|
|
19
|
+
var NO_ACCESS = "no";
|
|
20
|
+
var CUSTOM_ACCESS = "custom";
|
|
21
|
+
export var SecurityPermissions = function SecurityPermissions(_ref) {
|
|
22
|
+
var value = _ref.value,
|
|
23
|
+
onChange = _ref.onChange;
|
|
24
|
+
var onFormChange = useCallback(function (data) {
|
|
25
|
+
var newValue = [];
|
|
26
|
+
|
|
27
|
+
if (Array.isArray(value)) {
|
|
28
|
+
// Let's just filter out the `security*` permission objects, it's easier to build new ones from scratch.
|
|
29
|
+
newValue = value.filter(function (item) {
|
|
30
|
+
return !item.name.startsWith(SECURITY);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var permissions = [];
|
|
35
|
+
|
|
36
|
+
if (data.accessLevel === FULL_ACCESS) {
|
|
37
|
+
permissions.push({
|
|
38
|
+
name: SECURITY_FULL_ACCESS
|
|
39
|
+
});
|
|
40
|
+
} else if (data.accessLevel === CUSTOM_ACCESS) {
|
|
41
|
+
if (data.groupAccessScope === FULL_ACCESS) {
|
|
42
|
+
permissions.push({
|
|
43
|
+
name: SECURITY_GROUP_ACCESS
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (data.apiKeyAccessScope === FULL_ACCESS) {
|
|
48
|
+
permissions.push({
|
|
49
|
+
name: SECURITY_API_KEY_ACCESS
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (permissions && permissions.length) {
|
|
55
|
+
var _newValue;
|
|
56
|
+
|
|
57
|
+
(_newValue = newValue).push.apply(_newValue, permissions);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
onChange(newValue);
|
|
61
|
+
}, [value]);
|
|
62
|
+
var formData = useMemo(function () {
|
|
63
|
+
if (!Array.isArray(value)) {
|
|
64
|
+
return {
|
|
65
|
+
accessLevel: NO_ACCESS
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
var hasFullAccess = value.find(function (item) {
|
|
70
|
+
return item.name === SECURITY_FULL_ACCESS || item.name === "*";
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
if (hasFullAccess) {
|
|
74
|
+
return {
|
|
75
|
+
accessLevel: FULL_ACCESS
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
var permissions = value.filter(function (item) {
|
|
80
|
+
return item.name.startsWith(SECURITY);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
if (permissions.length === 0) {
|
|
84
|
+
return {
|
|
85
|
+
accessLevel: NO_ACCESS
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
var data = {
|
|
90
|
+
accessLevel: CUSTOM_ACCESS,
|
|
91
|
+
groupAccessScope: NO_ACCESS,
|
|
92
|
+
apiKeyAccessScope: NO_ACCESS
|
|
93
|
+
};
|
|
94
|
+
var hasGroupAccess = permissions.find(function (item) {
|
|
95
|
+
return item.name === SECURITY_GROUP_ACCESS;
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
if (hasGroupAccess) {
|
|
99
|
+
data.groupAccessScope = FULL_ACCESS;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
var hasApiKeyAccess = permissions.find(function (item) {
|
|
103
|
+
return item.name === SECURITY_API_KEY_ACCESS;
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
if (hasApiKeyAccess) {
|
|
107
|
+
data.apiKeyAccessScope = FULL_ACCESS;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return data;
|
|
111
|
+
}, []);
|
|
112
|
+
return /*#__PURE__*/React.createElement(Form, {
|
|
113
|
+
data: formData,
|
|
114
|
+
onChange: onFormChange
|
|
115
|
+
}, function (_ref2) {
|
|
116
|
+
var data = _ref2.data,
|
|
117
|
+
Bind = _ref2.Bind;
|
|
118
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Grid, {
|
|
119
|
+
className: gridNoPaddingClass
|
|
120
|
+
}, /*#__PURE__*/React.createElement(Cell, {
|
|
121
|
+
span: 6
|
|
122
|
+
}, /*#__PURE__*/React.createElement(PermissionInfo, {
|
|
123
|
+
title: t(_templateObject || (_templateObject = _taggedTemplateLiteral(["Access Level"])))
|
|
124
|
+
})), /*#__PURE__*/React.createElement(Cell, {
|
|
125
|
+
span: 6
|
|
126
|
+
}, /*#__PURE__*/React.createElement(Bind, {
|
|
127
|
+
name: "accessLevel"
|
|
128
|
+
}, /*#__PURE__*/React.createElement(Select, {
|
|
129
|
+
label: t(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["Access Level"])))
|
|
130
|
+
}, /*#__PURE__*/React.createElement("option", {
|
|
131
|
+
value: NO_ACCESS
|
|
132
|
+
}, t(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["No access"])))), /*#__PURE__*/React.createElement("option", {
|
|
133
|
+
value: FULL_ACCESS
|
|
134
|
+
}, t(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["Full access"])))), /*#__PURE__*/React.createElement("option", {
|
|
135
|
+
value: CUSTOM_ACCESS
|
|
136
|
+
}, t(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["Custom access"])))))))), data.accessLevel === CUSTOM_ACCESS && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Elevation, {
|
|
137
|
+
z: 1,
|
|
138
|
+
style: {
|
|
139
|
+
marginTop: 10
|
|
140
|
+
}
|
|
141
|
+
}, /*#__PURE__*/React.createElement(Grid, null, /*#__PURE__*/React.createElement(Cell, {
|
|
142
|
+
span: 12
|
|
143
|
+
}, /*#__PURE__*/React.createElement(Typography, {
|
|
144
|
+
use: "overline"
|
|
145
|
+
}, t(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["API Keys"]))))), /*#__PURE__*/React.createElement(Cell, {
|
|
146
|
+
span: 12
|
|
147
|
+
}, /*#__PURE__*/React.createElement(Bind, {
|
|
148
|
+
name: "apiKeyAccessScope"
|
|
149
|
+
}, /*#__PURE__*/React.createElement(Select, {
|
|
150
|
+
label: t(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["Access Scope"])))
|
|
151
|
+
}, /*#__PURE__*/React.createElement("option", {
|
|
152
|
+
value: NO_ACCESS
|
|
153
|
+
}, t(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["No access"])))), /*#__PURE__*/React.createElement("option", {
|
|
154
|
+
value: FULL_ACCESS
|
|
155
|
+
}, t(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["Full access"]))))))))), /*#__PURE__*/React.createElement(Elevation, {
|
|
156
|
+
z: 1,
|
|
157
|
+
style: {
|
|
158
|
+
marginTop: 10
|
|
159
|
+
}
|
|
160
|
+
}, /*#__PURE__*/React.createElement(Grid, null, /*#__PURE__*/React.createElement(Cell, {
|
|
161
|
+
span: 12
|
|
162
|
+
}, /*#__PURE__*/React.createElement(Typography, {
|
|
163
|
+
use: "overline"
|
|
164
|
+
}, t(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["Groups"]))))), /*#__PURE__*/React.createElement(Cell, {
|
|
165
|
+
span: 12
|
|
166
|
+
}, /*#__PURE__*/React.createElement(Bind, {
|
|
167
|
+
name: "groupAccessScope"
|
|
168
|
+
}, /*#__PURE__*/React.createElement(Select, {
|
|
169
|
+
label: t(_templateObject11 || (_templateObject11 = _taggedTemplateLiteral(["Access Scope"])))
|
|
170
|
+
}, /*#__PURE__*/React.createElement("option", {
|
|
171
|
+
value: NO_ACCESS
|
|
172
|
+
}, t(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["No access"])))), /*#__PURE__*/React.createElement("option", {
|
|
173
|
+
value: FULL_ACCESS
|
|
174
|
+
}, t(_templateObject13 || (_templateObject13 = _taggedTemplateLiteral(["Full access"])))))))))));
|
|
175
|
+
});
|
|
176
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
|
|
2
|
+
|
|
3
|
+
var _templateObject, _templateObject2;
|
|
4
|
+
|
|
5
|
+
import React from "react";
|
|
6
|
+
import { i18n } from "@webiny/app/i18n";
|
|
7
|
+
import { AccordionItem } from "@webiny/ui/Accordion";
|
|
8
|
+
import { ReactComponent as SecurityIcon } from "@svgr/webpack!@webiny/app-admin/assets/icons/baseline-security-24px.svg";
|
|
9
|
+
import { SecurityPermissions } from "./SecurityPermissions";
|
|
10
|
+
import { PermissionRendererPlugin } from "@webiny/app-admin/plugins/PermissionRendererPlugin";
|
|
11
|
+
var t = i18n.ns("app-security-admin-users/plugins/permissionRenderer");
|
|
12
|
+
export default new PermissionRendererPlugin({
|
|
13
|
+
render: function render(props) {
|
|
14
|
+
return /*#__PURE__*/React.createElement(AccordionItem, {
|
|
15
|
+
icon: /*#__PURE__*/React.createElement(SecurityIcon, null),
|
|
16
|
+
title: t(_templateObject || (_templateObject = _taggedTemplateLiteral(["Security"]))),
|
|
17
|
+
description: t(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["Manage Security app access permissions."]))),
|
|
18
|
+
"data-testid": "permission.security"
|
|
19
|
+
}, /*#__PURE__*/React.createElement(SecurityPermissions, props));
|
|
20
|
+
}
|
|
21
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import Helmet from "react-helmet";
|
|
3
|
+
import { Route } from "@webiny/react-router";
|
|
4
|
+
import { AdminLayout } from "@webiny/app-admin/components/AdminLayout";
|
|
5
|
+
import { SecureRoute } from "@webiny/app-security/components";
|
|
6
|
+
import { Groups } from "../ui/views/Groups";
|
|
7
|
+
import { ApiKeys } from "../ui/views/ApiKeys";
|
|
8
|
+
import { Permission } from "./constants";
|
|
9
|
+
var plugins = [{
|
|
10
|
+
name: "route-security-groups",
|
|
11
|
+
type: "route",
|
|
12
|
+
route: /*#__PURE__*/React.createElement(Route, {
|
|
13
|
+
exact: true,
|
|
14
|
+
path: "/access-management/groups",
|
|
15
|
+
render: function render() {
|
|
16
|
+
return /*#__PURE__*/React.createElement(SecureRoute, {
|
|
17
|
+
permission: Permission.Groups
|
|
18
|
+
}, /*#__PURE__*/React.createElement(AdminLayout, null, /*#__PURE__*/React.createElement(Helmet, {
|
|
19
|
+
title: "Access Management - Groups"
|
|
20
|
+
}), /*#__PURE__*/React.createElement(Groups, null)));
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
}, {
|
|
24
|
+
name: "route-security-api-keys",
|
|
25
|
+
type: "route",
|
|
26
|
+
route: /*#__PURE__*/React.createElement(Route, {
|
|
27
|
+
exact: true,
|
|
28
|
+
path: "/access-management/api-keys",
|
|
29
|
+
render: function render() {
|
|
30
|
+
return /*#__PURE__*/React.createElement(SecureRoute, {
|
|
31
|
+
permission: Permission.ApiKeys
|
|
32
|
+
}, /*#__PURE__*/React.createElement(AdminLayout, {
|
|
33
|
+
title: "Access Management - API Keys"
|
|
34
|
+
}, /*#__PURE__*/React.createElement(ApiKeys, null)));
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
}];
|
|
38
|
+
export default plugins;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { NotAuthorizedError } from "../components/NotAuthorizedError";
|
|
3
|
+
var plugin = {
|
|
4
|
+
type: "secure-route-error",
|
|
5
|
+
name: "secure-route-error",
|
|
6
|
+
render: function render() {
|
|
7
|
+
return /*#__PURE__*/React.createElement(NotAuthorizedError, null);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
export default plugin;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
4
|
+
import _createSuper from "@babel/runtime/helpers/createSuper";
|
|
5
|
+
import React from "react";
|
|
6
|
+
import { InputElement } from "@webiny/app-admin/ui/elements/form/InputElement";
|
|
7
|
+
import { GroupAutocomplete } from "../../components/GroupAutocomplete";
|
|
8
|
+
export var GroupAutocompleteElement = /*#__PURE__*/function (_InputElement) {
|
|
9
|
+
_inherits(GroupAutocompleteElement, _InputElement);
|
|
10
|
+
|
|
11
|
+
var _super = _createSuper(GroupAutocompleteElement);
|
|
12
|
+
|
|
13
|
+
function GroupAutocompleteElement() {
|
|
14
|
+
_classCallCheck(this, GroupAutocompleteElement);
|
|
15
|
+
|
|
16
|
+
return _super.apply(this, arguments);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
_createClass(GroupAutocompleteElement, [{
|
|
20
|
+
key: "render",
|
|
21
|
+
value: function render(_ref) {
|
|
22
|
+
var formProps = _ref.formProps;
|
|
23
|
+
var _ref2 = formProps,
|
|
24
|
+
Bind = _ref2.Bind;
|
|
25
|
+
return /*#__PURE__*/React.createElement(Bind, {
|
|
26
|
+
name: this.id,
|
|
27
|
+
validators: this.config.validators
|
|
28
|
+
}, /*#__PURE__*/React.createElement(GroupAutocomplete, {
|
|
29
|
+
label: "Group"
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
}]);
|
|
33
|
+
|
|
34
|
+
return GroupAutocompleteElement;
|
|
35
|
+
}(InputElement);
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
|
+
|
|
5
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10;
|
|
6
|
+
|
|
7
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
8
|
+
import React, { useCallback } from "react";
|
|
9
|
+
import { useMutation, useQuery } from "@apollo/react-hooks";
|
|
10
|
+
import get from "lodash/get";
|
|
11
|
+
import { useRouter } from "@webiny/react-router";
|
|
12
|
+
import { i18n } from "@webiny/app/i18n";
|
|
13
|
+
import { Form } from "@webiny/form";
|
|
14
|
+
import { Grid, Cell } from "@webiny/ui/Grid";
|
|
15
|
+
import { Input } from "@webiny/ui/Input";
|
|
16
|
+
import { ButtonDefault, ButtonIcon, ButtonPrimary, CopyButton } from "@webiny/ui/Button";
|
|
17
|
+
import { CircularProgress } from "@webiny/ui/Progress";
|
|
18
|
+
import { FormElementMessage } from "@webiny/ui/FormElementMessage";
|
|
19
|
+
import { Permissions } from "@webiny/app-admin/components/Permissions";
|
|
20
|
+
import { validation } from "@webiny/validation";
|
|
21
|
+
import { SimpleForm, SimpleFormFooter, SimpleFormContent, SimpleFormHeader } from "@webiny/app-admin/components/SimpleForm";
|
|
22
|
+
import { Typography } from "@webiny/ui/Typography";
|
|
23
|
+
import { useSnackbar } from "@webiny/app-admin/hooks/useSnackbar";
|
|
24
|
+
import { pickDataForAPI } from "./utils";
|
|
25
|
+
import * as GQL from "./graphql";
|
|
26
|
+
import { SnackbarAction } from "@webiny/ui/Snackbar";
|
|
27
|
+
import isEmpty from "lodash/isEmpty";
|
|
28
|
+
import EmptyView from "@webiny/app-admin/components/EmptyView";
|
|
29
|
+
import { ReactComponent as AddIcon } from "@svgr/webpack!@webiny/app-admin/assets/icons/add-18px.svg";
|
|
30
|
+
import styled from "@emotion/styled";
|
|
31
|
+
var t = i18n.ns("app-security-admin-users/admin/api-keys/form");
|
|
32
|
+
var ButtonWrapper = /*#__PURE__*/styled("div", {
|
|
33
|
+
target: "e18bg2x40",
|
|
34
|
+
label: "ButtonWrapper"
|
|
35
|
+
})({
|
|
36
|
+
display: "flex",
|
|
37
|
+
justifyContent: "space-between"
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
var ApiKeyForm = function ApiKeyForm() {
|
|
41
|
+
var _useRouter = useRouter(),
|
|
42
|
+
location = _useRouter.location,
|
|
43
|
+
history = _useRouter.history;
|
|
44
|
+
|
|
45
|
+
var _useSnackbar = useSnackbar(),
|
|
46
|
+
showSnackbar = _useSnackbar.showSnackbar;
|
|
47
|
+
|
|
48
|
+
var newEntry = new URLSearchParams(location.search).get("new") === "true";
|
|
49
|
+
var id = new URLSearchParams(location.search).get("id");
|
|
50
|
+
var getQuery = useQuery(GQL.READ_API_KEY, {
|
|
51
|
+
variables: {
|
|
52
|
+
id: id
|
|
53
|
+
},
|
|
54
|
+
skip: !id,
|
|
55
|
+
onCompleted: function onCompleted(data) {
|
|
56
|
+
if (!data) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
var error = data.security.apiKey.error;
|
|
61
|
+
|
|
62
|
+
if (error) {
|
|
63
|
+
history.push("/access-management/api-keys");
|
|
64
|
+
showSnackbar(error.message);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
var _useMutation = useMutation(GQL.CREATE_API_KEY, {
|
|
70
|
+
refetchQueries: [{
|
|
71
|
+
query: GQL.LIST_API_KEYS
|
|
72
|
+
}]
|
|
73
|
+
}),
|
|
74
|
+
_useMutation2 = _slicedToArray(_useMutation, 2),
|
|
75
|
+
create = _useMutation2[0],
|
|
76
|
+
createMutation = _useMutation2[1];
|
|
77
|
+
|
|
78
|
+
var _useMutation3 = useMutation(GQL.UPDATE_API_KEY, {
|
|
79
|
+
refetchQueries: [{
|
|
80
|
+
query: GQL.LIST_API_KEYS
|
|
81
|
+
}]
|
|
82
|
+
}),
|
|
83
|
+
_useMutation4 = _slicedToArray(_useMutation3, 2),
|
|
84
|
+
update = _useMutation4[0],
|
|
85
|
+
updateMutation = _useMutation4[1];
|
|
86
|
+
|
|
87
|
+
var loading = [getQuery, createMutation, updateMutation].find(function (item) {
|
|
88
|
+
return item.loading;
|
|
89
|
+
});
|
|
90
|
+
var onSubmit = useCallback( /*#__PURE__*/function () {
|
|
91
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(data) {
|
|
92
|
+
var isUpdate, _ref2, _ref3, operation, args, response, error, id;
|
|
93
|
+
|
|
94
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
95
|
+
while (1) {
|
|
96
|
+
switch (_context.prev = _context.next) {
|
|
97
|
+
case 0:
|
|
98
|
+
if (!(!data.permissions || !data.permissions.length)) {
|
|
99
|
+
_context.next = 3;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
showSnackbar(t(_templateObject || (_templateObject = _taggedTemplateLiteral(["You must configure permissions before saving!"]))), {
|
|
104
|
+
timeout: 60000,
|
|
105
|
+
dismissesOnAction: true,
|
|
106
|
+
action: /*#__PURE__*/React.createElement(SnackbarAction, {
|
|
107
|
+
label: "OK"
|
|
108
|
+
})
|
|
109
|
+
});
|
|
110
|
+
return _context.abrupt("return");
|
|
111
|
+
|
|
112
|
+
case 3:
|
|
113
|
+
isUpdate = data.createdOn;
|
|
114
|
+
_ref2 = isUpdate ? [update, {
|
|
115
|
+
variables: {
|
|
116
|
+
id: data.id,
|
|
117
|
+
data: pickDataForAPI(data)
|
|
118
|
+
}
|
|
119
|
+
}] : [create, {
|
|
120
|
+
variables: {
|
|
121
|
+
data: pickDataForAPI(data)
|
|
122
|
+
}
|
|
123
|
+
}], _ref3 = _slicedToArray(_ref2, 2), operation = _ref3[0], args = _ref3[1];
|
|
124
|
+
_context.next = 7;
|
|
125
|
+
return operation(args);
|
|
126
|
+
|
|
127
|
+
case 7:
|
|
128
|
+
response = _context.sent;
|
|
129
|
+
error = response.data.security.apiKey.error;
|
|
130
|
+
|
|
131
|
+
if (!error) {
|
|
132
|
+
_context.next = 11;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return _context.abrupt("return", showSnackbar(error.message));
|
|
137
|
+
|
|
138
|
+
case 11:
|
|
139
|
+
id = response.data.security.apiKey.data.id;
|
|
140
|
+
!isUpdate && history.push("/access-management/api-keys?id=".concat(id));
|
|
141
|
+
showSnackbar(t(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["API key saved successfully."]))));
|
|
142
|
+
|
|
143
|
+
case 14:
|
|
144
|
+
case "end":
|
|
145
|
+
return _context.stop();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}, _callee);
|
|
149
|
+
}));
|
|
150
|
+
|
|
151
|
+
return function (_x) {
|
|
152
|
+
return _ref.apply(this, arguments);
|
|
153
|
+
};
|
|
154
|
+
}(), [id]);
|
|
155
|
+
var data = get(getQuery, "data.security.apiKey.data", {});
|
|
156
|
+
var showEmptyView = !newEntry && !loading && isEmpty(data); // Render "No content" selected view.
|
|
157
|
+
|
|
158
|
+
if (showEmptyView) {
|
|
159
|
+
return /*#__PURE__*/React.createElement(EmptyView, {
|
|
160
|
+
title: t(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["Click on the left side list to display API key details or create a..."]))),
|
|
161
|
+
action: /*#__PURE__*/React.createElement(ButtonDefault, {
|
|
162
|
+
"data-testid": "new-record-button",
|
|
163
|
+
onClick: function onClick() {
|
|
164
|
+
return history.push("/access-management/api-keys?new=true");
|
|
165
|
+
}
|
|
166
|
+
}, /*#__PURE__*/React.createElement(ButtonIcon, {
|
|
167
|
+
icon: /*#__PURE__*/React.createElement(AddIcon, null)
|
|
168
|
+
}), " ", t(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["New API Key"]))))
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return /*#__PURE__*/React.createElement(Form, {
|
|
173
|
+
data: data,
|
|
174
|
+
onSubmit: onSubmit
|
|
175
|
+
}, function (_ref4) {
|
|
176
|
+
var data = _ref4.data,
|
|
177
|
+
form = _ref4.form,
|
|
178
|
+
Bind = _ref4.Bind;
|
|
179
|
+
return /*#__PURE__*/React.createElement(SimpleForm, null, loading && /*#__PURE__*/React.createElement(CircularProgress, null), /*#__PURE__*/React.createElement(SimpleFormHeader, {
|
|
180
|
+
title: data.name ? data.name : "Untitled"
|
|
181
|
+
}), /*#__PURE__*/React.createElement(SimpleFormContent, null, /*#__PURE__*/React.createElement(Grid, null, /*#__PURE__*/React.createElement(Cell, {
|
|
182
|
+
span: 12
|
|
183
|
+
}, /*#__PURE__*/React.createElement(Bind, {
|
|
184
|
+
name: "name",
|
|
185
|
+
validators: validation.create("required")
|
|
186
|
+
}, /*#__PURE__*/React.createElement(Input, {
|
|
187
|
+
label: t(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["Name"])))
|
|
188
|
+
})))), /*#__PURE__*/React.createElement(Grid, null, /*#__PURE__*/React.createElement(Cell, {
|
|
189
|
+
span: 12
|
|
190
|
+
}, /*#__PURE__*/React.createElement(Bind, {
|
|
191
|
+
name: "description",
|
|
192
|
+
validators: validation.create("required")
|
|
193
|
+
}, /*#__PURE__*/React.createElement(Input, {
|
|
194
|
+
label: t(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["Description"]))),
|
|
195
|
+
rows: 4
|
|
196
|
+
})))), /*#__PURE__*/React.createElement(Grid, null, /*#__PURE__*/React.createElement(Cell, {
|
|
197
|
+
span: 12
|
|
198
|
+
}, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Typography, {
|
|
199
|
+
use: "subtitle1"
|
|
200
|
+
}, t(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["Token"])))), data.token ? /*#__PURE__*/React.createElement("div", {
|
|
201
|
+
style: {
|
|
202
|
+
background: "var(--mdc-theme-background)",
|
|
203
|
+
padding: "8px",
|
|
204
|
+
paddingLeft: "16px"
|
|
205
|
+
}
|
|
206
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
207
|
+
style: {
|
|
208
|
+
lineHeight: "48px",
|
|
209
|
+
verticalAlign: "middle"
|
|
210
|
+
}
|
|
211
|
+
}, data.token), /*#__PURE__*/React.createElement("span", {
|
|
212
|
+
style: {
|
|
213
|
+
position: "absolute",
|
|
214
|
+
right: "32px"
|
|
215
|
+
}
|
|
216
|
+
}, /*#__PURE__*/React.createElement(CopyButton, {
|
|
217
|
+
value: data.token,
|
|
218
|
+
onCopy: function onCopy() {
|
|
219
|
+
return showSnackbar("Successfully copied!");
|
|
220
|
+
}
|
|
221
|
+
}))) : /*#__PURE__*/React.createElement(FormElementMessage, null, "Your token will be shown once you submit the form.")))), /*#__PURE__*/React.createElement(Grid, null, /*#__PURE__*/React.createElement(Cell, {
|
|
222
|
+
span: 12
|
|
223
|
+
}, /*#__PURE__*/React.createElement(Typography, {
|
|
224
|
+
use: "subtitle1"
|
|
225
|
+
}, t(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["Permissions"]))))), /*#__PURE__*/React.createElement(Cell, {
|
|
226
|
+
span: 12
|
|
227
|
+
}, /*#__PURE__*/React.createElement(Bind, {
|
|
228
|
+
name: "permissions",
|
|
229
|
+
defaultValue: []
|
|
230
|
+
}, function (bind) {
|
|
231
|
+
return /*#__PURE__*/React.createElement(Permissions, Object.assign({
|
|
232
|
+
id: data.id || "new"
|
|
233
|
+
}, bind));
|
|
234
|
+
})))), /*#__PURE__*/React.createElement(SimpleFormFooter, null, /*#__PURE__*/React.createElement(ButtonWrapper, null, /*#__PURE__*/React.createElement(ButtonDefault, {
|
|
235
|
+
onClick: function onClick() {
|
|
236
|
+
return history.push("/access-management/api-keys");
|
|
237
|
+
}
|
|
238
|
+
}, t(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["Cancel"])))), /*#__PURE__*/React.createElement(ButtonPrimary, {
|
|
239
|
+
onClick: form.submit
|
|
240
|
+
}, t(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["Save API key"])))))));
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
export default ApiKeyForm;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { SplitView, LeftPanel, RightPanel } from "@webiny/app-admin/components/SplitView";
|
|
3
|
+
import ApiKeysDataList from "./ApiKeysDataList";
|
|
4
|
+
import ApiKeyForm from "./ApiKeyForm";
|
|
5
|
+
|
|
6
|
+
var ApiKeys = function ApiKeys(_ref) {
|
|
7
|
+
var formProps = _ref.formProps,
|
|
8
|
+
listProps = _ref.listProps;
|
|
9
|
+
return /*#__PURE__*/React.createElement(SplitView, null, /*#__PURE__*/React.createElement(LeftPanel, null, /*#__PURE__*/React.createElement(ApiKeysDataList, listProps)), /*#__PURE__*/React.createElement(RightPanel, null, /*#__PURE__*/React.createElement(ApiKeyForm, formProps)));
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default ApiKeys;
|