@bigbinary/neeto-commons-frontend 2.0.70 → 2.0.71
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/package.json +1 -1
- package/react-utils.cjs.js +18 -8
- package/react-utils.cjs.js.map +1 -1
- package/react-utils.d.ts +13 -4
- package/react-utils.js +19 -9
- package/react-utils.js.map +1 -1
package/react-utils.d.ts
CHANGED
|
@@ -51,13 +51,21 @@ export const HoneybadgerErrorBoundary: React.FC<{
|
|
|
51
51
|
}>;
|
|
52
52
|
/**
|
|
53
53
|
*
|
|
54
|
-
* A route that will restrict access to it based on a specified condition
|
|
54
|
+
* A route that will restrict access to it based on a specified condition and
|
|
55
55
|
*
|
|
56
|
-
*
|
|
56
|
+
* permissions.
|
|
57
57
|
*
|
|
58
|
-
*
|
|
58
|
+
* If the given condition is true and the user has the required permissions, it
|
|
59
59
|
*
|
|
60
|
-
*
|
|
60
|
+
* acts identical to a normal route. If the condition is true and the user does not
|
|
61
|
+
*
|
|
62
|
+
* have the required permissions, it will show 403 error page or it will render a
|
|
63
|
+
*
|
|
64
|
+
* supplied error page. If the condition is false, it will redirect user to a
|
|
65
|
+
*
|
|
66
|
+
* different path if redirectRoute is specified or it will render a supplied error
|
|
67
|
+
*
|
|
68
|
+
* page.
|
|
61
69
|
*
|
|
62
70
|
* If condition is not specified, it will assume the value of
|
|
63
71
|
*
|
|
@@ -70,6 +78,7 @@ export function PrivateRoute(props: {
|
|
|
70
78
|
condition?: boolean;
|
|
71
79
|
redirectRoute?: string;
|
|
72
80
|
errorPage?: React.ReactNode;
|
|
81
|
+
permissions?: string[];
|
|
73
82
|
} & RouteProps): JSX.Element;
|
|
74
83
|
type OptionsType = {
|
|
75
84
|
root?: Element | null;
|
package/react-utils.js
CHANGED
|
@@ -2,7 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import React__default, { useEffect, useState, useDebugValue, useRef, useMemo } from 'react';
|
|
3
3
|
import { Honeybadger, HoneybadgerErrorBoundary as HoneybadgerErrorBoundary$1 } from '@honeybadger-io/react';
|
|
4
4
|
import { Typography, Button } from '@bigbinary/neetoui';
|
|
5
|
-
import { isNil, prop, toPairs, mergeLeft, isEmpty, omit, curry } from 'ramda';
|
|
5
|
+
import { isNil, includes, __, prop, toPairs, mergeLeft, isEmpty, omit, curry } from 'ramda';
|
|
6
6
|
import { useTranslation, Trans } from 'react-i18next';
|
|
7
7
|
import ErrorPage from '@bigbinary/neeto-molecules/ErrorPage';
|
|
8
8
|
import { Route, Redirect } from 'react-router-dom';
|
|
@@ -152,7 +152,7 @@ function _objectWithoutProperties(source, excluded) {
|
|
|
152
152
|
return target;
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
var _excluded = ["condition", "redirectRoute", "errorPage"];
|
|
155
|
+
var _excluded = ["condition", "redirectRoute", "errorPage", "permissions"];
|
|
156
156
|
var PrivateRoute = function PrivateRoute(_ref) {
|
|
157
157
|
var _ref$condition = _ref.condition,
|
|
158
158
|
condition = _ref$condition === void 0 ? globalProps.authenticated : _ref$condition,
|
|
@@ -160,17 +160,27 @@ var PrivateRoute = function PrivateRoute(_ref) {
|
|
|
160
160
|
redirectRoute = _ref$redirectRoute === void 0 ? undefined : _ref$redirectRoute,
|
|
161
161
|
_ref$errorPage = _ref.errorPage,
|
|
162
162
|
errorPage = _ref$errorPage === void 0 ? undefined : _ref$errorPage,
|
|
163
|
+
_ref$permissions = _ref.permissions,
|
|
164
|
+
permissions = _ref$permissions === void 0 ? undefined : _ref$permissions,
|
|
163
165
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
166
|
+
if (condition) {
|
|
167
|
+
if (permissions) {
|
|
168
|
+
return globalProps.permissions.some(includes(__, permissions)) ? /*#__PURE__*/React__default.createElement(Route, props) : errorPage || /*#__PURE__*/React__default.createElement(ErrorPage, {
|
|
169
|
+
status: 403
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
return /*#__PURE__*/React__default.createElement(Route, props);
|
|
173
|
+
}
|
|
174
|
+
if (redirectRoute) {
|
|
175
|
+
return /*#__PURE__*/React__default.createElement(Redirect, {
|
|
167
176
|
to: {
|
|
168
177
|
pathname: redirectRoute
|
|
169
178
|
}
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
return errorPage || /*#__PURE__*/React__default.createElement(ErrorPage, {
|
|
182
|
+
status: 403
|
|
183
|
+
});
|
|
174
184
|
};
|
|
175
185
|
|
|
176
186
|
function _arrayWithHoles(arr) {
|