From 55b85d92d6a7cd056009618c32ef98ff737b7de4 Mon Sep 17 00:00:00 2001 From: Farhaan Bukhsh Date: Wed, 23 Oct 2024 17:56:11 +0530 Subject: [PATCH] fix: Adds a fix to remove "Add a post" button when discussion is restricted "Add a post" button was visible even though the banner says that posting is restricted. This change helps in removing the button when posting is restricted. Signed-off-by: Farhaan Bukhsh --- src/discussions/data/hooks.js | 8 +------- src/discussions/data/hooks.test.jsx | 8 ++++---- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/discussions/data/hooks.js b/src/discussions/data/hooks.js index 6de5e1f0f..f4deb82a2 100644 --- a/src/discussions/data/hooks.js +++ b/src/discussions/data/hooks.js @@ -33,14 +33,11 @@ import { ContentSelectors } from './constants'; import { selectAreThreadsFiltered, selectEnableInContext, - selectIsCourseAdmin, - selectIsCourseStaff, selectIsPostingEnabled, selectIsUserLearner, selectPostThreadCount, selectUserHasModerationPrivileges, selectUserIsGroupTa, - selectUserIsStaff, } from './selectors'; import fetchCourseConfig from './thunks'; @@ -220,12 +217,9 @@ export const useCurrentDiscussionTopic = () => { export const useUserPostingEnabled = () => { const isPostingEnabled = useSelector(selectIsPostingEnabled); - const isUserAdmin = useSelector(selectUserIsStaff); const userHasModerationPrivileges = useSelector(selectUserHasModerationPrivileges); const isUserGroupTA = useSelector(selectUserIsGroupTa); - const isCourseAdmin = useSelector(selectIsCourseAdmin); - const isCourseStaff = useSelector(selectIsCourseStaff); - const isPrivileged = isUserAdmin || userHasModerationPrivileges || isUserGroupTA || isCourseAdmin || isCourseStaff; + const isPrivileged = userHasModerationPrivileges || isUserGroupTA; return (isPostingEnabled || isPrivileged); }; diff --git a/src/discussions/data/hooks.test.jsx b/src/discussions/data/hooks.test.jsx index ca58ebe82..e5648ce7e 100644 --- a/src/discussions/data/hooks.test.jsx +++ b/src/discussions/data/hooks.test.jsx @@ -19,11 +19,11 @@ const courseConfigApiUrl = getCourseConfigApiUrl(); let store; let axiosMock; -const generateApiResponse = (isPostingEnabled, isCourseAdmin = false) => ({ +const generateApiResponse = (isPostingEnabled, hasModerationPrivileges = false) => ({ isPostingEnabled, - hasModerationPrivileges: false, + hasModerationPrivileges, isGroupTa: false, - isCourseAdmin, + isCourseAdmin: false, isCourseStaff: false, isUserAdmin: false, }); @@ -160,7 +160,7 @@ describe('Hooks', () => { expect(queryByText('false')).toBeInTheDocument(); }); - test('when posting is not disabled and Role is not Learner return true', async () => { + test('when posting is disabled and Role is not Learner return true', async () => { axiosMock.onGet(`${courseConfigApiUrl}${courseId}/`) .reply(200, generateApiResponse(false, true)); await executeThunk(fetchCourseConfig(courseId), store.dispatch, store.getState);