diff --git a/openmetadata-ui/src/main/resources/ui/src/components/router/AdminProtectedRoute.tsx b/openmetadata-ui/src/main/resources/ui/src/components/router/AdminProtectedRoute.tsx index 38c418bc070..3e7c4b5b9f9 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/router/AdminProtectedRoute.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/router/AdminProtectedRoute.tsx @@ -19,15 +19,16 @@ import { ROUTES } from '../../constants/constants'; import { useAuth } from '../../hooks/authHooks'; interface AdminProtectedRouteProps extends RouteProps { - hasPermission: boolean; + hasPermission?: boolean; } const AdminProtectedRoute = (routeProps: AdminProtectedRouteProps) => { const { isAdminUser } = useAuth(); + const hasPermission = Boolean(routeProps.hasPermission); - if (isAdminUser || routeProps.hasPermission) { + if (isAdminUser || hasPermission) { return ; - } else if (!routeProps.hasPermission) { + } else if (!hasPermission) { return ; } else { return ; diff --git a/openmetadata-ui/src/main/resources/ui/src/components/router/GlobalSettingRouter.tsx b/openmetadata-ui/src/main/resources/ui/src/components/router/GlobalSettingRouter.tsx index 5fa6ad27d2e..419e3cef589 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/router/GlobalSettingRouter.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/router/GlobalSettingRouter.tsx @@ -175,17 +175,13 @@ const GlobalSettingRouter = () => { - { - jest.fn().mockReturnValue(
Loader
) ); -jest.mock('components/PermissionProvider/PermissionProvider', () => ({ - usePermissionProvider: jest.fn().mockReturnValue({ - getEntityPermissionByFqn: jest.fn().mockReturnValue({ - Create: true, - Delete: true, - ViewAll: true, - EditAll: true, - EditDescription: true, - EditDisplayName: true, - EditCustomFields: true, - }), - }), -})); - jest.mock('../../../constants/HelperTextUtil', () => ({ NO_PERMISSION_FOR_ACTION: '', NO_PERMISSION_TO_VIEW: '', @@ -80,18 +66,6 @@ jest.mock('../../../utils/CommonUtils', () => ({ getEntityName: jest.fn().mockReturnValue(''), })); -jest.mock('../../../utils/PermissionsUtils', () => ({ - DEFAULT_ENTITY_PERMISSION: { - Create: true, - Delete: true, - ViewAll: true, - EditAll: true, - EditDescription: true, - EditDisplayName: true, - EditCustomFields: true, - }, -})); - jest.mock('../../../utils/RouterUtils', () => ({ getAddPolicyRulePath: jest.fn(), getEditPolicyRulePath: jest.fn(), diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/PoliciesPage/PoliciesDetailPage/PoliciesDetailPage.tsx b/openmetadata-ui/src/main/resources/ui/src/pages/PoliciesPage/PoliciesDetailPage/PoliciesDetailPage.tsx index 27fcb91c5b3..9679e0da752 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/PoliciesPage/PoliciesDetailPage/PoliciesDetailPage.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/pages/PoliciesPage/PoliciesDetailPage/PoliciesDetailPage.tsx @@ -22,7 +22,6 @@ import { Row, Space, Tabs, - Tooltip, Typography, } from 'antd'; import { ReactComponent as EditIcon } from 'assets/svg/edit-new.svg'; @@ -32,12 +31,6 @@ import ErrorPlaceHolder from 'components/common/error-with-placeholder/ErrorPlac import RichTextEditorPreviewer from 'components/common/rich-text-editor/RichTextEditorPreviewer'; import TitleBreadcrumb from 'components/common/title-breadcrumb/title-breadcrumb.component'; import Loader from 'components/Loader/Loader'; -import { usePermissionProvider } from 'components/PermissionProvider/PermissionProvider'; -import { - OperationPermission, - ResourceEntity, -} from 'components/PermissionProvider/PermissionProvider.interface'; -import { ERROR_PLACEHOLDER_TYPE } from 'enums/common.enum'; import { compare } from 'fast-json-patch'; import { isEmpty, isUndefined, startCase } from 'lodash'; import React, { useCallback, useEffect, useMemo, useState } from 'react'; @@ -59,7 +52,6 @@ import { EntityType } from '../../../enums/entity.enum'; import { Rule } from '../../../generated/api/policies/createPolicy'; import { Policy } from '../../../generated/entity/policies/policy'; import { EntityReference } from '../../../generated/type/entityReference'; -import { DEFAULT_ENTITY_PERMISSION } from '../../../utils/PermissionsUtils'; import { getAddPolicyRulePath, getEditPolicyRulePath, @@ -78,7 +70,6 @@ const PoliciesDetailPage = () => { const { t } = useTranslation(); const history = useHistory(); const { fqn } = useParams<{ fqn: string }>(); - const { getEntityPermissionByFqn } = usePermissionProvider(); const [policy, setPolicy] = useState({} as Policy); const [isLoading, setLoading] = useState(false); @@ -87,10 +78,6 @@ const PoliciesDetailPage = () => { const [selectedEntity, setEntity] = useState<{ attribute: Attribute; record: EntityReference }>(); - const [policyPermission, setPolicyPermission] = useState( - DEFAULT_ENTITY_PERMISSION - ); - const policiesPath = getSettingPath( GlobalSettingsMenuCategory.ACCESS, GlobalSettingOptions.POLICIES @@ -110,21 +97,6 @@ const PoliciesDetailPage = () => { [policy] ); - const fetchPolicyPermission = async () => { - setLoading(true); - try { - const response = await getEntityPermissionByFqn( - ResourceEntity.POLICY, - fqn - ); - setPolicyPermission(response); - } catch (error) { - showErrorToast(error as AxiosError); - } finally { - setLoading(false); - } - }; - const fetchPolicy = async () => { setLoading(true); try { @@ -256,7 +228,6 @@ const PoliciesDetailPage = () => { (rule: Rule) => { return ( { } placement="bottomRight" trigger={['click']}> - - - -
- ) : ( -
- - {getEntityName(policy)} - - setEditDescription(false)} - onDescriptionEdit={() => setEditDescription(true)} - onDescriptionUpdate={handleDescriptionUpdate} - /> - - - {isEmpty(policy.rules) ? ( - - ) : ( - - - - - - - {policy.rules.map((rule) => ( - - - - {rule.name} - - {getRuleActionElement(rule)} - - - - {rule.description && ( - - - - {`${t('label.description')}:`} - - - - - - - )} - - - - - {`${t('label.resource-plural')}:`} - - - - - {rule.resources - ?.map((resource) => startCase(resource)) - ?.join(', ')} - - - - - - - - {`${t('label.operation-plural')}:`} - - - - - {rule.operations?.join(', ')} - - - - - - - {`${t('label.effect')}:`} - - - - - {startCase(rule.effect)} - - - - {rule.condition && ( - - - - {`${t('label.condition')}:`} - - - - {rule.condition} - - - )} - - - ))} - - - )} - - - - setEntity({ record, attribute: 'roles' }) - } - /> - - - - setEntity({ record, attribute: 'teams' }) - } - /> - - + <> + {isEmpty(policy) ? ( + +
+

+ {t('message.no-entity-found-for-name', { + entity: t('label.policy-lowercase'), + name: fqn, + })} +

+
- )} - - ) : ( - - )} + + ) : ( +
+ + {getEntityName(policy)} + + setEditDescription(false)} + onDescriptionEdit={() => setEditDescription(true)} + onDescriptionUpdate={handleDescriptionUpdate} + /> + + + + {isEmpty(policy.rules) ? ( + + ) : ( + + + + + {policy.rules.map((rule) => ( + + + + {rule.name} + + {getRuleActionElement(rule)} + + + + {rule.description && ( + + + + {`${t('label.description')}:`} + + + + + + + )} + + + + + {`${t('label.resource-plural')}:`} + + + + + {rule.resources + ?.map((resource) => startCase(resource)) + ?.join(', ')} + + + + + + + + {`${t('label.operation-plural')}:`} + + + + + {rule.operations?.join(', ')} + + + + + + + {`${t('label.effect')}:`} + + + + + {startCase(rule.effect)} + + + + {rule.condition && ( + + + + {`${t('label.condition')}:`} + + + + {rule.condition} + + + )} + + + ))} + + + )} + + + + setEntity({ record, attribute: 'roles' }) + } + /> + + + + setEntity({ record, attribute: 'teams' }) + } + /> + + +
+ )} + + {selectedEntity && ( ({ getTeamsWithFqnPath: jest.fn(), })); -jest.mock('components/PermissionProvider/PermissionProvider', () => ({ - usePermissionProvider: jest.fn().mockReturnValue({ - getEntityPermissionByFqn: jest.fn().mockReturnValue({ - Create: true, - Delete: true, - ViewAll: true, - EditAll: true, - EditDescription: true, - EditDisplayName: true, - EditCustomFields: true, - }), - }), -})); - describe('Test Roles Details Page', () => { it('Should render the detail component', async () => { render(); diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/RolesPage/RolesDetailPage/RolesDetailPage.tsx b/openmetadata-ui/src/main/resources/ui/src/pages/RolesPage/RolesDetailPage/RolesDetailPage.tsx index cb2ad831223..efaf1341d2f 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/RolesPage/RolesDetailPage/RolesDetailPage.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/pages/RolesPage/RolesDetailPage/RolesDetailPage.tsx @@ -11,17 +11,12 @@ * limitations under the License. */ -import { Button, Modal, Space, Tabs, Tooltip, Typography } from 'antd'; +import { Button, Modal, Space, Tabs, Typography } from 'antd'; import { AxiosError } from 'axios'; import Description from 'components/common/description/Description'; import ErrorPlaceHolder from 'components/common/error-with-placeholder/ErrorPlaceHolder'; import TitleBreadcrumb from 'components/common/title-breadcrumb/title-breadcrumb.component'; import Loader from 'components/Loader/Loader'; -import { usePermissionProvider } from 'components/PermissionProvider/PermissionProvider'; -import { - OperationPermission, - ResourceEntity, -} from 'components/PermissionProvider/PermissionProvider.interface'; import { ERROR_PLACEHOLDER_TYPE } from 'enums/common.enum'; import { compare } from 'fast-json-patch'; import { isEmpty, isUndefined } from 'lodash'; @@ -39,7 +34,6 @@ import { import { EntityType } from '../../../enums/entity.enum'; import { Role } from '../../../generated/entity/teams/role'; import { EntityReference } from '../../../generated/type/entityReference'; -import { DEFAULT_ENTITY_PERMISSION } from '../../../utils/PermissionsUtils'; import { getSettingPath } from '../../../utils/RouterUtils'; import { showErrorToast } from '../../../utils/ToastUtils'; import AddAttributeModal from '../AddAttributeModal/AddAttributeModal'; @@ -58,7 +52,6 @@ interface AddAttribute { const RolesDetailPage = () => { const history = useHistory(); const { t } = useTranslation(); - const { getEntityPermissionByFqn } = usePermissionProvider(); const { fqn } = useParams<{ fqn: string }>(); const [role, setRole] = useState({} as Role); @@ -70,10 +63,6 @@ const RolesDetailPage = () => { const [addAttribute, setAddAttribute] = useState(); - const [rolePermission, setRolePermission] = useState( - DEFAULT_ENTITY_PERMISSION - ); - const rolesPath = getSettingPath( GlobalSettingsMenuCategory.ACCESS, GlobalSettingOptions.ROLES @@ -93,18 +82,6 @@ const RolesDetailPage = () => { [role] ); - const fetchRolePermission = async () => { - setLoading(true); - try { - const response = await getEntityPermissionByFqn(ResourceEntity.ROLE, fqn); - setRolePermission(response); - } catch (error) { - showErrorToast(error as AxiosError); - } finally { - setLoading(false); - } - }; - const fetchRole = async () => { setLoading(true); try { @@ -238,15 +215,9 @@ const RolesDetailPage = () => { }; useEffect(() => { - fetchRolePermission(); + fetchRole(); }, [fqn]); - useEffect(() => { - if (rolePermission.ViewAll || rolePermission.ViewBasic) { - fetchRole(); - } - }, [rolePermission, fqn]); - if (isLoading) { return ; } @@ -254,112 +225,99 @@ const RolesDetailPage = () => { return (
- {rolePermission.ViewAll || rolePermission.ViewBasic ? ( - <> - {isEmpty(role) ? ( - -
-

- {t('message.no-entity-found-for-name', { - entity: t('label.role'), - name: fqn, - })} -

- -
-
- ) : ( -
- - {getEntityName(role)} - - setEditDescription(false)} - onDescriptionEdit={() => setEditDescription(true)} - onDescriptionUpdate={handleDescriptionUpdate} - /> - - - - - - - - setEntity({ record, attribute: 'policies' }) - } - /> - - - - - setEntity({ record, attribute: 'teams' }) - } - /> - - - - setEntity({ record, attribute: 'users' }) - } - /> - - + <> + {isEmpty(role) ? ( + +
+

+ {t('message.no-entity-found-for-name', { + entity: t('label.role'), + name: fqn, + })} +

+
- )} - - ) : ( - - )} + + ) : ( +
+ + {getEntityName(role)} + + setEditDescription(false)} + onDescriptionEdit={() => setEditDescription(true)} + onDescriptionUpdate={handleDescriptionUpdate} + /> + + + + + + + + setEntity({ record, attribute: 'policies' }) + } + /> + + + + + setEntity({ record, attribute: 'teams' }) + } + /> + + + + setEntity({ record, attribute: 'users' }) + } + /> + + +
+ )} + + {selectedEntity && ( , }, { label: i18next.t('label.policy-plural'), - isProtected: userPermissions.hasViewPermissions( - ResourceEntity.POLICY, - permissions - ), + isProtected: Boolean(isAdminUser), key: 'access.policies', icon: , },