From 106f99f4c8940ef488829da061a7c7815359da75 Mon Sep 17 00:00:00 2001 From: Sachin Chaurasiya Date: Tue, 30 Aug 2022 14:42:55 +0530 Subject: [PATCH] Update MyData and Explore with new roles and policy (#7018) * Update MyData and Explore with new roles and policy * Add placeholder for explore side panel * Fix unit tests * Remove Permission API call from AuthProvider * Fix loading issue * Update global settings left panel * Remove feed check from mydata page * Remove permission check from explore page * Minor change * Add resource permission method to provider * Change global settings left panel * Remove unwanted codes * Add comments * Addressing review comments --- .../auth-provider/AuthProvider.tsx | 30 +-- .../resources/ui/src/axiosAPIs/miscAPI.ts | 13 - .../ui/src/axiosAPIs/permissionAPI.ts | 48 ++++ .../resources/ui/src/axiosAPIs/rolesAPIV1.ts | 13 - .../BotDetails/BotDetails.component.tsx | 38 ++- .../BotListV1/BotListV1.component.tsx | 10 +- .../components/Explore/Explore.component.tsx | 30 +-- .../src/components/Explore/Explore.test.tsx | 10 +- .../components/Explore/explore.interface.ts | 24 +- .../GlobalSetting/GlobalSettingLeftPanel.tsx | 119 ++++++--- .../PermissionProvider.interface.ts | 6 +- .../PermissionProvider/PermissionProvider.tsx | 67 +++-- .../ui/src/constants/explore.constants.ts | 26 ++ .../constants/globalSettings.constants.tsx | 158 ++--------- .../pages/MyDataPage/MyDataPage.component.tsx | 14 +- .../pages/explore/ExplorePage.component.tsx | 203 +++++---------- .../resources/ui/src/pages/signup/index.tsx | 21 -- .../pages/tour-page/TourPage.component.tsx | 9 +- .../resources/ui/src/utils/EntityUtils.tsx | 28 ++ .../ui/src/utils/GlobalSettingsUtils.tsx | 245 +++++++++++++++++- 20 files changed, 613 insertions(+), 499 deletions(-) create mode 100644 openmetadata-ui/src/main/resources/ui/src/axiosAPIs/permissionAPI.ts diff --git a/openmetadata-ui/src/main/resources/ui/src/authentication/auth-provider/AuthProvider.tsx b/openmetadata-ui/src/main/resources/ui/src/authentication/auth-provider/AuthProvider.tsx index 7619358a83f..2e42d792a66 100644 --- a/openmetadata-ui/src/main/resources/ui/src/authentication/auth-provider/AuthProvider.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/authentication/auth-provider/AuthProvider.tsx @@ -33,10 +33,7 @@ import React, { import { useHistory, useLocation } from 'react-router-dom'; import appState from '../../AppState'; import axiosClient from '../../axiosAPIs'; -import { - fetchAuthenticationConfig, - getLoggedInUserPermissions, -} from '../../axiosAPIs/miscAPI'; +import { fetchAuthenticationConfig } from '../../axiosAPIs/miscAPI'; import { getLoggedInUser, getUserByName, @@ -166,32 +163,14 @@ export const AuthProvider = ({ } }; - const getUserPermissions = () => { - setLoading(true); - getLoggedInUserPermissions() - .then((res) => { - appState.updateUserPermissions(res.data); - }) - .catch((err: AxiosError) => { - showErrorToast( - err, - jsonData['api-error-messages']['fetch-user-permission-error'] - ); - }) - .finally(() => setLoading(false)); - }; - const getLoggedInUserDetails = () => { setLoading(true); getLoggedInUser(userAPIQueryFields) .then((res) => { if (res) { - getUserPermissions(); appState.updateUserDetails(res); - fetchAllUsers(); } else { resetUserDetails(); - setLoading(false); } }) .catch((err: AxiosError) => { @@ -204,6 +183,9 @@ export const AuthProvider = ({ jsonData['api-error-messages']['fetch-logged-in-user-error'] ); } + }) + .finally(() => { + setLoading(false); }); }; @@ -368,8 +350,6 @@ export const AuthProvider = ({ } else { appState.updateUserDetails(res); } - getUserPermissions(); - fetchAllUsers(); handledVerifiedUser(); // Start expiry timer on successful login startTokenExpiryTimer(); @@ -439,8 +419,6 @@ export const AuthProvider = ({ storeRedirectPath(); showErrorToast(error); resetUserDetails(true); - } else if (status === ClientErrors.FORBIDDEN) { - showErrorToast(jsonData['api-error-messages']['forbidden-error']); } } diff --git a/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/miscAPI.ts b/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/miscAPI.ts index e17ec755209..1d4a20e6bc4 100644 --- a/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/miscAPI.ts +++ b/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/miscAPI.ts @@ -18,7 +18,6 @@ import { WILD_CARD_CHAR } from '../constants/char.constants'; import { SearchIndex } from '../enums/search.enum'; import { AirflowConfiguration } from '../generated/configuration/airflowConfiguration'; import { AuthenticationConfiguration } from '../generated/configuration/authenticationConfiguration'; -import { ResourcePermission } from '../generated/entity/policies/accessControl/resourcePermission'; import { EntitiesCount } from '../generated/entity/utils/entitiesCount'; import { Paging } from '../generated/type/paging'; import { getURLWithQueryFields } from '../utils/APIUtils'; @@ -121,18 +120,6 @@ export const deleteLineageEdge: Function = ( ); }; -export const getLoggedInUserPermissions = async () => { - const params = { - limit: 100, - }; - const response = await APIClient.get<{ - data: ResourcePermission[]; - paging: Paging; - }>('/permissions', { params }); - - return response.data; -}; - export const getInitialEntity = ( index: SearchIndex, params = {} as AxiosRequestConfig diff --git a/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/permissionAPI.ts b/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/permissionAPI.ts new file mode 100644 index 00000000000..98868c634db --- /dev/null +++ b/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/permissionAPI.ts @@ -0,0 +1,48 @@ +/* + * 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 { ResourceEntity } from '../components/PermissionProvider/PermissionProvider.interface'; +import { ResourcePermission } from '../generated/entity/policies/accessControl/resourcePermission'; +import { Paging } from '../generated/type/paging'; +import APIClient from './index'; + +export const getLoggedInUserPermissions = async () => { + const params = { + limit: 100, + }; + const response = await APIClient.get<{ + data: ResourcePermission[]; + paging: Paging; + }>('/permissions', { params }); + + return response.data; +}; + +export const getEntityPermissionById = async ( + resource: ResourceEntity, + entityId: string +) => { + const response = await APIClient.get( + `/permissions/${resource}/${entityId}` + ); + + return response.data; +}; + +export const getResourcePermission = async (resource: ResourceEntity) => { + const response = await APIClient.get( + `/permissions/${resource}` + ); + + return response.data; +}; diff --git a/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/rolesAPIV1.ts b/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/rolesAPIV1.ts index 8b5884ac393..7f4b340a166 100644 --- a/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/rolesAPIV1.ts +++ b/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/rolesAPIV1.ts @@ -13,11 +13,9 @@ import { AxiosResponse } from 'axios'; import { Operation } from 'fast-json-patch'; -import { ResourceEntity } from '../components/PermissionProvider/PermissionProvider.interface'; import { CreatePolicy } from '../generated/api/policies/createPolicy'; import { CreateRole } from '../generated/api/teams/createRole'; import { ResourceDescriptor } from '../generated/entity/policies/accessControl/resourceDescriptor'; -import { ResourcePermission } from '../generated/entity/policies/accessControl/resourcePermission'; import { Policy } from '../generated/entity/policies/policy'; import { Role } from '../generated/entity/teams/role'; import { Function } from '../generated/type/function'; @@ -156,14 +154,3 @@ export const validateRuleCondition = async (condition: string) => { */ return response; }; - -export const getEntityPermissionById = async ( - resource: ResourceEntity, - entityId: string -) => { - const response = await APIClient.get( - `/permissions/${resource}/${entityId}` - ); - - return response.data; -}; diff --git a/openmetadata-ui/src/main/resources/ui/src/components/BotDetails/BotDetails.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/BotDetails/BotDetails.component.tsx index aeda6fe17e7..5d49869b6f0 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/BotDetails/BotDetails.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/BotDetails/BotDetails.component.tsx @@ -15,13 +15,14 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { Card } from 'antd'; import { AxiosError } from 'axios'; import classNames from 'classnames'; -import { isNil } from 'lodash'; +import { isEmpty, isNil } from 'lodash'; import moment from 'moment'; import React, { FC, Fragment, HTMLAttributes, useEffect, + useMemo, useState, } from 'react'; import Select, { SingleValue } from 'react-select'; @@ -77,21 +78,32 @@ const BotDetails: FC = ({ const [generateToken, setGenerateToken] = useState(false); const [selectedExpiry, setSelectedExpiry] = useState('7'); - const editAllPermission = checkPermission( - Operation.EditAll, - ResourceEntity.BOT, - permissions + const editAllPermission = useMemo( + () => + !isEmpty(permissions) && + checkPermission(Operation.EditAll, ResourceEntity.BOT, permissions), + [permissions] ); - const displayNamePermission = checkPermission( - Operation.EditDisplayName, - ResourceEntity.BOT, - permissions + const displayNamePermission = useMemo( + () => + !isEmpty(permissions) && + checkPermission( + Operation.EditDisplayName, + ResourceEntity.BOT, + permissions + ), + [permissions] ); - const descriptionPermission = checkPermission( - Operation.EditDescription, - ResourceEntity.BOT, - permissions + const descriptionPermission = useMemo( + () => + !isEmpty(permissions) && + checkPermission( + Operation.EditDescription, + ResourceEntity.BOT, + permissions + ), + [permissions] ); const getJWTTokenExpiryOptions = () => { diff --git a/openmetadata-ui/src/main/resources/ui/src/components/BotListV1/BotListV1.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/BotListV1/BotListV1.component.tsx index cf9a25c867b..3a851e130d7 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/BotListV1/BotListV1.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/BotListV1/BotListV1.component.tsx @@ -14,6 +14,7 @@ import { Button, Col, Row, Space, Table, Tooltip } from 'antd'; import { ColumnsType } from 'antd/lib/table'; import { AxiosError } from 'axios'; +import { isEmpty } from 'lodash'; import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { Link } from 'react-router-dom'; import { getBots } from '../../axiosAPIs/botsAPI'; @@ -46,10 +47,11 @@ const BotListV1 = ({ showDeleted }: BotListV1Props) => { const [loading, setLoading] = useState(true); const [currentPage, setCurrentPage] = useState(INITIAL_PAGING_VALUE); - const deletePermission = checkPermission( - Operation.Delete, - ResourceEntity.BOT, - permissions + const deletePermission = useMemo( + () => + !isEmpty(permissions) && + checkPermission(Operation.Delete, ResourceEntity.BOT, permissions), + [permissions] ); /** diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Explore/Explore.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/Explore/Explore.component.tsx index ab7d448097a..8735d130e1b 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/Explore/Explore.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/Explore/Explore.component.tsx @@ -89,12 +89,8 @@ const Explore: React.FC = ({ fetchData, showDeleted, onShowDeleted, - updateTableCount, - updateTopicCount, - updateDashboardCount, - updatePipelineCount, isFilterSelected, - updateMlModelCount, + handleTabCounts, }: ExploreProps) => { const location = useLocation(); const history = useHistory(); @@ -273,23 +269,23 @@ const Explore: React.FC = ({ const setCount = (count = 0, index = searchIndex) => { switch (index) { case SearchIndex.TABLE: - updateTableCount(count); + handleTabCounts({ table: count }); break; case SearchIndex.DASHBOARD: - updateDashboardCount(count); + handleTabCounts({ dashboard: count }); break; case SearchIndex.TOPIC: - updateTopicCount(count); + handleTabCounts({ topic: count }); break; case SearchIndex.PIPELINE: - updatePipelineCount(count); + handleTabCounts({ pipeline: count }); break; case SearchIndex.MLMODEL: - updateMlModelCount(count); + handleTabCounts({ mlmodel: count }); break; default: @@ -441,7 +437,7 @@ const Explore: React.FC = ({ case SearchIndex.PIPELINE: return getCountBadge(tabCounts.pipeline, className, isActive); case SearchIndex.MLMODEL: - return getCountBadge(tabCounts.mlModel, className, isActive); + return getCountBadge(tabCounts.mlmodel, className, isActive); default: return getCountBadge(); } @@ -469,18 +465,6 @@ const Explore: React.FC = ({ 'tw-flex tw-flex-row tw-justify-between tw-gh-tabs-container' )}>
- {/*
- -
*/}
{tabsInfo.map((tabDetail, index) => (