fix: fixed api calling issues for admin (#691)
* fix: fixed api calling issues for admin * test: fixed test case * refactor: fixed review issue --------- Co-authored-by: Awais Ansari <79941147+awais-ansari@users.noreply.github.com>
This commit is contained in:
@@ -13,6 +13,8 @@ import { getAuthenticatedUser } from '@edx/frontend-platform/auth';
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
import { AppContext } from '@edx/frontend-platform/react';
|
||||
|
||||
import selectCourseTabs from '../../components/NavigationBar/data/selectors';
|
||||
import { LOADED } from '../../components/NavigationBar/data/slice';
|
||||
import fetchTab from '../../components/NavigationBar/data/thunks';
|
||||
import { RequestStatus, Routes } from '../../data/constants';
|
||||
import { selectTopicsUnderCategory } from '../../data/selectors';
|
||||
@@ -32,6 +34,7 @@ import {
|
||||
selectIsCourseAdmin,
|
||||
selectIsCourseStaff,
|
||||
selectIsPostingEnabled,
|
||||
selectIsUserLearner,
|
||||
selectPostThreadCount,
|
||||
selectUserHasModerationPrivileges,
|
||||
selectUserIsGroupTa,
|
||||
@@ -72,22 +75,34 @@ export const useSidebarVisible = () => {
|
||||
return !hideSidebar;
|
||||
};
|
||||
|
||||
export function useCourseDiscussionData(courseId, isEnrolled) {
|
||||
export function useCourseDiscussionData(courseId) {
|
||||
const dispatch = useDispatch();
|
||||
const { authenticatedUser } = useContext(AppContext);
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchBaseData() {
|
||||
if (isEnrolled) {
|
||||
await dispatch(fetchCourseConfig(courseId));
|
||||
await dispatch(fetchCourseConfig(courseId));
|
||||
await dispatch(fetchTab(courseId));
|
||||
}
|
||||
|
||||
fetchBaseData();
|
||||
}, [courseId]);
|
||||
}
|
||||
|
||||
export function useCourseBlockData(courseId) {
|
||||
const dispatch = useDispatch();
|
||||
const { authenticatedUser } = useContext(AppContext);
|
||||
const { isEnrolled, courseStatus } = useSelector(selectCourseTabs);
|
||||
const isUserLearner = useSelector(selectIsUserLearner);
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchBaseData() {
|
||||
if (courseStatus === LOADED && (!isUserLearner || isEnrolled)) {
|
||||
await dispatch(fetchCourseBlocks(courseId, authenticatedUser.username));
|
||||
} else {
|
||||
await dispatch(fetchTab(courseId));
|
||||
}
|
||||
}
|
||||
|
||||
fetchBaseData();
|
||||
}, [courseId, isEnrolled]);
|
||||
}, [courseId, isEnrolled, courseStatus, isUserLearner]);
|
||||
}
|
||||
|
||||
export function useRedirectToThread(courseId, enableInContextSidebar) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { createSelector } from '@reduxjs/toolkit';
|
||||
|
||||
import selectCourseTabs from '../../components/NavigationBar/data/selectors';
|
||||
import { LOADED } from '../../components/NavigationBar/data/slice';
|
||||
import { PostsStatusFilter, ThreadType } from '../../data/constants';
|
||||
import { isCourseStatusValid } from '../utils';
|
||||
|
||||
export const selectAnonymousPostingConfig = state => ({
|
||||
allowAnonymous: state.config.allowAnonymous,
|
||||
@@ -86,7 +86,7 @@ export const selectIsUserLearner = createSelector(
|
||||
&& !userIsStaff
|
||||
&& !userIsCourseAdmin
|
||||
&& !userIsCourseStaff
|
||||
&& courseStatus === LOADED
|
||||
&& isCourseStatusValid(courseStatus)
|
||||
) || false
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user