From fa62cc0238dc19c625443144d63f3eff1f927d72 Mon Sep 17 00:00:00 2001 From: Kaustav Banerjee Date: Wed, 14 Aug 2024 18:38:51 +0530 Subject: [PATCH] feat: remove new library button if user does not have create access (cherry picked from commit a9a4d9327ca96b4a0c43dcb2adeac0d0d84da503) --- src/studio-home/StudioHome.jsx | 35 ++++++++++++++++------------- src/studio-home/StudioHome.test.jsx | 9 ++++++++ 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/studio-home/StudioHome.jsx b/src/studio-home/StudioHome.jsx index 8348aaca34..45d7c8fb05 100644 --- a/src/studio-home/StudioHome.jsx +++ b/src/studio-home/StudioHome.jsx @@ -49,6 +49,7 @@ const StudioHome = ({ intl }) => { studioRequestEmail, libraryAuthoringMfeUrl, redirectToLibraryAuthoringMfe, + showNewLibraryButton, } = studioHomeData; function getHeaderButtons() { @@ -78,23 +79,25 @@ const StudioHome = ({ intl }) => { ); } - let libraryHref = `${getConfig().STUDIO_BASE_URL}/home_library`; - if (redirectToLibraryAuthoringMfe) { - libraryHref = `${libraryAuthoringMfeUrl}/create`; - } + if (showNewLibraryButton) { + let libraryHref = `${getConfig().STUDIO_BASE_URL}/home_library`; + if (redirectToLibraryAuthoringMfe) { + libraryHref = `${libraryAuthoringMfeUrl}/create`; + } - headerButtons.push( - , - ); + headerButtons.push( + , + ); + } return headerButtons; } diff --git a/src/studio-home/StudioHome.test.jsx b/src/studio-home/StudioHome.test.jsx index 8385c6d9b1..ad02f4373f 100644 --- a/src/studio-home/StudioHome.test.jsx +++ b/src/studio-home/StudioHome.test.jsx @@ -171,6 +171,15 @@ describe('', async () => { }); }); + it('do not render new library button if showNewLibraryButton is False', () => { + useSelector.mockReturnValue({ + ...studioHomeMock, + showNewLibraryButton: false, + }); + const { queryByTestId } = render(); + expect(queryByTestId('new-library-button')).not.toBeInTheDocument(); + }); + it('should render create new course container', async () => { useSelector.mockReturnValue({ ...studioHomeMock,