From ccd3d1fcae69263e12b23fce29122c5bf751d5d7 Mon Sep 17 00:00:00 2001 From: Sachin Chaurasiya Date: Fri, 2 Sep 2022 11:03:44 +0530 Subject: [PATCH] FIx #7136 UI: Admin is not able to edit an announcement (#7144) * FIx #7136 UI: Admin is not able to edit an announcement * Change edit check * Addressing review comments --- .../ActivityFeedCard/PopoverContent.test.tsx | 41 +++++++++++-------- .../ActivityFeedCard/PopoverContent.tsx | 14 +++++-- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/src/components/ActivityFeed/ActivityFeedCard/PopoverContent.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/ActivityFeed/ActivityFeedCard/PopoverContent.test.tsx index af73949d832..62042163d39 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/ActivityFeed/ActivityFeedCard/PopoverContent.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/ActivityFeed/ActivityFeedCard/PopoverContent.test.tsx @@ -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(); - - 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(); - - const deleteButton = screen.queryByTestId('delete-message'); - - expect(deleteButton).toBe(null); - }); - it('Should render reaction popover on click of reaction button', async () => { render(); @@ -162,4 +147,28 @@ describe('Test Popover content component', () => { expect(onConfirmation).toBeCalled(); }); + + it('Announcement should be editable by admin user', async () => { + render(); + + 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(); + + const deleteButton = await screen.findByTestId('delete-message'); + + expect(deleteButton).toBeInTheDocument(); + + fireEvent.click(deleteButton); + + expect(onConfirmation).toBeCalled(); + }); }); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/ActivityFeed/ActivityFeedCard/PopoverContent.tsx b/openmetadata-ui/src/main/resources/ui/src/components/ActivityFeed/ActivityFeedCard/PopoverContent.tsx index b018d8fda28..b1c3ead3adf 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/ActivityFeed/ActivityFeedCard/PopoverContent.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/ActivityFeed/ActivityFeedCard/PopoverContent.tsx @@ -51,7 +51,6 @@ const PopoverContent: FC = ({ onReactionSelect, onPopoverHide, onEdit, - isAnnouncement, }) => { // get current user details const currentUser = useMemo( @@ -69,7 +68,16 @@ const PopoverContent: FC = ({ 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) => { e.stopPropagation(); @@ -146,8 +154,6 @@ const PopoverContent: FC = ({ onEdit && onEdit(); }; - const editCheck = (isAnnouncement || !isThread) && isAuthor; - return (