Skip to content

Commit 388874a

Browse files
authored
fix: show Request Data Access button for Admin users (open-metadata#28790)
* fix: show Request Data Access button for Admin users * fix lint checks * fix unit test failure
1 parent 7600dc7 commit 388874a

4 files changed

Lines changed: 25 additions & 21 deletions

File tree

openmetadata-ui/src/main/resources/ui/src/components/DataAssets/DataAssetsHeader/DataAssetsHeader.component.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,7 @@ export const DataAssetsHeader = ({
611611
entityType !== EntityType.TABLE ||
612612
deleted ||
613613
isOwner ||
614-
currentUser?.isAdmin ||
615-
!canCreateTask
614+
(!canCreateTask && !currentUser?.isAdmin)
616615
) {
617616
return null;
618617
}
@@ -643,6 +642,7 @@ export const DataAssetsHeader = ({
643642
isDarAwaitingGrant,
644643
isDarGranted,
645644
canCreateTask,
645+
currentUser,
646646
t,
647647
]);
648648

openmetadata-ui/src/main/resources/ui/src/components/DataAssets/DataAssetsHeader/DataAssetsHeader.test.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ describe('DataAssetsHeader component', () => {
972972
).not.toBeInTheDocument();
973973
});
974974

975-
it('should not render when user is admin but has no canCreateTask permission', async () => {
975+
it('should render when user is admin even without canCreateTask permission', async () => {
976976
const { useApplicationStore } = jest.requireMock(
977977
'../../../hooks/useApplicationStore'
978978
);
@@ -983,16 +983,18 @@ describe('DataAssetsHeader component', () => {
983983

984984
render(<DataAssetsHeader {...tableProps} canCreateTask={false} />);
985985

986-
expect(
987-
screen.queryByTestId('request-data-access-button')
988-
).not.toBeInTheDocument();
986+
await waitFor(() => {
987+
expect(
988+
screen.getByTestId('request-data-access-button')
989+
).toBeInTheDocument();
990+
});
989991

990992
(useApplicationStore as jest.Mock).mockReturnValue({
991993
currentUser: { id: 'user-1', name: 'test.user' },
992994
});
993995
});
994996

995-
it('should not render when user is admin even with canCreateTask permission', async () => {
997+
it('should render when user is admin with canCreateTask permission', async () => {
996998
const { useApplicationStore } = jest.requireMock(
997999
'../../../hooks/useApplicationStore'
9981000
);
@@ -1004,8 +1006,8 @@ describe('DataAssetsHeader component', () => {
10041006

10051007
await waitFor(() => {
10061008
expect(
1007-
screen.queryByTestId('request-data-access-button')
1008-
).not.toBeInTheDocument();
1009+
screen.getByTestId('request-data-access-button')
1010+
).toBeInTheDocument();
10091011
});
10101012

10111013
(useApplicationStore as jest.Mock).mockReturnValue({
@@ -1017,9 +1019,11 @@ describe('DataAssetsHeader component', () => {
10171019
const { useApplicationStore } = jest.requireMock(
10181020
'../../../hooks/useApplicationStore'
10191021
);
1022+
const { hasEditAccess } = jest.requireMock('../../../utils/EntityUtils');
10201023
(useApplicationStore as jest.Mock).mockReturnValue({
10211024
currentUser: { id: 'user-1', name: 'test.user', isAdmin: true },
10221025
});
1026+
(hasEditAccess as jest.Mock).mockReturnValue(true);
10231027

10241028
render(
10251029
<DataAssetsHeader
@@ -1038,6 +1042,7 @@ describe('DataAssetsHeader component', () => {
10381042
(useApplicationStore as jest.Mock).mockReturnValue({
10391043
currentUser: { id: 'user-1', name: 'test.user' },
10401044
});
1045+
(hasEditAccess as jest.Mock).mockReturnValue(false);
10411046
});
10421047

10431048
it('should render for non-admin user with canCreateTask permission who is not owner', async () => {

openmetadata-ui/src/main/resources/ui/src/components/DataProducts/DataProductsDetailsPage/DataProductsDetailsPage.component.test.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,10 @@ jest.mock('../../../hooks/useCustomPages', () => ({
9797
.mockReturnValue({ customizedPage: null, isLoading: false }),
9898
}));
9999
jest.mock('../../../hooks/useMarketplaceStore', () => ({
100-
useMarketplaceStore: jest
101-
.fn()
102-
.mockReturnValue({
103-
isMarketplace: false,
104-
dataProductBasePath: '/data-product',
105-
}),
100+
useMarketplaceStore: jest.fn().mockReturnValue({
101+
isMarketplace: false,
102+
dataProductBasePath: '/data-product',
103+
}),
106104
}));
107105
jest.mock('../../../rest/dataProductAPI', () => ({
108106
getDataProductPortsView: jest.fn().mockResolvedValue({ data: [] }),
@@ -163,17 +161,19 @@ describe('DataProductsDetailsPage — Request Data Access button', () => {
163161
).not.toBeInTheDocument();
164162
});
165163

166-
it('does not render for an admin even when the feature flag is on', () => {
164+
it('renders and is enabled for an admin when the feature flag is on', () => {
167165
enableRequestDataAccess();
168166
(useApplicationStore as unknown as jest.Mock).mockReturnValue({
169167
currentUser: { id: 'admin-1', name: 'admin', isAdmin: true },
170168
});
169+
(usePermissionProvider as jest.Mock).mockReturnValue({
170+
getEntityPermission: jest.fn().mockResolvedValue({}),
171+
permissions: { task: { Create: false } },
172+
});
171173

172174
render(<DataProductsDetailsPage {...defaultProps} />);
173175

174-
expect(
175-
screen.queryByTestId('request-data-access-button')
176-
).not.toBeInTheDocument();
176+
expect(screen.getByTestId('request-data-access-button')).toBeEnabled();
177177
});
178178

179179
it('does not render for the entity owner', () => {

openmetadata-ui/src/main/resources/ui/src/components/DataProducts/DataProductsDetailsPage/DataProductsDetailsPage.component.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,8 +896,7 @@ const DataProductsDetailsPage = ({
896896
<div className="tw:flex tw:gap-3 tw:justify-end tw:items-center tw:pb-1">
897897
{!isVersionsView &&
898898
!isOwner &&
899-
!currentUser?.isAdmin &&
900-
canCreateTask &&
899+
(canCreateTask || currentUser?.isAdmin) &&
901900
dataProductClassBase.getShowRequestDataAccess() && (
902901
<CoreTooltip
903902
isDisabled={!isDarDisabled}

0 commit comments

Comments
 (0)