mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-12-05 03:54:23 +00:00
This commit is contained in:
parent
098cb865d5
commit
1d3ba3e3a1
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2021 Collate
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Redirect, Route, RouteProps } from 'react-router-dom';
|
||||
import { useAuthContext } from '../authentication/auth-provider/AuthProvider';
|
||||
import { ROUTES } from '../constants/constants';
|
||||
import { useAuth } from '../hooks/authHooks';
|
||||
|
||||
const AdminProtectedRoute = (routeProps: RouteProps) => {
|
||||
const { isAdminUser } = useAuth();
|
||||
const { isAuthDisabled, isAuthenticated } = useAuthContext();
|
||||
|
||||
if (isAuthDisabled || isAdminUser) {
|
||||
return <Route {...routeProps} />;
|
||||
} else if (isAuthenticated) {
|
||||
return <Redirect to={ROUTES.NOT_FOUND} />;
|
||||
} else {
|
||||
return <Redirect to={ROUTES.SIGNIN} />;
|
||||
}
|
||||
};
|
||||
|
||||
export default AdminProtectedRoute;
|
||||
@ -15,9 +15,7 @@ import { isEmpty } from 'lodash';
|
||||
import React, { FunctionComponent } from 'react';
|
||||
import { Redirect, Route, Switch } from 'react-router-dom';
|
||||
import AppState from '../AppState';
|
||||
import { useAuthContext } from '../authentication/auth-provider/AuthProvider';
|
||||
import { ROUTES } from '../constants/constants';
|
||||
import { useAuth } from '../hooks/authHooks';
|
||||
import AddGlossaryPage from '../pages/AddGlossary/AddGlossaryPage.component';
|
||||
import AddGlossaryTermPage from '../pages/AddGlossaryTermPage/AddGlossaryTermPage.component';
|
||||
import AddServicePage from '../pages/AddServicePage/AddServicePage.component';
|
||||
@ -45,10 +43,8 @@ import TourPageComponent from '../pages/tour-page/TourPage.component';
|
||||
import UserListPage from '../pages/UserListPage/UserListPage';
|
||||
import UserPage from '../pages/UserPage/UserPage.component';
|
||||
import WebhooksPage from '../pages/WebhooksPage/WebhooksPage.component';
|
||||
import AdminProtectedRoute from './AdminProtectedRoute';
|
||||
const AuthenticatedAppRouter: FunctionComponent = () => {
|
||||
const { isAdminUser } = useAuth();
|
||||
const { isAuthDisabled } = useAuthContext();
|
||||
|
||||
return (
|
||||
<Switch>
|
||||
<Route exact component={MyDataPage} path={ROUTES.MY_DATA} />
|
||||
@ -118,37 +114,41 @@ const AuthenticatedAppRouter: FunctionComponent = () => {
|
||||
<Route exact component={EntityVersionPage} path={ROUTES.ENTITY_VERSION} />
|
||||
<Route exact component={WebhooksPage} path={ROUTES.WEBHOOKS} />
|
||||
<Route exact component={EditWebhookPage} path={ROUTES.EDIT_WEBHOOK} />
|
||||
{/* <Route exact component={GlossaryPage} path={ROUTES.GLOSSARY} /> */}
|
||||
<Route exact component={GlossaryPageV1} path={ROUTES.GLOSSARY} />
|
||||
<Route exact component={GlossaryPageV1} path={ROUTES.GLOSSARY_DETAILS} />
|
||||
<Route exact component={GlossaryPageV1} path={ROUTES.GLOSSARY_TERMS} />
|
||||
{/* <Route
|
||||
exact
|
||||
component={GlossaryTermPage}
|
||||
path={ROUTES.GLOSSARY_DETAILS}
|
||||
/> */}
|
||||
{/* <Route exact component={GlossaryTermPage} path={ROUTES.GLOSSARY_TERMS} /> */}
|
||||
<Route exact component={UserPage} path={ROUTES.USER_PROFILE} />
|
||||
{isAuthDisabled || isAdminUser ? (
|
||||
<>
|
||||
<Route exact component={AddGlossaryPage} path={ROUTES.ADD_GLOSSARY} />
|
||||
<Route
|
||||
exact
|
||||
component={AddGlossaryTermPage}
|
||||
path={ROUTES.ADD_GLOSSARY_TERMS_CHILD}
|
||||
/>
|
||||
<Route
|
||||
exact
|
||||
component={AddGlossaryTermPage}
|
||||
path={ROUTES.ADD_GLOSSARY_TERMS}
|
||||
/>
|
||||
<Route exact component={AddWebhookPage} path={ROUTES.ADD_WEBHOOK} />
|
||||
<Route exact component={RolesPage} path={ROUTES.ROLES} />
|
||||
<Route exact component={CreateUserPage} path={ROUTES.CREATE_USER} />
|
||||
<Route exact component={UserListPage} path={ROUTES.USER_LIST} />
|
||||
</>
|
||||
) : null}
|
||||
|
||||
<AdminProtectedRoute
|
||||
exact
|
||||
component={AddGlossaryPage}
|
||||
path={ROUTES.ADD_GLOSSARY}
|
||||
/>
|
||||
<AdminProtectedRoute
|
||||
exact
|
||||
component={AddGlossaryTermPage}
|
||||
path={ROUTES.ADD_GLOSSARY_TERMS_CHILD}
|
||||
/>
|
||||
<AdminProtectedRoute
|
||||
exact
|
||||
component={AddGlossaryTermPage}
|
||||
path={ROUTES.ADD_GLOSSARY_TERMS}
|
||||
/>
|
||||
<AdminProtectedRoute
|
||||
exact
|
||||
component={AddWebhookPage}
|
||||
path={ROUTES.ADD_WEBHOOK}
|
||||
/>
|
||||
<AdminProtectedRoute exact component={RolesPage} path={ROUTES.ROLES} />
|
||||
<AdminProtectedRoute
|
||||
exact
|
||||
component={CreateUserPage}
|
||||
path={ROUTES.CREATE_USER}
|
||||
/>
|
||||
<AdminProtectedRoute
|
||||
exact
|
||||
component={UserListPage}
|
||||
path={ROUTES.USER_LIST}
|
||||
/>
|
||||
<Redirect to={ROUTES.NOT_FOUND} />
|
||||
</Switch>
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user