mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-12-03 19:16:10 +00:00
support owner operation with editOwner and editALL for teams (#23625)
* support owner opertaion with editOwner and editALL for teams * remove the isAdmin condition here, as for admin there will be editALL permissionby default * fix the playwright test * used the getPrioritizedEditPermission method for permission check
This commit is contained in:
parent
d0074d748a
commit
dbf482f8da
@ -798,7 +798,7 @@ test.describe('Teams Page with Data Consumer User', () => {
|
|||||||
dataConsumerPage.getByTestId('edit-team-name')
|
dataConsumerPage.getByTestId('edit-team-name')
|
||||||
).not.toBeVisible();
|
).not.toBeVisible();
|
||||||
await expect(dataConsumerPage.getByTestId('add-domain')).not.toBeVisible();
|
await expect(dataConsumerPage.getByTestId('add-domain')).not.toBeVisible();
|
||||||
await expect(dataConsumerPage.getByTestId('edit-owner')).not.toBeVisible();
|
await expect(dataConsumerPage.getByTestId('edit-owner')).toBeVisible();
|
||||||
await expect(dataConsumerPage.getByTestId('edit-email')).not.toBeVisible();
|
await expect(dataConsumerPage.getByTestId('edit-email')).not.toBeVisible();
|
||||||
await expect(
|
await expect(
|
||||||
dataConsumerPage.getByTestId('edit-team-subscription')
|
dataConsumerPage.getByTestId('edit-team-subscription')
|
||||||
@ -969,12 +969,12 @@ test.describe('Teams Page action as Owner of Team', () => {
|
|||||||
state: 'detached',
|
state: 'detached',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await expect(ownerUserPage.getByTestId('edit-owner')).toBeVisible();
|
||||||
|
|
||||||
await expect(ownerUserPage.getByTestId('manage-button')).not.toBeVisible();
|
await expect(ownerUserPage.getByTestId('manage-button')).not.toBeVisible();
|
||||||
|
|
||||||
await expect(ownerUserPage.getByTestId('add-domain')).not.toBeVisible();
|
await expect(ownerUserPage.getByTestId('add-domain')).not.toBeVisible();
|
||||||
|
|
||||||
await expect(ownerUserPage.getByTestId('edit-owner')).not.toBeVisible();
|
|
||||||
|
|
||||||
await expect(ownerUserPage.getByTestId('edit-email')).not.toBeVisible();
|
await expect(ownerUserPage.getByTestId('edit-email')).not.toBeVisible();
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
@ -986,6 +986,7 @@ test.describe('Teams Page action as Owner of Team', () => {
|
|||||||
await executionOnOwnerTeam(ownerUserPage, team, {
|
await executionOnOwnerTeam(ownerUserPage, team, {
|
||||||
domain: domain,
|
domain: domain,
|
||||||
email: teamDetails.updatedEmail,
|
email: teamDetails.updatedEmail,
|
||||||
|
user: user.responseData.displayName,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -993,6 +994,7 @@ test.describe('Teams Page action as Owner of Team', () => {
|
|||||||
await executionOnOwnerTeam(ownerUserPage, team2, {
|
await executionOnOwnerTeam(ownerUserPage, team2, {
|
||||||
domain: domain,
|
domain: domain,
|
||||||
email: teamDetails.updatedEmail,
|
email: teamDetails.updatedEmail,
|
||||||
|
user: user.responseData.displayName,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1000,6 +1002,7 @@ test.describe('Teams Page action as Owner of Team', () => {
|
|||||||
await executionOnOwnerTeam(ownerUserPage, team3, {
|
await executionOnOwnerTeam(ownerUserPage, team3, {
|
||||||
domain: domain,
|
domain: domain,
|
||||||
email: teamDetails.updatedEmail,
|
email: teamDetails.updatedEmail,
|
||||||
|
user: user.responseData.displayName,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
import { APIRequestContext, expect, Page } from '@playwright/test';
|
import { APIRequestContext, expect, Page } from '@playwright/test';
|
||||||
import { GlobalSettingOptions } from '../constant/settings';
|
import { GlobalSettingOptions } from '../constant/settings';
|
||||||
import { Domain } from '../support/domain/Domain';
|
import { Domain } from '../support/domain/Domain';
|
||||||
|
import { EntityTypeEndpoint } from '../support/entity/Entity.interface';
|
||||||
import { TableClass } from '../support/entity/TableClass';
|
import { TableClass } from '../support/entity/TableClass';
|
||||||
import { TeamClass } from '../support/team/TeamClass';
|
import { TeamClass } from '../support/team/TeamClass';
|
||||||
import { UserClass } from '../support/user/UserClass';
|
import { UserClass } from '../support/user/UserClass';
|
||||||
@ -22,7 +23,7 @@ import {
|
|||||||
toastNotification,
|
toastNotification,
|
||||||
uuid,
|
uuid,
|
||||||
} from './common';
|
} from './common';
|
||||||
import { addOwner } from './entity';
|
import { addMultiOwner, addOwner } from './entity';
|
||||||
import { validateFormNameFieldInput } from './form';
|
import { validateFormNameFieldInput } from './form';
|
||||||
import { settingClick } from './sidebar';
|
import { settingClick } from './sidebar';
|
||||||
|
|
||||||
@ -447,6 +448,7 @@ export const executionOnOwnerTeam = async (
|
|||||||
data: {
|
data: {
|
||||||
domain: Domain;
|
domain: Domain;
|
||||||
email: string;
|
email: string;
|
||||||
|
user: string;
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
await team.visitTeamPage(page);
|
await team.visitTeamPage(page);
|
||||||
@ -458,6 +460,16 @@ export const executionOnOwnerTeam = async (
|
|||||||
|
|
||||||
await assignDomain(page, data.domain.responseData);
|
await assignDomain(page, data.domain.responseData);
|
||||||
|
|
||||||
|
await addMultiOwner({
|
||||||
|
page,
|
||||||
|
ownerNames: [data.user],
|
||||||
|
activatorBtnDataTestId: 'edit-owner',
|
||||||
|
resultTestId: 'teams-info-header',
|
||||||
|
endpoint: EntityTypeEndpoint.Teams,
|
||||||
|
type: 'Users',
|
||||||
|
clearAll: false,
|
||||||
|
});
|
||||||
|
|
||||||
await addEmailTeam(page, data.email);
|
await addEmailTeam(page, data.email);
|
||||||
|
|
||||||
await page.getByTestId('add-placeholder-button').click();
|
await page.getByTestId('add-placeholder-button').click();
|
||||||
|
|||||||
@ -28,10 +28,11 @@ import {
|
|||||||
} from '../../../../../constants/constants';
|
} from '../../../../../constants/constants';
|
||||||
import { EMAIL_REG_EX } from '../../../../../constants/regex.constants';
|
import { EMAIL_REG_EX } from '../../../../../constants/regex.constants';
|
||||||
import { EntityType } from '../../../../../enums/entity.enum';
|
import { EntityType } from '../../../../../enums/entity.enum';
|
||||||
|
import { Operation } from '../../../../../generated/entity/policies/policy';
|
||||||
import { Team, TeamType } from '../../../../../generated/entity/teams/team';
|
import { Team, TeamType } from '../../../../../generated/entity/teams/team';
|
||||||
import { EntityReference } from '../../../../../generated/entity/type';
|
import { EntityReference } from '../../../../../generated/entity/type';
|
||||||
import { useAuth } from '../../../../../hooks/authHooks';
|
|
||||||
import { useApplicationStore } from '../../../../../hooks/useApplicationStore';
|
import { useApplicationStore } from '../../../../../hooks/useApplicationStore';
|
||||||
|
import { getPrioritizedEditPermission } from '../../../../../utils/PermissionsUtils';
|
||||||
import { DomainLabel } from '../../../../common/DomainLabel/DomainLabel.component';
|
import { DomainLabel } from '../../../../common/DomainLabel/DomainLabel.component';
|
||||||
import { OwnerLabel } from '../../../../common/OwnerLabel/OwnerLabel.component';
|
import { OwnerLabel } from '../../../../common/OwnerLabel/OwnerLabel.component';
|
||||||
import TeamTypeSelect from '../../../../common/TeamTypeSelect/TeamTypeSelect.component';
|
import TeamTypeSelect from '../../../../common/TeamTypeSelect/TeamTypeSelect.component';
|
||||||
@ -49,8 +50,6 @@ const TeamsInfo = ({
|
|||||||
}: TeamsInfoProps) => {
|
}: TeamsInfoProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const { isAdminUser } = useAuth();
|
|
||||||
|
|
||||||
const [isEmailEdit, setIsEmailEdit] = useState<boolean>(false);
|
const [isEmailEdit, setIsEmailEdit] = useState<boolean>(false);
|
||||||
const [showTypeSelector, setShowTypeSelector] = useState(false);
|
const [showTypeSelector, setShowTypeSelector] = useState(false);
|
||||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||||
@ -62,10 +61,12 @@ const TeamsInfo = ({
|
|||||||
[currentTeam]
|
[currentTeam]
|
||||||
);
|
);
|
||||||
|
|
||||||
const { hasEditPermission, hasAccess } = useMemo(
|
const { hasEditPermission, hasEditOwnerPermission } = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
hasEditPermission: entityPermissions.EditAll && !isTeamDeleted,
|
hasEditPermission: entityPermissions.EditAll && !isTeamDeleted,
|
||||||
hasAccess: isAdminUser && !isTeamDeleted,
|
hasEditOwnerPermission:
|
||||||
|
getPrioritizedEditPermission(entityPermissions, Operation.EditOwners) &&
|
||||||
|
!isTeamDeleted,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
[entityPermissions, isTeamDeleted]
|
[entityPermissions, isTeamDeleted]
|
||||||
@ -307,7 +308,10 @@ const TeamsInfo = ({
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Space className="teams-info-header-container" size={0}>
|
<Space
|
||||||
|
className="teams-info-header-container"
|
||||||
|
data-testid="teams-info-header"
|
||||||
|
size={0}>
|
||||||
<DomainLabel
|
<DomainLabel
|
||||||
headerLayout
|
headerLayout
|
||||||
multiple
|
multiple
|
||||||
@ -320,7 +324,7 @@ const TeamsInfo = ({
|
|||||||
<Divider className="vertical-divider" type="vertical" />
|
<Divider className="vertical-divider" type="vertical" />
|
||||||
<OwnerLabel
|
<OwnerLabel
|
||||||
className="text-sm"
|
className="text-sm"
|
||||||
hasPermission={hasAccess}
|
hasPermission={hasEditOwnerPermission}
|
||||||
isCompactView={false}
|
isCompactView={false}
|
||||||
owners={owners}
|
owners={owners}
|
||||||
onUpdate={updateOwner}
|
onUpdate={updateOwner}
|
||||||
|
|||||||
@ -12,7 +12,6 @@
|
|||||||
*/
|
*/
|
||||||
import { act, fireEvent, render, screen } from '@testing-library/react';
|
import { act, fireEvent, render, screen } from '@testing-library/react';
|
||||||
import { TeamType } from '../../../../../generated/entity/teams/team';
|
import { TeamType } from '../../../../../generated/entity/teams/team';
|
||||||
import { useAuth } from '../../../../../hooks/authHooks';
|
|
||||||
import { ENTITY_PERMISSIONS } from '../../../../../mocks/Permissions.mock';
|
import { ENTITY_PERMISSIONS } from '../../../../../mocks/Permissions.mock';
|
||||||
import TeamsInfo from './TeamsInfo.component';
|
import TeamsInfo from './TeamsInfo.component';
|
||||||
|
|
||||||
@ -45,10 +44,6 @@ const mockTeam = {
|
|||||||
version: 1,
|
version: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
jest.mock('../../../../../hooks/authHooks', () => ({
|
|
||||||
useAuth: jest.fn().mockReturnValue({ isAdminUser: true }),
|
|
||||||
}));
|
|
||||||
|
|
||||||
jest.mock('../../../../common/OwnerLabel/OwnerLabel.component', () => ({
|
jest.mock('../../../../common/OwnerLabel/OwnerLabel.component', () => ({
|
||||||
OwnerLabel: jest.fn().mockImplementation(() => <div>OwnerLabel</div>),
|
OwnerLabel: jest.fn().mockImplementation(() => <div>OwnerLabel</div>),
|
||||||
}));
|
}));
|
||||||
@ -161,8 +156,6 @@ describe('TeamsInfo', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not show edit button if user does not have permission', () => {
|
it('should not show edit button if user does not have permission', () => {
|
||||||
(useAuth as jest.Mock).mockReturnValue({ isAdminUser: false });
|
|
||||||
|
|
||||||
mockEntityPermissions.EditAll = false;
|
mockEntityPermissions.EditAll = false;
|
||||||
const { queryByTestId } = render(<TeamsInfo {...teamProps} />);
|
const { queryByTestId } = render(<TeamsInfo {...teamProps} />);
|
||||||
const ownerLabel = queryByTestId('edit-email');
|
const ownerLabel = queryByTestId('edit-email');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user