asab_webui_components 27.3.3 → 27.3.5

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.
@@ -234,7 +234,7 @@ function DataTableCardContent(_ref2) {
234
234
  }
235
235
  };
236
236
  return /*#__PURE__*/_react.default.createElement("div", {
237
- className: "card",
237
+ className: "card ".concat(className || ''),
238
238
  ref: cardRef
239
239
  }, /*#__PURE__*/_react.default.createElement(_reactstrap.CardHeader, {
240
240
  className: "card-header-flex"
@@ -182,7 +182,7 @@ function DataTableCardContent({ columns, loader, loaderParams, header, className
182
182
  };
183
183
 
184
184
  return (
185
- <div className="card" ref={cardRef}>
185
+ <div className={`card ${className || ''}`} ref={cardRef}>
186
186
  <CardHeader className="card-header-flex">
187
187
  {header}
188
188
  </CardHeader>
@@ -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 authzObj = (0, _authz.authz)(childProps);
71
- var disabled = authzObj.disabled;
72
- var hide = authzObj.hide;
73
- var title = authzObj.title;
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 authzObj = (0, _authz.authz)(childProps);
54
- var disabled = authzObj.disabled;
55
- var title = authzObj.title;
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 authzObj = (0, _authz.authz)(childProps);
67
- var disabled = authzObj.disabled;
68
- var hide = authzObj.hide;
69
- var title = authzObj.title;
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 authzObj = (0, _authz.authz)(childProps);
68
- var disabled = authzObj.disabled;
69
- var hide = authzObj.hide;
70
- var title = authzObj.title;
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 disabled = childProps.resources && childProps.resource ? childProps.resources.indexOf(childProps.resource) === -1 : true;
15
- // If user is superuser, then button is enabled
16
- if (childProps.resources && childProps.resources.indexOf('authz:superuser') !== -1) {
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 = childProps.hideOnUnauthorizedAccess ? true : false;
35
+ var hide = Boolean(hideOnUnauthorizedAccess);
36
+
21
37
  // Remove hideOnUnauthorized element from props to avoid react warnings
22
- if (childProps.hideOnUnauthorizedAccess) {
23
- delete childProps["hideOnUnauthorizedAccess"];
38
+ if (hideOnUnauthorizedAccess) {
39
+ delete childProps.hideOnUnauthorizedAccess;
24
40
  }
25
- var title = childProps.title;
26
- // Check on title eventually passed in the props
41
+
42
+ // Set the title for unauthorized state
43
+ var title = titleProp;
27
44
  if (disabled) {
28
- title = t("General|You do not have access rights to perform this action");
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 (childProps.disabled && disabled == false) {
32
- disabled = childProps.disabled;
49
+ if (disabledProp && disabled === false) {
50
+ disabled = disabledProp;
33
51
  }
34
52
  return {
35
- disabled: disabled,
36
- hide: hide,
37
- title: title
53
+ disabled,
54
+ hide,
55
+ title
38
56
  };
39
57
  };
40
58
  exports.authz = authz;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asab_webui_components",
3
- "version": "27.3.3",
3
+ "version": "27.3.5",
4
4
  "license": "BSD-3-Clause",
5
5
  "description": "TeskaLabs ASAB WebUI Components Library",
6
6
  "contributors": [