@redhat-cloud-services/frontend-components-utilities 3.2.7 → 3.2.10

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/RBAC/RBAC.d.ts CHANGED
@@ -5,5 +5,5 @@ export interface RBAC {
5
5
  permissions: Access[];
6
6
  }
7
7
 
8
- export function getRBAC(applicationName: string): Promise<RBAC>;
8
+ export function getRBAC(applicationName: string, disableCache?: boolean): Promise<RBAC>;
9
9
  export function doesHavePermissions(RBACResults: RBAC, permissionList: string[]): boolean;
package/RBAC/RBAC.js CHANGED
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.getRBAC = getRBAC;
9
9
  exports.doesHavePermissions = doesHavePermissions;
10
+ exports["default"] = void 0;
10
11
 
11
12
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
12
13
 
@@ -21,6 +22,7 @@ function _getRBAC() {
21
22
  var _insights$chrome, _insights$chrome$auth, _user$identity, _user$identity$user, _insights$chrome2;
22
23
 
23
24
  var applicationName,
25
+ disableCache,
24
26
  insights,
25
27
  user,
26
28
  _args = arguments;
@@ -29,34 +31,35 @@ function _getRBAC() {
29
31
  switch (_context.prev = _context.next) {
30
32
  case 0:
31
33
  applicationName = _args.length > 0 && _args[0] !== undefined ? _args[0] : '';
34
+ disableCache = _args.length > 1 && _args[1] !== undefined ? _args[1] : false;
32
35
  insights = window.insights;
33
- _context.next = 4;
36
+ _context.next = 5;
34
37
  return insights === null || insights === void 0 ? void 0 : (_insights$chrome = insights.chrome) === null || _insights$chrome === void 0 ? void 0 : (_insights$chrome$auth = _insights$chrome.auth) === null || _insights$chrome$auth === void 0 ? void 0 : _insights$chrome$auth.getUser();
35
38
 
36
- case 4:
39
+ case 5:
37
40
  user = _context.sent;
38
41
  _context.t0 = (user === null || user === void 0 ? void 0 : (_user$identity = user.identity) === null || _user$identity === void 0 ? void 0 : (_user$identity$user = _user$identity.user) === null || _user$identity$user === void 0 ? void 0 : _user$identity$user.is_org_admin) || false;
39
- _context.next = 8;
40
- return insights === null || insights === void 0 ? void 0 : (_insights$chrome2 = insights.chrome) === null || _insights$chrome2 === void 0 ? void 0 : _insights$chrome2.getUserPermissions(applicationName);
42
+ _context.next = 9;
43
+ return insights === null || insights === void 0 ? void 0 : (_insights$chrome2 = insights.chrome) === null || _insights$chrome2 === void 0 ? void 0 : _insights$chrome2.getUserPermissions(applicationName, disableCache);
41
44
 
42
- case 8:
45
+ case 9:
43
46
  _context.t1 = _context.sent;
44
47
 
45
48
  if (_context.t1) {
46
- _context.next = 11;
49
+ _context.next = 12;
47
50
  break;
48
51
  }
49
52
 
50
53
  _context.t1 = null;
51
54
 
52
- case 11:
55
+ case 12:
53
56
  _context.t2 = _context.t1;
54
57
  return _context.abrupt("return", {
55
58
  isOrgAdmin: _context.t0,
56
59
  permissions: _context.t2
57
60
  });
58
61
 
59
- case 13:
62
+ case 14:
60
63
  case "end":
61
64
  return _context.stop();
62
65
  }
@@ -74,4 +77,7 @@ function doesHavePermissions(userPermissions, permissionList) {
74
77
  return userPermissions.some(function (access) {
75
78
  return permissionList.includes((access === null || access === void 0 ? void 0 : access.permission) || access);
76
79
  });
77
- }
80
+ }
81
+
82
+ var _default = getRBAC;
83
+ exports["default"] = _default;
@@ -4,4 +4,4 @@ export interface UsePermissionsState extends RBAC {
4
4
  hasAccess: boolean;
5
5
  }
6
6
 
7
- export function usePermissions(appName: string, permissionsList: string[]): UsePermissionsState;
7
+ export function usePermissions(appName: string, permissionsList: string[], disableCache?: boolean): UsePermissionsState;
@@ -18,7 +18,7 @@ var _react = require("react");
18
18
 
19
19
  var _RBAC = require("../RBAC");
20
20
 
21
- function usePermissions(appName, permissionsList) {
21
+ function usePermissions(appName, permissionsList, disableCache) {
22
22
  var _useState = (0, _react.useState)({
23
23
  isLoading: true
24
24
  }),
@@ -38,7 +38,7 @@ function usePermissions(appName, permissionsList) {
38
38
  switch (_context.prev = _context.next) {
39
39
  case 0:
40
40
  _context.next = 2;
41
- return (0, _RBAC.getRBAC)(appName);
41
+ return (0, _RBAC.getRBAC)(appName, disableCache);
42
42
 
43
43
  case 2:
44
44
  _yield$getRBAC = _context.sent;
@@ -58,7 +58,7 @@ function usePermissions(appName, permissionsList) {
58
58
  }
59
59
  }, _callee);
60
60
  }))();
61
- }, [appName]);
61
+ }, [appName, disableCache]);
62
62
  return permissions;
63
63
  }
64
64
 
package/esm/RBAC/RBAC.js CHANGED
@@ -9,6 +9,7 @@ function _getRBAC() {
9
9
  var _insights$chrome, _insights$chrome$auth, _user$identity, _user$identity$user, _insights$chrome2;
10
10
 
11
11
  var applicationName,
12
+ disableCache,
12
13
  insights,
13
14
  user,
14
15
  _args = arguments;
@@ -17,34 +18,35 @@ function _getRBAC() {
17
18
  switch (_context.prev = _context.next) {
18
19
  case 0:
19
20
  applicationName = _args.length > 0 && _args[0] !== undefined ? _args[0] : '';
21
+ disableCache = _args.length > 1 && _args[1] !== undefined ? _args[1] : false;
20
22
  insights = window.insights;
21
- _context.next = 4;
23
+ _context.next = 5;
22
24
  return insights === null || insights === void 0 ? void 0 : (_insights$chrome = insights.chrome) === null || _insights$chrome === void 0 ? void 0 : (_insights$chrome$auth = _insights$chrome.auth) === null || _insights$chrome$auth === void 0 ? void 0 : _insights$chrome$auth.getUser();
23
25
 
24
- case 4:
26
+ case 5:
25
27
  user = _context.sent;
26
28
  _context.t0 = (user === null || user === void 0 ? void 0 : (_user$identity = user.identity) === null || _user$identity === void 0 ? void 0 : (_user$identity$user = _user$identity.user) === null || _user$identity$user === void 0 ? void 0 : _user$identity$user.is_org_admin) || false;
27
- _context.next = 8;
28
- return insights === null || insights === void 0 ? void 0 : (_insights$chrome2 = insights.chrome) === null || _insights$chrome2 === void 0 ? void 0 : _insights$chrome2.getUserPermissions(applicationName);
29
+ _context.next = 9;
30
+ return insights === null || insights === void 0 ? void 0 : (_insights$chrome2 = insights.chrome) === null || _insights$chrome2 === void 0 ? void 0 : _insights$chrome2.getUserPermissions(applicationName, disableCache);
29
31
 
30
- case 8:
32
+ case 9:
31
33
  _context.t1 = _context.sent;
32
34
 
33
35
  if (_context.t1) {
34
- _context.next = 11;
36
+ _context.next = 12;
35
37
  break;
36
38
  }
37
39
 
38
40
  _context.t1 = null;
39
41
 
40
- case 11:
42
+ case 12:
41
43
  _context.t2 = _context.t1;
42
44
  return _context.abrupt("return", {
43
45
  isOrgAdmin: _context.t0,
44
46
  permissions: _context.t2
45
47
  });
46
48
 
47
- case 13:
49
+ case 14:
48
50
  case "end":
49
51
  return _context.stop();
50
52
  }
@@ -62,4 +64,5 @@ export function doesHavePermissions(userPermissions, permissionList) {
62
64
  return userPermissions.some(function (access) {
63
65
  return permissionList.includes((access === null || access === void 0 ? void 0 : access.permission) || access);
64
66
  });
65
- }
67
+ }
68
+ export default getRBAC;
@@ -3,7 +3,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  import _regeneratorRuntime from "@babel/runtime/regenerator";
4
4
  import { useState, useEffect } from 'react';
5
5
  import { getRBAC, doesHavePermissions } from '../RBAC';
6
- export function usePermissions(appName, permissionsList) {
6
+ export function usePermissions(appName, permissionsList, disableCache) {
7
7
  var _useState = useState({
8
8
  isLoading: true
9
9
  }),
@@ -24,7 +24,7 @@ export function usePermissions(appName, permissionsList) {
24
24
  switch (_context.prev = _context.next) {
25
25
  case 0:
26
26
  _context.next = 2;
27
- return getRBAC(appName);
27
+ return getRBAC(appName, disableCache);
28
28
 
29
29
  case 2:
30
30
  _yield$getRBAC = _context.sent;
@@ -44,7 +44,7 @@ export function usePermissions(appName, permissionsList) {
44
44
  }
45
45
  }, _callee);
46
46
  }))();
47
- }, [appName]);
47
+ }, [appName, disableCache]);
48
48
  return permissions;
49
49
  }
50
50
  export default usePermissions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redhat-cloud-services/frontend-components-utilities",
3
- "version": "3.2.7",
3
+ "version": "3.2.10",
4
4
  "description": "Util functions for RedHat Cloud Services project.",
5
5
  "main": "index.js",
6
6
  "module": "esm/index.js",