Skip to content

Commit 078d323

Browse files
LuisValgoiMarcusNotheis
authored andcommitted
Merge pull request #27 from LuisValgoi/issue-24
[ISSUE-24] Refactor Validator Components prop names
1 parent 808e08f commit 078d323

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

packages/ui5-webcomponents-react-seed/src/permissions/ComponentValidator.js renamed to packages/ui5-webcomponents-react-seed/src/auth/ComponentValidator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ const fetchUser = async () => {
1111
return res.data;
1212
};
1313

14-
const ComponentValidator = ({ allowedPermissions, allowenceKey, children }) => {
14+
const ComponentValidator = ({ allowedAuthorities, authorityKey, children }) => {
1515
const { data, status } = useQuery('GET_USER_LOGGED', fetchUser);
1616

1717
const getRoute = () => {
1818
if (status === Constants.CODES.RQ_SUCCESS) {
19-
const hasAccess = data.data.user[allowenceKey].some(permission => allowedPermissions.includes(permission));
19+
const hasAccess = data.data.user[authorityKey].some(permission => allowedAuthorities.includes(permission));
2020
if (hasAccess) {
2121
return children;
2222
}

packages/ui5-webcomponents-react-seed/src/permissions/RouteValidator.js renamed to packages/ui5-webcomponents-react-seed/src/auth/RouteValidator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ const fetchUser = async () => {
1515
return res.data;
1616
};
1717

18-
const RouteValidator = ({ allowedPermissions, allowenceKey, path, component, ...props }) => {
18+
const RouteValidator = ({ allowedAuthorities, authorityKey, path, component, ...props }) => {
1919
const { data, status } = useQuery('GET_USER_LOGGED', fetchUser);
2020

2121
const getRoute = () => {
2222
if (status === Constants.CODES.RQ_SUCCESS) {
23-
const hasAccess = data.data.user[allowenceKey].some(permission => allowedPermissions.includes(permission));
23+
const hasAccess = data.data.user[authorityKey].some(permission => allowedAuthorities.includes(permission));
2424
return <Route path={path} {...props} component={hasAccess ? component : NotFound} />;
2525
}
2626

packages/ui5-webcomponents-react-seed/src/pages/Todo/List/TodoList.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Helmet } from 'react-helmet';
44

55
import CenteredLink from '../../../components/CenteredLink/CenteredLink';
66
import BrowserURL from '../../../util/BrowserURL';
7-
import ComponentValidator from '../../../permissions/ComponentValidator';
7+
import ComponentValidator from '../../../auth/ComponentValidator';
88

99
export default function TodoList() {
1010
const history = useHistory();
@@ -16,7 +16,7 @@ export default function TodoList() {
1616
<br />
1717
<CenteredLink onClick={() => history.push(BrowserURL.BUGGY)} text='Test Error Page' />
1818
<br />
19-
<ComponentValidator allowedPermissions={['canAccessDropApplication']} allowenceKey='permissions'>
19+
<ComponentValidator allowedAuthorities={['canAccessDropApplication']} authorityKey='permissions'>
2020
<CenteredLink text='Drop Application (this is a restricted text and you should not see unless you have access)' />
2121
</ComponentValidator>
2222
</>

packages/ui5-webcomponents-react-seed/src/routes/Routes.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import BrowserURL from '../util/BrowserURL';
55
import TodoList from '../pages/Todo/List/TodoList';
66
import NotFound from '../pages/Fallback/NotFound';
77
import Buggy from '../pages/Fallback/Buggy';
8-
import RouteValidator from '../permissions/RouteValidator';
8+
import RouteValidator from '../auth/RouteValidator';
99

1010
const Routes = () => {
1111
return (
@@ -15,8 +15,8 @@ const Routes = () => {
1515
exact
1616
to={BrowserURL.TODO_LIST} />
1717
<RouteValidator
18-
allowedPermissions={['canAccessTodoListPage']}
19-
allowenceKey='permissions'
18+
allowedAuthorities={['canAccessTodoListPage']}
19+
authorityKey='permissions'
2020
path={BrowserURL.TODO_LIST}
2121
component={TodoList} />
2222
<Route

0 commit comments

Comments
 (0)