diff --git a/src/discussions/common/AlertBanner.jsx b/src/discussions/common/AlertBanner.jsx index 474fb701d..e66f7ae92 100644 --- a/src/discussions/common/AlertBanner.jsx +++ b/src/discussions/common/AlertBanner.jsx @@ -10,7 +10,7 @@ import { Report } from '@edx/paragon/icons'; import { AvatarOutlineAndLabelColors } from '../../data/constants'; import { - selectModerationSettings, selectUserHasModerationPrivileges, selectUserIsGroupTa, selectUserIsStaff, + selectUserHasModerationPrivileges, selectUserIsGroupTa, selectUserIsStaff, } from '../data/selectors'; import messages from '../post-comments/messages'; import AlertBar from './AlertBar'; @@ -29,7 +29,6 @@ const AlertBanner = ({ const userHasModerationPrivileges = useSelector(selectUserHasModerationPrivileges); const userIsGroupTa = useSelector(selectUserIsGroupTa); const userIsGlobalStaff = useSelector(selectUserIsStaff); - const { reasonCodesEnabled } = useSelector(selectModerationSettings); const userIsContentAuthor = getAuthenticatedUser().username === author; const canSeeReportedBanner = abuseFlagged; const canSeeLastEditOrClosedAlert = (userHasModerationPrivileges || userIsGroupTa @@ -45,7 +44,7 @@ const AlertBanner = ({ {intl.formatMessage(messages.abuseFlaggedMessage)} )} - {reasonCodesEnabled && canSeeLastEditOrClosedAlert && ( + { canSeeLastEditOrClosedAlert && ( <> {lastEdit?.reason && ( { const userHasModerationPrivileges = useSelector(selectUserHasModerationPrivileges); const userIsGroupTa = useSelector(selectUserIsGroupTa); - const { reasonCodesEnabled } = useSelector(selectModerationSettings); const userIsContentAuthor = getAuthenticatedUser().username === author; const canSeeLastEditOrClosedAlert = (userHasModerationPrivileges || userIsContentAuthor || userIsGroupTa); const canSeeReportedBanner = abuseFlagged; return ( - (reasonCodesEnabled && canSeeLastEditOrClosedAlert && (lastEdit?.reason || closed)) || (canSeeReportedBanner) + (canSeeLastEditOrClosedAlert && (lastEdit?.reason || closed)) || (canSeeReportedBanner) ); }; diff --git a/src/discussions/data/selectors.js b/src/discussions/data/selectors.js index b6c9b2e20..0689967e8 100644 --- a/src/discussions/data/selectors.js +++ b/src/discussions/data/selectors.js @@ -33,7 +33,6 @@ export const selectIsPostingEnabled = state => state.config.isPostingEnabled; export const selectModerationSettings = state => ({ postCloseReasons: state.config.postCloseReasons, editReasons: state.config.editReasons, - reasonCodesEnabled: state.config.reasonCodesEnabled, }); export const selectDiscussionProvider = state => state.config.provider; diff --git a/src/discussions/data/slices.js b/src/discussions/data/slices.js index 05f47d3f7..1b8c488ec 100644 --- a/src/discussions/data/slices.js +++ b/src/discussions/data/slices.js @@ -24,7 +24,6 @@ const configSlice = createSlice({ dividedInlineDiscussions: [], dividedCourseWideDiscussions: [], }, - reasonCodesEnabled: false, editReasons: [], postCloseReasons: [], enableInContext: false, diff --git a/src/discussions/post-comments/PostCommentsView.test.jsx b/src/discussions/post-comments/PostCommentsView.test.jsx index 984d3683b..cda492919 100644 --- a/src/discussions/post-comments/PostCommentsView.test.jsx +++ b/src/discussions/post-comments/PostCommentsView.test.jsx @@ -89,11 +89,10 @@ async function getThreadAPIResponse(attr = null) { await executeThunk(fetchThread(discussionPostId), store.dispatch, store.getState); } -async function setupCourseConfig(reasonCodesEnabled = true) { +async function setupCourseConfig() { axiosMock.onGet(`${courseConfigApiUrl}${courseId}/`).reply(200, { has_moderation_privileges: true, isPostingEnabled: true, - reason_codes_enabled: reasonCodesEnabled, editReasons: [ { code: 'reason-1', label: 'reason 1' }, { code: 'reason-2', label: 'reason 2' }, @@ -392,12 +391,12 @@ describe('ThreadView', () => { assertLastUpdateData({ edit_reason_code: 'reason-1' }); }); - it('should close the post directly if reason codes are not enabled', async () => { - await setupCourseConfig(false); - await waitFor(() => renderComponent(discussionPostId)); + it('should reopen the post', async () => { + await setupCourseConfig(); + renderComponent(closedPostId); - const post = await screen.findByTestId('post-thread-1'); - const hoverCard = within(post).getByTestId('hover-card-thread-1'); + const post = screen.getByTestId('post-thread-2'); + const hoverCard = within(post).getByTestId('hover-card-thread-2'); await act(async () => { fireEvent.click( within(hoverCard).getByRole('button', { name: /actions menu/i }), @@ -405,33 +404,11 @@ describe('ThreadView', () => { }); expect(screen.queryByRole('dialog', { name: /close post/i })).not.toBeInTheDocument(); await act(async () => { - fireEvent.click(screen.getByRole('button', { name: /close/i })); + fireEvent.click(screen.getByRole('button', { name: /reopen/i })); }); expect(screen.queryByRole('dialog', { name: /close post/i })).not.toBeInTheDocument(); - assertLastUpdateData({ closed: true }); - }); - - it.each([true, false])( - 'should reopen the post directly when reason codes enabled=%s', - async (reasonCodesEnabled) => { - await setupCourseConfig(reasonCodesEnabled); - renderComponent(closedPostId); - - const post = screen.getByTestId('post-thread-2'); - const hoverCard = within(post).getByTestId('hover-card-thread-2'); - await act(async () => { - fireEvent.click( - within(hoverCard).getByRole('button', { name: /actions menu/i }), - ); - }); - expect(screen.queryByRole('dialog', { name: /close post/i })).not.toBeInTheDocument(); - await act(async () => { - fireEvent.click(screen.getByRole('button', { name: /reopen/i })); - }); - expect(screen.queryByRole('dialog', { name: /close post/i })).not.toBeInTheDocument(); - assertLastUpdateData({ closed: false }); - }, - ); + assertLastUpdateData({ closed: false }); + }); it('should show the editor if the post is edited', async () => { await setupCourseConfig(false); diff --git a/src/discussions/post-comments/comments/comment/CommentEditor.jsx b/src/discussions/post-comments/comments/comment/CommentEditor.jsx index 256be0157..c0a0ed73b 100644 --- a/src/discussions/post-comments/comments/comment/CommentEditor.jsx +++ b/src/discussions/post-comments/comments/comment/CommentEditor.jsx @@ -40,10 +40,10 @@ const CommentEditor = ({ const userHasModerationPrivileges = useSelector(selectUserHasModerationPrivileges); const userIsGroupTa = useSelector(selectUserIsGroupTa); const userIsStaff = useSelector(selectUserIsStaff); - const { reasonCodesEnabled, editReasons } = useSelector(selectModerationSettings); + const { editReasons } = useSelector(selectModerationSettings); const [submitting, dispatch] = useDispatchWithState(); - const canDisplayEditReason = (reasonCodesEnabled && edit + const canDisplayEditReason = (edit && (userHasModerationPrivileges || userIsGroupTa || userIsStaff) && author !== authenticatedUser.username ); diff --git a/src/discussions/posts/post-editor/PostEditor.jsx b/src/discussions/posts/post-editor/PostEditor.jsx index 5231dac2e..8a15ca8aa 100644 --- a/src/discussions/posts/post-editor/PostEditor.jsx +++ b/src/discussions/posts/post-editor/PostEditor.jsx @@ -75,12 +75,12 @@ const PostEditor = ({ const userIsGroupTa = useSelector(selectUserIsGroupTa); const settings = useSelector(selectDivisionSettings); const { allowAnonymous, allowAnonymousToPeers } = useSelector(selectAnonymousPostingConfig); - const { reasonCodesEnabled, editReasons } = useSelector(selectModerationSettings); + const { editReasons } = useSelector(selectModerationSettings); const userIsStaff = useSelector(selectUserIsStaff); const archivedTopics = useSelector(selectArchivedTopics); const postEditorId = `post-editor-${editExisting ? postId : 'new'}`; - const canDisplayEditReason = (reasonCodesEnabled && editExisting + const canDisplayEditReason = (editExisting && (userHasModerationPrivileges || userIsGroupTa || userIsStaff) && post?.author !== authenticatedUser.username ); diff --git a/src/discussions/posts/post-editor/PostEditor.test.jsx b/src/discussions/posts/post-editor/PostEditor.test.jsx index 1c8bda181..49a15693d 100644 --- a/src/discussions/posts/post-editor/PostEditor.test.jsx +++ b/src/discussions/posts/post-editor/PostEditor.test.jsx @@ -266,7 +266,18 @@ describe('PostEditor', () => { test('cancel posting of existing post', async () => { const threadId = 'thread-1'; - await setupData(); + await setupData({ + editReasons: [ + { + code: 'reason-1', + label: 'Reason 1', + }, + { + code: 'reason-2', + label: 'Reason 2', + }, + ], + }); await act(async () => { axiosMock.onGet(`${threadsApiUrl}${threadId}/`).reply(200, Factory.build('thread')); await executeThunk(fetchThread(threadId), store.dispatch, store.getState); @@ -292,7 +303,6 @@ describe('PostEditor', () => { config: { provider: 'legacy', hasModerationPrivileges: true, - reasonCodesEnabled: true, editReasons: [ { code: 'reason-1', diff --git a/src/discussions/posts/post/Post.jsx b/src/discussions/posts/post/Post.jsx index 1f7ee1f92..7ec90218b 100644 --- a/src/discussions/posts/post/Post.jsx +++ b/src/discussions/posts/post/Post.jsx @@ -17,7 +17,7 @@ import { AlertBanner, Confirmation } from '../../common'; import { DiscussionContext } from '../../common/context'; import HoverCard from '../../common/HoverCard'; import { ContentTypes } from '../../data/constants'; -import { selectModerationSettings, selectUserHasModerationPrivileges } from '../../data/selectors'; +import { selectUserHasModerationPrivileges } from '../../data/selectors'; import { selectTopic } from '../../topics/data/selectors'; import { selectThread } from '../data/selectors'; import { removeThread, updateExistingThread } from '../data/thunks'; @@ -41,7 +41,6 @@ const Post = ({ handleAddResponseButton }) => { const topic = useSelector(selectTopic(topicId)); const getTopicSubsection = useSelector(selectorForUnitSubsection); const topicContext = useSelector(selectTopicContext(topicId)); - const { reasonCodesEnabled } = useSelector(selectModerationSettings); const [isDeleting, showDeleteConfirmation, hideDeleteConfirmation] = useToggle(false); const [isReporting, showReportConfirmation, hideReportConfirmation] = useToggle(false); const [isClosing, showClosePostModal, hideClosePostModal] = useToggle(false); @@ -70,12 +69,10 @@ const Post = ({ handleAddResponseButton }) => { const handlePostClose = useCallback(() => { if (closed) { dispatch(updateExistingThread(postId, { closed: false })); - } else if (reasonCodesEnabled) { - showClosePostModal(); } else { - dispatch(updateExistingThread(postId, { closed: true })); + showClosePostModal(); } - }, [closed, postId, reasonCodesEnabled, showClosePostModal]); + }, [closed, postId, showClosePostModal]); const handlePostCopyLink = useCallback(() => { const postURL = new URL(`${getConfig().PUBLIC_PATH}${courseId}/posts/${postId}`, window.location.origin);