fix: show studio button if user has access (#1452)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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(<InstructorToolbar {...data} />);
|
||||
|
||||
const linksContainer = screen.getByText('View course in:').parentElement;
|
||||
expect(screen.queryByText(linksContainer, 'Studio')).toBeNull();
|
||||
expect(getByText(linksContainer, 'Insights').getAttribute('href')).toMatch(/http.*/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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}
|
||||
/>
|
||||
)}
|
||||
<StreakModal
|
||||
|
||||
Reference in New Issue
Block a user