From e5c27ab8519fe137d7862c2b5200c0807674dc13 Mon Sep 17 00:00:00 2001 From: Shailesh Parmar Date: Thu, 19 Dec 2024 12:41:08 +0530 Subject: [PATCH 1/3] Feat: revamp the permissions in test case and test suite details page --- .../IncidentManagerPageHeader.component.tsx | 29 ++++---- .../TestCaseResultTab.component.tsx | 23 +++--- ...estCaseIncidentManagerStatus.component.tsx | 12 ++- ...TestCaseIncidentManagerStatus.interface.ts | 1 + .../DataQualityTab/DataQualityTab.tsx | 74 +++++++++++++------ .../profilerDashboard.interface.ts | 5 ++ .../IncidentManagerDetailPage.tsx | 63 ++++++++++------ .../useTestCase.store.ts | 17 +++++ .../TestSuiteDetailsPage.component.tsx | 26 +++++-- 9 files changed, 167 insertions(+), 83 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/IncidentManagerPageHeader/IncidentManagerPageHeader.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/IncidentManagerPageHeader/IncidentManagerPageHeader.component.tsx index c417d45b4b62..4914f442b369 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/IncidentManagerPageHeader/IncidentManagerPageHeader.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/IncidentManagerPageHeader/IncidentManagerPageHeader.component.tsx @@ -19,8 +19,6 @@ import React, { useEffect, useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Link, useParams } from 'react-router-dom'; import { getEntityDetailsPath } from '../../../../constants/constants'; -import { usePermissionProvider } from '../../../../context/PermissionProvider/PermissionProvider'; -import { ResourceEntity } from '../../../../context/PermissionProvider/PermissionProvider.interface'; import { EntityTabs, EntityType } from '../../../../enums/entity.enum'; import { ThreadType } from '../../../../generated/api/feed/createThread'; import { CreateTestCaseResolutionStatus } from '../../../../generated/api/tests/createTestCaseResolutionStatus'; @@ -28,13 +26,13 @@ import { Thread, ThreadTaskStatus, } from '../../../../generated/entity/feed/thread'; -import { Operation } from '../../../../generated/entity/policies/policy'; import { EntityReference } from '../../../../generated/tests/testCase'; import { Severities, TestCaseResolutionStatus, TestCaseResolutionStatusTypes, } from '../../../../generated/tests/testCaseResolutionStatus'; +import { useTestCaseStore } from '../../../../pages/IncidentManager/IncidentManagerDetailPage/useTestCase.store'; import { getListTestCaseIncidentByStateId, postTestCaseIncidentStatus, @@ -46,7 +44,6 @@ import { getEntityName, } from '../../../../utils/EntityUtils'; import { getEntityFQN } from '../../../../utils/FeedUtils'; -import { checkPermission } from '../../../../utils/PermissionsUtils'; import { getDecodedFqn } from '../../../../utils/StringsUtils'; import { getTaskDetailPath } from '../../../../utils/TasksUtils'; import { showErrorToast } from '../../../../utils/ToastUtils'; @@ -59,7 +56,6 @@ import { IncidentManagerPageHeaderProps } from './IncidentManagerPageHeader.inte const IncidentManagerPageHeader = ({ onOwnerUpdate, - testCaseData, fetchTaskCount, }: IncidentManagerPageHeaderProps) => { const { t } = useTranslation(); @@ -67,6 +63,7 @@ const IncidentManagerPageHeader = ({ const [testCaseStatusData, setTestCaseStatusData] = useState(); const [isLoading, setIsLoading] = useState(true); + const { testCase: testCaseData, testCasePermission } = useTestCaseStore(); const { fqn } = useParams<{ fqn: string }>(); const decodedFqn = getDecodedFqn(fqn); @@ -212,14 +209,14 @@ const IncidentManagerPageHeader = ({ } }, [testCaseData]); - const { permissions } = usePermissionProvider(); - const hasEditPermission = useMemo(() => { - return checkPermission( - Operation.EditAll, - ResourceEntity.TEST_CASE, - permissions - ); - }, [permissions]); + const { hasEditStatusPermission, hasEditOwnerPermission } = useMemo(() => { + return { + hasEditStatusPermission: + testCasePermission?.EditAll || testCasePermission?.EditStatus, + hasEditOwnerPermission: + testCasePermission?.EditAll || testCasePermission?.EditOwners, + }; + }, []); const statusDetails = useMemo(() => { if (isLoading) { @@ -257,7 +254,7 @@ const IncidentManagerPageHeader = ({ className="font-medium" data-testid="table-name" to={getTaskDetailPath(activeTask)}> - {`#${activeTask?.task?.id}` ?? '--'} + {`#${activeTask?.task?.id}`} @@ -281,7 +278,7 @@ const IncidentManagerPageHeader = ({ {`${t('label.assignee')}: `} diff --git a/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/TestCaseResultTab/TestCaseResultTab.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/TestCaseResultTab/TestCaseResultTab.component.tsx index 379d942f481a..22172643f4cb 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/TestCaseResultTab/TestCaseResultTab.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/TestCaseResultTab/TestCaseResultTab.component.tsx @@ -23,17 +23,13 @@ import { DE_ACTIVE_COLOR, ICON_DIMENSION, } from '../../../../constants/constants'; -import { usePermissionProvider } from '../../../../context/PermissionProvider/PermissionProvider'; -import { ResourceEntity } from '../../../../context/PermissionProvider/PermissionProvider.interface'; import { CSMode } from '../../../../enums/codemirror.enum'; import { EntityType } from '../../../../enums/entity.enum'; -import { Operation } from '../../../../generated/entity/policies/policy'; import { ReactComponent as StarIcon } from '../../../../assets/svg/ic-suggestions.svg'; import { TestCaseParameterValue } from '../../../../generated/tests/testCase'; import { useTestCaseStore } from '../../../../pages/IncidentManager/IncidentManagerDetailPage/useTestCase.store'; import { updateTestCaseById } from '../../../../rest/testAPI'; -import { checkPermission } from '../../../../utils/PermissionsUtils'; import { showErrorToast, showSuccessToast } from '../../../../utils/ToastUtils'; import DescriptionV1 from '../../../common/EntityDescription/DescriptionV1'; import TestSummary from '../../../Database/Profiler/TestSummary/TestSummary'; @@ -49,19 +45,20 @@ const TestCaseResultTab = () => { testCase: testCaseData, setTestCase, showAILearningBanner, + testCasePermission, } = useTestCaseStore(); const additionalComponent = testCaseResultTabClassBase.getAdditionalComponents(); const [isDescriptionEdit, setIsDescriptionEdit] = useState(false); const [isParameterEdit, setIsParameterEdit] = useState(false); - const { permissions } = usePermissionProvider(); - const hasEditPermission = useMemo(() => { - return checkPermission( - Operation.EditAll, - ResourceEntity.TEST_CASE, - permissions - ); - }, [permissions]); + + const { hasEditPermission, hasEditDescriptionPermission } = useMemo(() => { + return { + hasEditPermission: testCasePermission?.EditAll, + hasEditDescriptionPermission: + testCasePermission?.EditAll || testCasePermission?.EditDescription, + }; + }, [testCasePermission]); const { withSqlParams, withoutSqlParams } = useMemo(() => { const params = testCaseData?.parameterValues ?? []; @@ -168,7 +165,7 @@ const TestCaseResultTab = () => { setIsDescriptionEdit(false)} diff --git a/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/TestCaseStatus/TestCaseIncidentManagerStatus.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/TestCaseStatus/TestCaseIncidentManagerStatus.component.tsx index 11677985027d..62e129844bf5 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/TestCaseStatus/TestCaseIncidentManagerStatus.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/TestCaseStatus/TestCaseIncidentManagerStatus.component.tsx @@ -35,16 +35,20 @@ const TestCaseIncidentManagerStatus = ({ data, onSubmit, usersList, + hasPermission, }: TestCaseStatusIncidentManagerProps) => { const [isEditStatus, setIsEditStatus] = useState(false); const statusType = useMemo(() => data.testCaseResolutionStatusType, [data]); const { permissions } = usePermissionProvider(); const hasEditPermission = useMemo(() => { - return checkPermission( - Operation.EditAll, - ResourceEntity.TEST_CASE, - permissions + return ( + hasPermission ?? + checkPermission( + Operation.EditAll, + ResourceEntity.TEST_CASE_RESOLUTION_STATUS, + permissions + ) ); }, [permissions]); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/TestCaseStatus/TestCaseIncidentManagerStatus.interface.ts b/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/TestCaseStatus/TestCaseIncidentManagerStatus.interface.ts index 8fc98be9fe24..415a5e81d15a 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/TestCaseStatus/TestCaseIncidentManagerStatus.interface.ts +++ b/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/TestCaseStatus/TestCaseIncidentManagerStatus.interface.ts @@ -18,4 +18,5 @@ export interface TestCaseStatusIncidentManagerProps { data: TestCaseResolutionStatus; onSubmit: (data: TestCaseResolutionStatus) => void; usersList?: EntityReference[]; + hasPermission?: boolean; } diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Database/Profiler/DataQualityTab/DataQualityTab.tsx b/openmetadata-ui/src/main/resources/ui/src/components/Database/Profiler/DataQualityTab/DataQualityTab.tsx index 08d3dd98f4fe..16275a92547f 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/Database/Profiler/DataQualityTab/DataQualityTab.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/Database/Profiler/DataQualityTab/DataQualityTab.tsx @@ -31,7 +31,6 @@ import { usePermissionProvider } from '../../../../context/PermissionProvider/Pe import { ResourceEntity } from '../../../../context/PermissionProvider/PermissionProvider.interface'; import { SORT_ORDER } from '../../../../enums/common.enum'; import { EntityTabs, EntityType } from '../../../../enums/entity.enum'; -import { Operation } from '../../../../generated/entity/policies/policy'; import { TestCase, TestCaseResult, @@ -50,7 +49,6 @@ import { getEntityName, } from '../../../../utils/EntityUtils'; import { getEntityFQN } from '../../../../utils/FeedUtils'; -import { checkPermission } from '../../../../utils/PermissionsUtils'; import { getIncidentManagerDetailPagePath } from '../../../../utils/RouterUtils'; import { replacePlus } from '../../../../utils/StringsUtils'; import { showErrorToast } from '../../../../utils/ToastUtils'; @@ -66,6 +64,7 @@ import { DataQualityTabProps, TableProfilerTab, TestCaseAction, + TestCasePermission, } from '../ProfilerDashboard/profilerDashboard.interface'; import './data-quality-tab.less'; @@ -82,30 +81,18 @@ const DataQualityTab: React.FC = ({ fetchTestCases, }) => { const { t } = useTranslation(); - const { permissions } = usePermissionProvider(); + const { getEntityPermissionByFqn } = usePermissionProvider(); const [selectedTestCase, setSelectedTestCase] = useState(); const [isStatusLoading, setIsStatusLoading] = useState(true); const [testCaseStatus, setTestCaseStatus] = useState< TestCaseResolutionStatus[] >([]); + const [isPermissionLoading, setIsPermissionLoading] = useState(true); + const [testCasePermissions, setTestCasePermissions] = useState< + TestCasePermission[] + >([]); const isApiSortingEnabled = useRef(false); - const testCaseEditPermission = useMemo(() => { - return checkPermission( - Operation.EditAll, - ResourceEntity.TEST_CASE, - permissions - ); - }, [permissions]); - - const testCaseDeletePermission = useMemo(() => { - return checkPermission( - Operation.Delete, - ResourceEntity.TEST_CASE, - permissions - ); - }, [permissions]); - const sortedData = useMemo( () => isApiSortingEnabled.current @@ -312,6 +299,18 @@ const DataQualityTab: React.FC = ({ width: 100, fixed: 'right', render: (_, record) => { + if (isPermissionLoading) { + return ; + } + + const testCasePermission = testCasePermissions.find( + (permission) => + permission.fullyQualifiedName === record.fullyQualifiedName + ); + + const testCaseEditPermission = testCasePermission?.EditAll; + const testCaseDeletePermission = testCasePermission?.Delete; + return ( = ({ return data; }, [ - testCaseEditPermission, - testCaseDeletePermission, testCases, testCaseStatus, isStatusLoading, + isPermissionLoading, + testCasePermissions, ]); const fetchTestCaseStatus = async () => { @@ -422,6 +421,38 @@ const DataQualityTab: React.FC = ({ } }; + const fetchTestCasePermissions = async () => { + try { + setIsPermissionLoading(true); + const promises = testCases.map((testCase) => { + return getEntityPermissionByFqn( + ResourceEntity.TEST_CASE, + testCase.fullyQualifiedName ?? '' + ); + }); + const testCasePermission = await Promise.allSettled(promises); + const data = testCasePermission.reduce((acc, status, i) => { + if (status.status === 'fulfilled') { + return [ + ...acc, + { + ...status.value, + fullyQualifiedName: testCases[i].fullyQualifiedName, + }, + ]; + } + + return acc; + }, [] as TestCasePermission[]); + + setTestCasePermissions(data); + } catch (error) { + // do nothing + } finally { + setIsPermissionLoading(false); + } + }; + const handleTableChange = ( _pagination: TablePaginationConfig, _filters: Record, @@ -448,6 +479,7 @@ const DataQualityTab: React.FC = ({ useEffect(() => { if (testCases.length) { fetchTestCaseStatus(); + fetchTestCasePermissions(); } else { setIsStatusLoading(false); } diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Database/Profiler/ProfilerDashboard/profilerDashboard.interface.ts b/openmetadata-ui/src/main/resources/ui/src/components/Database/Profiler/ProfilerDashboard/profilerDashboard.interface.ts index 2c249b7e3a73..171dde89ed0a 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/Database/Profiler/ProfilerDashboard/profilerDashboard.interface.ts +++ b/openmetadata-ui/src/main/resources/ui/src/components/Database/Profiler/ProfilerDashboard/profilerDashboard.interface.ts @@ -12,6 +12,7 @@ */ import { CurveType } from 'recharts/types/shape/Curve'; +import { OperationPermission } from '../../../../context/PermissionProvider/PermissionProvider.interface'; import { Thread } from '../../../../generated/entity/feed/thread'; import { TestCase } from '../../../../generated/tests/testCase'; import { TestSuite } from '../../../../generated/tests/testSuite'; @@ -87,3 +88,7 @@ export type TestCaseChartDataType = { export interface LineChartRef { container: HTMLElement; } + +export type TestCasePermission = OperationPermission & { + fullyQualifiedName?: string; +}; diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/IncidentManager/IncidentManagerDetailPage/IncidentManagerDetailPage.tsx b/openmetadata-ui/src/main/resources/ui/src/pages/IncidentManager/IncidentManagerDetailPage/IncidentManagerDetailPage.tsx index 2e535783fbf8..57bbda22a1cf 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/IncidentManager/IncidentManagerDetailPage/IncidentManagerDetailPage.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/pages/IncidentManager/IncidentManagerDetailPage/IncidentManagerDetailPage.tsx @@ -34,13 +34,11 @@ import { usePermissionProvider } from '../../../context/PermissionProvider/Permi import { ResourceEntity } from '../../../context/PermissionProvider/PermissionProvider.interface'; import { ERROR_PLACEHOLDER_TYPE } from '../../../enums/common.enum'; import { EntityTabs, EntityType } from '../../../enums/entity.enum'; -import { Operation } from '../../../generated/entity/policies/policy'; import { EntityReference } from '../../../generated/tests/testCase'; import { useFqn } from '../../../hooks/useFqn'; import { FeedCounts } from '../../../interface/feed.interface'; import { getTestCaseByFqn, updateTestCaseById } from '../../../rest/testAPI'; import { getFeedCounts } from '../../../utils/CommonUtils'; -import { checkPermission } from '../../../utils/PermissionsUtils'; import { getIncidentManagerDetailPagePath } from '../../../utils/RouterUtils'; import { showErrorToast } from '../../../utils/ToastUtils'; import { IncidentManagerTabs } from '../IncidentManager.interface'; @@ -58,33 +56,32 @@ const IncidentManagerDetailPage = () => { const { fqn: testCaseFQN } = useFqn(); - const { isLoading, setIsLoading, setTestCase, testCase, reset } = - useTestCaseStore(); + const { + isLoading, + setIsLoading, + setTestCase, + testCase, + reset, + isPermissionLoading, + testCasePermission, + setTestCasePermission, + setIsPermissionLoading, + } = useTestCaseStore(); const [feedCount, setFeedCount] = useState( FEED_COUNT_INITIAL_DATA ); - const { permissions } = usePermissionProvider(); + const { getEntityPermissionByFqn } = usePermissionProvider(); const { hasViewPermission, editDisplayNamePermission, hasDeletePermission } = useMemo(() => { return { - hasViewPermission: checkPermission( - Operation.ViewAll, - ResourceEntity.TEST_CASE, - permissions - ), - editDisplayNamePermission: checkPermission( - Operation.EditDisplayName, - ResourceEntity.TEST_CASE, - permissions - ), - hasDeletePermission: checkPermission( - Operation.Delete, - ResourceEntity.TEST_CASE, - permissions - ), + hasViewPermission: + testCasePermission?.ViewAll || testCasePermission?.ViewBasic, + editDisplayNamePermission: + testCasePermission?.EditAll || testCasePermission?.EditDisplayName, + hasDeletePermission: testCasePermission?.Delete, }; - }, [permissions]); + }, [testCasePermission]); const tabDetails: TabsProps['items'] = useMemo(() => { const tabs = testCaseClassBase.getTab(feedCount.openTaskCount); @@ -96,6 +93,22 @@ const IncidentManagerDetailPage = () => { })); }, [feedCount.openTaskCount, testCaseClassBase.showSqlQueryTab]); + const fetchTestCasePermission = async () => { + setIsPermissionLoading(true); + try { + const response = await getEntityPermissionByFqn( + ResourceEntity.TEST_CASE, + testCaseFQN + ); + + setTestCasePermission(response); + } catch (error) { + showErrorToast(error as AxiosError); + } finally { + setIsPermissionLoading(false); + } + }; + const fetchTestCaseData = async () => { setIsLoading(true); try { @@ -195,6 +208,12 @@ const IncidentManagerDetailPage = () => { getFeedCounts(EntityType.TEST_CASE, testCaseFQN, handleFeedCount); }, [testCaseFQN]); + useEffect(() => { + if (testCaseFQN) { + fetchTestCasePermission(); + } + }, [testCaseFQN]); + useEffect(() => { if (hasViewPermission && testCaseFQN) { fetchTestCaseData(); @@ -210,7 +229,7 @@ const IncidentManagerDetailPage = () => { }; }, [testCaseFQN, hasViewPermission]); - if (isLoading) { + if (isLoading || isPermissionLoading) { return ; } diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/IncidentManager/IncidentManagerDetailPage/useTestCase.store.ts b/openmetadata-ui/src/main/resources/ui/src/pages/IncidentManager/IncidentManagerDetailPage/useTestCase.store.ts index 6e5f55619626..ed2d37649687 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/IncidentManager/IncidentManagerDetailPage/useTestCase.store.ts +++ b/openmetadata-ui/src/main/resources/ui/src/pages/IncidentManager/IncidentManagerDetailPage/useTestCase.store.ts @@ -12,12 +12,19 @@ */ import { create } from 'zustand'; import { EntityLineageResponse } from '../../../components/Lineage/Lineage.interface'; +import { OperationPermission } from '../../../context/PermissionProvider/PermissionProvider.interface'; import { TestCase } from '../../../generated/tests/testCase'; export interface UseTestCaseStoreInterface { testCase: TestCase | undefined; isLoading: boolean; + isPermissionLoading: boolean; showAILearningBanner: boolean; + testCasePermission: OperationPermission | undefined; + setTestCasePermission: ( + testCasePermission: OperationPermission | undefined + ) => void; + setIsPermissionLoading: (isPermissionLoading: boolean) => void; setTestCase: (testCase: TestCase) => void; setIsLoading: (isLoading: boolean) => void; setShowAILearningBanner: (showBanner: boolean) => void; @@ -29,10 +36,20 @@ export const useTestCaseStore = create()((set) => ({ testCase: undefined, dqLineageData: undefined, isLoading: true, + isPermissionLoading: true, showAILearningBanner: false, + testCasePermission: undefined, setTestCase: (testCase: TestCase) => { set({ testCase }); }, + setTestCasePermission: ( + testCasePermission: OperationPermission | undefined + ) => { + set({ testCasePermission }); + }, + setIsPermissionLoading: (isPermissionLoading: boolean) => { + set({ isPermissionLoading }); + }, setIsLoading: (isLoading: boolean) => { set({ isLoading }); }, diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/TestSuiteDetailsPage/TestSuiteDetailsPage.component.tsx b/openmetadata-ui/src/main/resources/ui/src/pages/TestSuiteDetailsPage/TestSuiteDetailsPage.component.tsx index 2c1cbec1e395..5a77fb38af99 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/TestSuiteDetailsPage/TestSuiteDetailsPage.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/pages/TestSuiteDetailsPage/TestSuiteDetailsPage.component.tsx @@ -43,7 +43,6 @@ import { EntityType, TabSpecificField } from '../../enums/entity.enum'; import { TestCase } from '../../generated/tests/testCase'; import { TestSuite } from '../../generated/tests/testSuite'; import { Include } from '../../generated/type/include'; -import { useAuth } from '../../hooks/authHooks'; import { usePaging } from '../../hooks/paging/usePaging'; import { useFqn } from '../../hooks/useFqn'; import { DataQualityPageTabs } from '../../pages/DataQuality/DataQualityPage.interface'; @@ -67,7 +66,6 @@ const TestSuiteDetailsPage = () => { const { t } = useTranslation(); const { getEntityPermissionByFqn } = usePermissionProvider(); const { fqn: testSuiteFQN } = useFqn(); - const { isAdminUser } = useAuth(); const history = useHistory(); const afterDeleteAction = () => { @@ -107,6 +105,20 @@ const TestSuiteDetailsPage = () => { }; }, [testSuite]); + const permissions = useMemo(() => { + return { + hasViewPermission: + testSuitePermissions?.ViewAll || testSuitePermissions?.ViewBasic, + hasEditPermission: testSuitePermissions?.EditAll, + hasEditOwnerPermission: + testSuitePermissions?.EditAll || testSuitePermissions?.EditOwners, + hasEditDescriptionPermission: + testSuitePermissions?.EditAll || testSuitePermissions?.EditDescription, + hasDeletePermission: + testSuitePermissions?.EditAll || testSuitePermissions?.Delete, + }; + }, [testSuitePermissions]); + const incidentUrlState = useMemo(() => { return [ { @@ -302,10 +314,10 @@ const TestSuiteDetailsPage = () => { }; useEffect(() => { - if (testSuitePermissions.ViewAll || testSuitePermissions.ViewBasic) { + if (permissions.hasViewPermission) { fetchTestSuiteByName(); } - }, [testSuitePermissions, testSuiteFQN]); + }, [permissions, testSuiteFQN]); useEffect(() => { fetchTestSuitePermission(); @@ -365,7 +377,7 @@ const TestSuiteDetailsPage = () => { isRecursiveDelete afterDeleteAction={afterDeleteAction} allowSoftDelete={false} - canDelete={isAdminUser} + canDelete={permissions.hasDeletePermission} deleted={testSuite?.deleted} displayName={getEntityName(testSuite)} entityId={testSuite?.id} @@ -377,7 +389,7 @@ const TestSuiteDetailsPage = () => {
@@ -388,7 +400,7 @@ const TestSuiteDetailsPage = () => { description={testSuiteDescription} entityName={getEntityName(testSuite)} entityType={EntityType.TEST_SUITE} - hasEditAccess={isAdminUser} + hasEditAccess={permissions.hasEditDescriptionPermission} isEdit={isDescriptionEditable} showCommentsIcon={false} onCancel={() => descriptionHandler(false)} From 230010d2e7805ec9df209d3d9d3785ad06fd135d Mon Sep 17 00:00:00 2001 From: Shailesh Parmar Date: Thu, 19 Dec 2024 13:09:56 +0530 Subject: [PATCH 2/3] minor fixes --- .../IncidentManagerPageHeader.component.tsx | 2 +- .../TestCaseStatus/TestCaseIncidentManagerStatus.component.tsx | 2 +- .../TestSuiteDetailsPage/TestSuiteDetailsPage.component.tsx | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/IncidentManagerPageHeader/IncidentManagerPageHeader.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/IncidentManagerPageHeader/IncidentManagerPageHeader.component.tsx index 4914f442b369..6529b927f620 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/IncidentManagerPageHeader/IncidentManagerPageHeader.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/IncidentManagerPageHeader/IncidentManagerPageHeader.component.tsx @@ -216,7 +216,7 @@ const IncidentManagerPageHeader = ({ hasEditOwnerPermission: testCasePermission?.EditAll || testCasePermission?.EditOwners, }; - }, []); + }, [testCasePermission]); const statusDetails = useMemo(() => { if (isLoading) { diff --git a/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/TestCaseStatus/TestCaseIncidentManagerStatus.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/TestCaseStatus/TestCaseIncidentManagerStatus.component.tsx index 62e129844bf5..36e796753aab 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/TestCaseStatus/TestCaseIncidentManagerStatus.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/TestCaseStatus/TestCaseIncidentManagerStatus.component.tsx @@ -50,7 +50,7 @@ const TestCaseIncidentManagerStatus = ({ permissions ) ); - }, [permissions]); + }, [permissions, hasPermission]); const onEditStatus = useCallback(() => setIsEditStatus(true), []); const onCancel = useCallback(() => setIsEditStatus(false), []); diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/TestSuiteDetailsPage/TestSuiteDetailsPage.component.tsx b/openmetadata-ui/src/main/resources/ui/src/pages/TestSuiteDetailsPage/TestSuiteDetailsPage.component.tsx index 5a77fb38af99..8aaaa0d9f350 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/TestSuiteDetailsPage/TestSuiteDetailsPage.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/pages/TestSuiteDetailsPage/TestSuiteDetailsPage.component.tsx @@ -114,8 +114,7 @@ const TestSuiteDetailsPage = () => { testSuitePermissions?.EditAll || testSuitePermissions?.EditOwners, hasEditDescriptionPermission: testSuitePermissions?.EditAll || testSuitePermissions?.EditDescription, - hasDeletePermission: - testSuitePermissions?.EditAll || testSuitePermissions?.Delete, + hasDeletePermission: testSuitePermissions?.Delete, }; }, [testSuitePermissions]); From 1a9889f97d2b6929dfa4855e1b57a159384c1d22 Mon Sep 17 00:00:00 2001 From: Shailesh Parmar Date: Wed, 15 Jan 2025 17:06:10 +0530 Subject: [PATCH 3/3] added permission checks for test case details page --- .../IncidentManagerPageHeader.component.tsx | 10 +++++++++- .../IncidentManager/Severity/Severity.component.tsx | 11 +++++------ .../IncidentManager/Severity/Severity.interface.ts | 1 + 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/IncidentManagerPageHeader/IncidentManagerPageHeader.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/IncidentManagerPageHeader/IncidentManagerPageHeader.component.tsx index 6529b927f620..40ad8559f563 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/IncidentManagerPageHeader/IncidentManagerPageHeader.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/IncidentManagerPageHeader/IncidentManagerPageHeader.component.tsx @@ -267,6 +267,7 @@ const IncidentManagerPageHeader = ({ @@ -298,13 +299,20 @@ const IncidentManagerPageHeader = ({ {`${t('label.severity')}: `} ); - }, [testCaseStatusData, isLoading, activeTask, initialAssignees]); + }, [ + testCaseStatusData, + isLoading, + activeTask, + initialAssignees, + hasEditStatusPermission, + ]); return ( diff --git a/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/Severity/Severity.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/Severity/Severity.component.tsx index 19a86ac6c31d..837cf3f9aa4a 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/Severity/Severity.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/Severity/Severity.component.tsx @@ -32,17 +32,16 @@ import '../incident-manager.style.less'; import { SeverityProps } from './Severity.interface'; import SeverityModal from './SeverityModal.component'; -const Severity = ({ severity, onSubmit }: SeverityProps) => { +const Severity = ({ severity, onSubmit, hasPermission }: SeverityProps) => { const { t } = useTranslation(); const [isEditSeverity, setIsEditSeverity] = useState(false); const { permissions } = usePermissionProvider(); const hasEditPermission = useMemo(() => { - return checkPermission( - Operation.EditAll, - ResourceEntity.TEST_CASE, - permissions + return ( + hasPermission ?? + checkPermission(Operation.EditAll, ResourceEntity.TEST_CASE, permissions) ); - }, [permissions]); + }, [permissions, hasPermission]); const onEditSeverity = useCallback(() => setIsEditSeverity(true), []); const onCancel = useCallback(() => setIsEditSeverity(false), []); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/Severity/Severity.interface.ts b/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/Severity/Severity.interface.ts index 8814af9244a7..480ebad497ea 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/Severity/Severity.interface.ts +++ b/openmetadata-ui/src/main/resources/ui/src/components/DataQuality/IncidentManager/Severity/Severity.interface.ts @@ -19,6 +19,7 @@ export interface SeverityFormProps { export interface SeverityProps extends SeverityFormProps { severity?: Severities; + hasPermission?: boolean; } export interface SeverityModalProps {