Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement: Revamp the permissions for testCase & testSuite details page #19137

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ public void setFullyQualifiedName(TestSuite testSuite) {
}
}

@Override
public EntityInterface getParentEntity(TestSuite entity, String fields) {
if (entity.getExecutable()) {
return Entity.getEntity(entity.getExecutableEntityReference(), fields, ALL);
}
return null;
}

private TestSummary getTestCasesExecutionSummary(JsonObject aggregation) {
// Initialize the test summary with 0 values
TestSummary testSummary =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ public Response delete(
String fqn) {
ResourceContextInterface resourceContext = TestCaseResourceContext.builder().name(fqn).build();
OperationContext operationContext =
new OperationContext(Entity.TABLE, MetadataOperation.EDIT_TESTS);
new OperationContext(Entity.TEST_CASE, MetadataOperation.DELETE);
authorizer.authorize(securityContext, operationContext, resourceContext);
return deleteByName(uriInfo, securityContext, fqn, recursive, hardDelete);
}
Expand All @@ -854,7 +854,7 @@ public Response deleteLogicalTestCase(
@PathParam("id") UUID id) {
ResourceContextInterface resourceContext = TestCaseResourceContext.builder().id(id).build();
OperationContext operationContext =
new OperationContext(Entity.TEST_SUITE, MetadataOperation.EDIT_TESTS);
new OperationContext(Entity.TEST_CASE, MetadataOperation.DELETE);
authorizer.authorize(securityContext, operationContext, resourceContext);
DeleteResponse<TestCase> response =
repository.deleteTestCaseFromLogicalTestSuite(testSuiteId, id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,8 @@ public Response delete(
@Parameter(description = "Id of the logical test suite", schema = @Schema(type = "UUID"))
@PathParam("id")
UUID id) {
OperationContext operationContext = new OperationContext(entityType, MetadataOperation.DELETE);
OperationContext operationContext =
new OperationContext(Entity.TEST_SUITE, MetadataOperation.DELETE);
authorizer.authorize(securityContext, operationContext, getResourceContextById(id));
TestSuite testSuite = Entity.getEntity(Entity.TEST_SUITE, id, "*", ALL);
if (Boolean.TRUE.equals(testSuite.getExecutable())) {
Expand Down Expand Up @@ -724,7 +725,8 @@ public Response delete(
@Parameter(description = "FQN of the logical test suite", schema = @Schema(type = "String"))
@PathParam("name")
String name) {
OperationContext operationContext = new OperationContext(entityType, MetadataOperation.DELETE);
OperationContext operationContext =
new OperationContext(Entity.TEST_SUITE, MetadataOperation.DELETE);
authorizer.authorize(securityContext, operationContext, getResourceContextByName(name));
TestSuite testSuite = Entity.getEntityByName(Entity.TEST_SUITE, name, "*", ALL);
if (Boolean.TRUE.equals(testSuite.getExecutable())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,20 @@ 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';
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,
Expand All @@ -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';
Expand All @@ -59,14 +56,14 @@ import { IncidentManagerPageHeaderProps } from './IncidentManagerPageHeader.inte

const IncidentManagerPageHeader = ({
onOwnerUpdate,
testCaseData,
fetchTaskCount,
}: IncidentManagerPageHeaderProps) => {
const { t } = useTranslation();
const [activeTask, setActiveTask] = useState<Thread>();
const [testCaseStatusData, setTestCaseStatusData] =
useState<TestCaseResolutionStatus>();
const [isLoading, setIsLoading] = useState(true);
const { testCase: testCaseData, testCasePermission } = useTestCaseStore();

const { fqn } = useParams<{ fqn: string }>();
const decodedFqn = getDecodedFqn(fqn);
Expand Down Expand Up @@ -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,
};
}, [testCasePermission]);

const statusDetails = useMemo(() => {
if (isLoading) {
Expand Down Expand Up @@ -257,7 +254,7 @@ const IncidentManagerPageHeader = ({
className="font-medium"
data-testid="table-name"
to={getTaskDetailPath(activeTask)}>
{`#${activeTask?.task?.id}` ?? '--'}
{`#${activeTask?.task?.id}`}
</Link>
</Typography.Text>
</>
Expand All @@ -281,7 +278,7 @@ const IncidentManagerPageHeader = ({
<span className="text-grey-muted">{`${t('label.assignee')}: `}</span>

<OwnerLabel
hasPermission={hasEditPermission}
hasPermission={hasEditStatusPermission}
multiple={{
user: false,
team: false,
Expand Down Expand Up @@ -312,7 +309,7 @@ const IncidentManagerPageHeader = ({
return (
<Space wrap align="center">
<OwnerLabel
hasPermission={hasEditPermission}
hasPermission={hasEditOwnerPermission}
owners={testCaseData?.owners}
onUpdate={onOwnerUpdate}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -49,19 +45,20 @@ const TestCaseResultTab = () => {
testCase: testCaseData,
setTestCase,
showAILearningBanner,
testCasePermission,
} = useTestCaseStore();
const additionalComponent =
testCaseResultTabClassBase.getAdditionalComponents();
const [isDescriptionEdit, setIsDescriptionEdit] = useState<boolean>(false);
const [isParameterEdit, setIsParameterEdit] = useState<boolean>(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 ?? [];
Expand Down Expand Up @@ -168,7 +165,7 @@ const TestCaseResultTab = () => {
<DescriptionV1
description={testCaseData?.description}
entityType={EntityType.TEST_CASE}
hasEditAccess={hasEditPermission}
hasEditAccess={hasEditDescriptionPermission}
isEdit={isDescriptionEdit}
showCommentsIcon={false}
onCancel={() => setIsDescriptionEdit(false)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,22 @@ const TestCaseIncidentManagerStatus = ({
data,
onSubmit,
usersList,
hasPermission,
}: TestCaseStatusIncidentManagerProps) => {
const [isEditStatus, setIsEditStatus] = useState<boolean>(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]);
}, [permissions, hasPermission]);

const onEditStatus = useCallback(() => setIsEditStatus(true), []);
const onCancel = useCallback(() => setIsEditStatus(false), []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export interface TestCaseStatusIncidentManagerProps {
data: TestCaseResolutionStatus;
onSubmit: (data: TestCaseResolutionStatus) => void;
usersList?: EntityReference[];
hasPermission?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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';
Expand All @@ -66,6 +64,7 @@ import {
DataQualityTabProps,
TableProfilerTab,
TestCaseAction,
TestCasePermission,
} from '../ProfilerDashboard/profilerDashboard.interface';
import './data-quality-tab.less';

Expand All @@ -82,30 +81,18 @@ const DataQualityTab: React.FC<DataQualityTabProps> = ({
fetchTestCases,
}) => {
const { t } = useTranslation();
const { permissions } = usePermissionProvider();
const { getEntityPermissionByFqn } = usePermissionProvider();
const [selectedTestCase, setSelectedTestCase] = useState<TestCaseAction>();
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
Expand Down Expand Up @@ -312,6 +299,18 @@ const DataQualityTab: React.FC<DataQualityTabProps> = ({
width: 100,
fixed: 'right',
render: (_, record) => {
if (isPermissionLoading) {
return <Skeleton.Input size="small" />;
}

const testCasePermission = testCasePermissions.find(
(permission) =>
permission.fullyQualifiedName === record.fullyQualifiedName
);

const testCaseEditPermission = testCasePermission?.EditAll;
const testCaseDeletePermission = testCasePermission?.Delete;

return (
<Row align="middle">
<Tooltip
Expand Down Expand Up @@ -386,11 +385,11 @@ const DataQualityTab: React.FC<DataQualityTabProps> = ({

return data;
}, [
testCaseEditPermission,
testCaseDeletePermission,
testCases,
testCaseStatus,
isStatusLoading,
isPermissionLoading,
testCasePermissions,
]);

const fetchTestCaseStatus = async () => {
Expand Down Expand Up @@ -422,6 +421,38 @@ const DataQualityTab: React.FC<DataQualityTabProps> = ({
}
};

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<string, FilterValue | null>,
Expand All @@ -448,6 +479,7 @@ const DataQualityTab: React.FC<DataQualityTabProps> = ({
useEffect(() => {
if (testCases.length) {
fetchTestCaseStatus();
fetchTestCasePermissions();
} else {
setIsStatusLoading(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -87,3 +88,7 @@ export type TestCaseChartDataType = {
export interface LineChartRef {
container: HTMLElement;
}

export type TestCasePermission = OperationPermission & {
fullyQualifiedName?: string;
};
Loading
Loading