Skip to content

Commit

Permalink
feat: remove new library button if user does not have create access (#61
Browse files Browse the repository at this point in the history
)

(cherry picked from commit a9a4d93)
  • Loading branch information
kaustavb12 authored Aug 31, 2024
1 parent 9719b2a commit d4f6606
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/studio-home/StudioHome.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const StudioHome = ({ intl }) => {
studioRequestEmail,
libraryAuthoringMfeUrl,
redirectToLibraryAuthoringMfe,
showNewLibraryButton,
} = studioHomeData;

function getHeaderButtons() {
Expand Down Expand Up @@ -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(
<Button
variant="outline-primary"
iconBefore={AddIcon}
size="sm"
disabled={showNewCourseContainer}
href={libraryHref}
data-testid="new-library-button"
>
{intl.formatMessage(messages.addNewLibraryBtnText)}
</Button>,
);
headerButtons.push(
<Button
variant="outline-primary"
iconBefore={AddIcon}
size="sm"
disabled={showNewCourseContainer}
href={libraryHref}
data-testid="new-library-button"
>
{intl.formatMessage(messages.addNewLibraryBtnText)}
</Button>,
);
}

return headerButtons;
}
Expand Down
9 changes: 9 additions & 0 deletions src/studio-home/StudioHome.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ describe('<StudioHome />', async () => {
});
});

it('do not render new library button if showNewLibraryButton is False', () => {
useSelector.mockReturnValue({
...studioHomeMock,
showNewLibraryButton: false,
});
const { queryByTestId } = render(<RootWrapper />);
expect(queryByTestId('new-library-button')).not.toBeInTheDocument();
});

it('should render create new course container', async () => {
useSelector.mockReturnValue({
...studioHomeMock,
Expand Down

0 comments on commit d4f6606

Please sign in to comment.