From 82b27e59ccfcb201c6f25bf6f4f0d61e05d02275 Mon Sep 17 00:00:00 2001
From: Kristin Aoki <42981026+KristinAoki@users.noreply.github.com>
Date: Mon, 9 Sep 2024 09:11:56 -0400
Subject: [PATCH] fix: show studio button if user has access (#1452)
---
src/instructor-toolbar/InstructorToolbar.jsx | 9 ++++++---
src/instructor-toolbar/InstructorToolbar.test.jsx | 13 +++++++++++++
src/tab-page/LoadedTabPage.jsx | 2 ++
3 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/src/instructor-toolbar/InstructorToolbar.jsx b/src/instructor-toolbar/InstructorToolbar.jsx
index 71d968c869..83a0538f57 100644
--- a/src/instructor-toolbar/InstructorToolbar.jsx
+++ b/src/instructor-toolbar/InstructorToolbar.jsx
@@ -23,10 +23,10 @@ function getInsightsUrl(courseId) {
return urlFull;
}
-function getStudioUrl(courseId, unitId) {
+function getStudioUrl(courseId, unitId, hasStudioAccess) {
const urlBase = getConfig().STUDIO_BASE_URL;
let urlFull;
- if (urlBase) {
+ if (urlBase && hasStudioAccess) {
if (unitId) {
urlFull = `${urlBase}/container/${unitId}`;
} else if (courseId) {
@@ -56,10 +56,11 @@ const InstructorToolbar = (props) => {
courseId,
unitId,
tab,
+ hasStudioAccess,
} = props;
const urlInsights = getInsightsUrl(courseId);
- const urlStudio = getStudioUrl(courseId, unitId);
+ const urlStudio = getStudioUrl(courseId, unitId, hasStudioAccess);
const [masqueradeErrorMessage, showMasqueradeError] = useState(null);
const accessExpirationMasqueradeBanner = useAccessExpirationMasqueradeBanner(courseId, tab);
@@ -115,12 +116,14 @@ InstructorToolbar.propTypes = {
courseId: PropTypes.string,
unitId: PropTypes.string,
tab: PropTypes.string,
+ hasStudioAccess: PropTypes.bool,
};
InstructorToolbar.defaultProps = {
courseId: undefined,
unitId: undefined,
tab: '',
+ hasStudioAccess: false,
};
export default InstructorToolbar;
diff --git a/src/instructor-toolbar/InstructorToolbar.test.jsx b/src/instructor-toolbar/InstructorToolbar.test.jsx
index f74c751b0f..d586671cd1 100644
--- a/src/instructor-toolbar/InstructorToolbar.test.jsx
+++ b/src/instructor-toolbar/InstructorToolbar.test.jsx
@@ -34,6 +34,7 @@ describe('Instructor Toolbar', () => {
mockData = {
courseId: courseware.courseId,
unitId: Object.values(models.units)[0].id,
+ hasStudioAccess: true,
};
axiosMock.reset();
axiosMock.onGet(masqueradeUrl).reply(200, { success: true });
@@ -76,4 +77,16 @@ describe('Instructor Toolbar', () => {
expect(screen.queryByText('View course in:')).not.toBeInTheDocument();
});
+
+ it('does not display Studio link if user does not have studio access', () => {
+ const config = { ...originalConfig };
+ const data = { ...mockData, hasStudioAccess: false };
+ config.INSIGHTS_BASE_URL = 'http://localhost:18100';
+ getConfig.mockImplementation(() => config);
+ render();
+
+ const linksContainer = screen.getByText('View course in:').parentElement;
+ expect(screen.queryByText(linksContainer, 'Studio')).toBeNull();
+ expect(getByText(linksContainer, 'Insights').getAttribute('href')).toMatch(/http.*/);
+ });
});
diff --git a/src/tab-page/LoadedTabPage.jsx b/src/tab-page/LoadedTabPage.jsx
index 0259aa1bfd..5684844c8a 100644
--- a/src/tab-page/LoadedTabPage.jsx
+++ b/src/tab-page/LoadedTabPage.jsx
@@ -26,6 +26,7 @@ const LoadedTabPage = ({
celebrations,
org,
originalUserIsStaff,
+ studioAccess,
tabs,
title,
verifiedMode,
@@ -58,6 +59,7 @@ const LoadedTabPage = ({
courseId={courseId}
unitId={unitId}
tab={activeTabSlug}
+ hasStudioAccess={studioAccess}
/>
)}