Skip to content

Commit 3cc39d8

Browse files
fix: Adds a fix to remove "Add a post" button when discussion is restricted (#742)
"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 <[email protected]>
1 parent af6cd18 commit 3cc39d8

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

src/discussions/data/hooks.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,11 @@ import { ContentSelectors } from './constants';
3333
import {
3434
selectAreThreadsFiltered,
3535
selectEnableInContext,
36-
selectIsCourseAdmin,
37-
selectIsCourseStaff,
3836
selectIsPostingEnabled,
3937
selectIsUserLearner,
4038
selectPostThreadCount,
4139
selectUserHasModerationPrivileges,
4240
selectUserIsGroupTa,
43-
selectUserIsStaff,
4441
} from './selectors';
4542
import fetchCourseConfig from './thunks';
4643

@@ -220,12 +217,9 @@ export const useCurrentDiscussionTopic = () => {
220217

221218
export const useUserPostingEnabled = () => {
222219
const isPostingEnabled = useSelector(selectIsPostingEnabled);
223-
const isUserAdmin = useSelector(selectUserIsStaff);
224220
const userHasModerationPrivileges = useSelector(selectUserHasModerationPrivileges);
225221
const isUserGroupTA = useSelector(selectUserIsGroupTa);
226-
const isCourseAdmin = useSelector(selectIsCourseAdmin);
227-
const isCourseStaff = useSelector(selectIsCourseStaff);
228-
const isPrivileged = isUserAdmin || userHasModerationPrivileges || isUserGroupTA || isCourseAdmin || isCourseStaff;
222+
const isPrivileged = userHasModerationPrivileges || isUserGroupTA;
229223

230224
return (isPostingEnabled || isPrivileged);
231225
};

src/discussions/data/hooks.test.jsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ const courseConfigApiUrl = getCourseConfigApiUrl();
1919
let store;
2020
let axiosMock;
2121

22-
const generateApiResponse = (isPostingEnabled, isCourseAdmin = false) => ({
22+
const generateApiResponse = (isPostingEnabled, hasModerationPrivileges = false) => ({
2323
isPostingEnabled,
24-
hasModerationPrivileges: false,
24+
hasModerationPrivileges,
2525
isGroupTa: false,
26-
isCourseAdmin,
26+
isCourseAdmin: false,
2727
isCourseStaff: false,
2828
isUserAdmin: false,
2929
});
@@ -160,7 +160,7 @@ describe('Hooks', () => {
160160
expect(queryByText('false')).toBeInTheDocument();
161161
});
162162

163-
test('when posting is not disabled and Role is not Learner return true', async () => {
163+
test('when posting is disabled and Role is not Learner return true', async () => {
164164
axiosMock.onGet(`${courseConfigApiUrl}${courseId}/`)
165165
.reply(200, generateApiResponse(false, true));
166166
await executeThunk(fetchCourseConfig(courseId), store.dispatch, store.getState);

0 commit comments

Comments
 (0)