mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-07-12 19:48:26 +00:00
* FIx #7136 UI: Admin is not able to edit an announcement * Change edit check * Addressing review comments
This commit is contained in:
parent
2f84bfbfa8
commit
ccd3d1fcae
@ -43,6 +43,7 @@ jest.mock('../../../AppState', () => {
|
||||
fullyQualifiedName: 'aaron_johnson0',
|
||||
displayName: 'Aaron Johnson',
|
||||
deleted: false,
|
||||
isAdmin: true,
|
||||
href: 'http://localhost:8585/api/v1/users/011bdb24-90a7-4a97-ba66-24002adb2b12',
|
||||
teams: [{ id: '8754b53f-15cd-4d9a-af52-bdb3a2abffss' }],
|
||||
};
|
||||
@ -96,22 +97,6 @@ describe('Test Popover content component', () => {
|
||||
expect(replyButton).toBe(null);
|
||||
});
|
||||
|
||||
it('Should not render the edit button if user is not a author', async () => {
|
||||
render(<PopoverContent {...mockProps} isAuthor={false} />);
|
||||
|
||||
const editButton = screen.queryByTestId('edit-message');
|
||||
|
||||
expect(editButton).toBe(null);
|
||||
});
|
||||
|
||||
it('Should not render the delete button if user is not a author', async () => {
|
||||
render(<PopoverContent {...mockProps} isAuthor={false} />);
|
||||
|
||||
const deleteButton = screen.queryByTestId('delete-message');
|
||||
|
||||
expect(deleteButton).toBe(null);
|
||||
});
|
||||
|
||||
it('Should render reaction popover on click of reaction button', async () => {
|
||||
render(<PopoverContent {...mockProps} />);
|
||||
|
||||
@ -162,4 +147,28 @@ describe('Test Popover content component', () => {
|
||||
|
||||
expect(onConfirmation).toBeCalled();
|
||||
});
|
||||
|
||||
it('Announcement should be editable by admin user', async () => {
|
||||
render(<PopoverContent {...mockProps} isAnnouncement isAuthor={false} />);
|
||||
|
||||
const editButton = await screen.findByTestId('edit-message');
|
||||
|
||||
expect(editButton).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(editButton);
|
||||
|
||||
expect(onEdit).toBeCalled();
|
||||
});
|
||||
|
||||
it('Announcement should be delete by admin user', async () => {
|
||||
render(<PopoverContent {...mockProps} isAnnouncement isAuthor={false} />);
|
||||
|
||||
const deleteButton = await screen.findByTestId('delete-message');
|
||||
|
||||
expect(deleteButton).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(deleteButton);
|
||||
|
||||
expect(onConfirmation).toBeCalled();
|
||||
});
|
||||
});
|
||||
|
@ -51,7 +51,6 @@ const PopoverContent: FC<Props> = ({
|
||||
onReactionSelect,
|
||||
onPopoverHide,
|
||||
onEdit,
|
||||
isAnnouncement,
|
||||
}) => {
|
||||
// get current user details
|
||||
const currentUser = useMemo(
|
||||
@ -69,7 +68,16 @@ const PopoverContent: FC<Props> = ({
|
||||
setVisible(newVisible);
|
||||
};
|
||||
|
||||
const deleteButtonCheck = threadId && postId && onConfirmation && isAuthor;
|
||||
const deleteButtonCheck = useMemo(() => {
|
||||
const baseCheck = Boolean(threadId && postId && onConfirmation);
|
||||
|
||||
return Boolean(baseCheck && (isAuthor || currentUser?.isAdmin));
|
||||
}, [threadId, postId, onConfirmation, isAuthor, currentUser]);
|
||||
|
||||
const editCheck = useMemo(
|
||||
() => isAuthor || currentUser?.isAdmin,
|
||||
[isAuthor, currentUser]
|
||||
);
|
||||
|
||||
const handleDelete = (e: React.MouseEvent<HTMLButtonElement>) => {
|
||||
e.stopPropagation();
|
||||
@ -146,8 +154,6 @@ const PopoverContent: FC<Props> = ({
|
||||
onEdit && onEdit();
|
||||
};
|
||||
|
||||
const editCheck = (isAnnouncement || !isThread) && isAuthor;
|
||||
|
||||
return (
|
||||
<Space>
|
||||
<Popover
|
||||
|
Loading…
x
Reference in New Issue
Block a user