asab_webui_components 27.3.4 → 27.3.6
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/dist/seacat-auth/components/ButtonWithAuthz.js +5 -4
- package/dist/seacat-auth/components/LinkWithAuthz.js +4 -3
- package/dist/seacat-auth/components/Switches/ControlledSwitchWithAuthz.js +5 -4
- package/dist/seacat-auth/components/Switches/UncontrolledSwitchWithAuthz.js +5 -4
- package/dist/seacat-auth/utils/authz.js +34 -16
- package/dist/utils/ErrorHandler.js +4 -1
- package/package.json +1 -1
|
@@ -67,10 +67,11 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
67
67
|
|
|
68
68
|
function ButtonWithAuthz(props) {
|
|
69
69
|
var childProps = _objectSpread({}, props); // Create a new child component to have option to remove props
|
|
70
|
-
var
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
var {
|
|
71
|
+
disabled,
|
|
72
|
+
title,
|
|
73
|
+
hide
|
|
74
|
+
} = (0, _authz.authz)(childProps);
|
|
74
75
|
return hide && disabled ? null : /*#__PURE__*/_react.default.createElement(_reactstrap.Button, (0, _extends2.default)({}, childProps, {
|
|
75
76
|
title: title,
|
|
76
77
|
disabled: disabled
|
|
@@ -50,9 +50,10 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
50
50
|
|
|
51
51
|
function LinkWithAuthz(props) {
|
|
52
52
|
var childProps = _objectSpread({}, props);
|
|
53
|
-
var
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
var {
|
|
54
|
+
disabled,
|
|
55
|
+
title
|
|
56
|
+
} = (0, _authz.authz)(childProps);
|
|
56
57
|
return disabled ? /*#__PURE__*/_react.default.createElement("span", (0, _extends2.default)({
|
|
57
58
|
title: title
|
|
58
59
|
}, childProps), childProps.children) : /*#__PURE__*/_react.default.createElement(_reactRouter.Link, childProps, childProps.children);
|
|
@@ -63,10 +63,11 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
63
63
|
|
|
64
64
|
function ControlledSwitchWithAuthz(props) {
|
|
65
65
|
var childProps = _objectSpread({}, props); // Create a new child component to have option to remove props
|
|
66
|
-
var
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
var {
|
|
67
|
+
disabled,
|
|
68
|
+
title,
|
|
69
|
+
hide
|
|
70
|
+
} = (0, _authz.authz)(childProps);
|
|
70
71
|
return hide && disabled ? null : /*#__PURE__*/_react.default.createElement(_ControlledSwitch.ControlledSwitch, (0, _extends2.default)({}, childProps, {
|
|
71
72
|
title: title,
|
|
72
73
|
disabled: disabled
|
|
@@ -64,10 +64,11 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
64
64
|
|
|
65
65
|
function UncontrolledSwitchWithAuthz(props) {
|
|
66
66
|
var childProps = _objectSpread({}, props); // Create a new child component to have option to remove props
|
|
67
|
-
var
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
var {
|
|
68
|
+
disabled,
|
|
69
|
+
title,
|
|
70
|
+
hide
|
|
71
|
+
} = (0, _authz.authz)(childProps);
|
|
71
72
|
return hide && disabled ? null : /*#__PURE__*/_react.default.createElement(_UncontrolledSwitch.UncontrolledSwitch, (0, _extends2.default)({}, childProps, {
|
|
72
73
|
title: title,
|
|
73
74
|
disabled: disabled
|
|
@@ -8,33 +8,51 @@ var _reactI18next = require("react-i18next");
|
|
|
8
8
|
// Used for Button and Switches with authz
|
|
9
9
|
var authz = childProps => {
|
|
10
10
|
var {
|
|
11
|
-
t
|
|
12
|
-
i18n
|
|
11
|
+
t
|
|
13
12
|
} = (0, _reactI18next.useTranslation)();
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
var {
|
|
14
|
+
resources,
|
|
15
|
+
resource,
|
|
16
|
+
hideOnUnauthorizedAccess,
|
|
17
|
+
disabled: disabledProp,
|
|
18
|
+
title: titleProp
|
|
19
|
+
} = childProps;
|
|
20
|
+
var disabled = true;
|
|
21
|
+
|
|
22
|
+
// Check if the user has at least one of the required resources. Also, if user has 'authz:superuser', always allow
|
|
23
|
+
var requiredResources = Array.isArray(resource) ? resource : [resource];
|
|
24
|
+
|
|
25
|
+
// superuser always allow
|
|
26
|
+
if (resources !== null && resources !== void 0 && resources.includes('authz:superuser')) {
|
|
17
27
|
disabled = false;
|
|
28
|
+
} else {
|
|
29
|
+
// if at least one match is found — access is granted
|
|
30
|
+
var resourcesSet = new Set(resources);
|
|
31
|
+
disabled = !requiredResources.some(r => resourcesSet.has(r));
|
|
18
32
|
}
|
|
33
|
+
|
|
19
34
|
// If defined, hide the disabled button
|
|
20
|
-
var hide =
|
|
35
|
+
var hide = Boolean(hideOnUnauthorizedAccess);
|
|
36
|
+
|
|
21
37
|
// Remove hideOnUnauthorized element from props to avoid react warnings
|
|
22
|
-
if (
|
|
23
|
-
delete childProps
|
|
38
|
+
if (hideOnUnauthorizedAccess) {
|
|
39
|
+
delete childProps.hideOnUnauthorizedAccess;
|
|
24
40
|
}
|
|
25
|
-
|
|
26
|
-
//
|
|
41
|
+
|
|
42
|
+
// Set the title for unauthorized state
|
|
43
|
+
var title = titleProp;
|
|
27
44
|
if (disabled) {
|
|
28
|
-
title = t(
|
|
45
|
+
title = t('General|You do not have access rights to perform this action');
|
|
29
46
|
}
|
|
47
|
+
|
|
30
48
|
// Check on disabled eventually passed in the props
|
|
31
|
-
if (
|
|
32
|
-
disabled =
|
|
49
|
+
if (disabledProp && disabled === false) {
|
|
50
|
+
disabled = disabledProp;
|
|
33
51
|
}
|
|
34
52
|
return {
|
|
35
|
-
disabled
|
|
36
|
-
hide
|
|
37
|
-
title
|
|
53
|
+
disabled,
|
|
54
|
+
hide,
|
|
55
|
+
title
|
|
38
56
|
};
|
|
39
57
|
};
|
|
40
58
|
exports.authz = authz;
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.ErrorHandler = ErrorHandler;
|
|
7
7
|
var _reactI18next = require("react-i18next");
|
|
8
|
+
// TODO: REMOVE/REWRITE THIS COMPONENT AFTER ALL DEPENDENCY ON ERRORHANDLER COMPONENT IS STRIPPED
|
|
9
|
+
|
|
8
10
|
/*
|
|
9
11
|
- Component responsible for handling and displaying error messages.
|
|
10
12
|
- The 'error' prop is an object that contains the error message and any which contains a dictionary with variables, if any, in the error message.
|
|
@@ -21,8 +23,9 @@ function ErrorHandler(_ref) {
|
|
|
21
23
|
t
|
|
22
24
|
} = (0, _reactI18next.useTranslation)();
|
|
23
25
|
if (error.error_dict) {
|
|
26
|
+
// Always escape the values (safety precaution), do not change this!
|
|
24
27
|
error.error_dict['interpolation'] = {
|
|
25
|
-
escapeValue:
|
|
28
|
+
escapeValue: true
|
|
26
29
|
};
|
|
27
30
|
}
|
|
28
31
|
return t(error.error, error.error_dict);
|