feat: removed enable_moderation_reason_codes flag (#615)
* chore: removed deprecated flag fix: resolved linter error fix: changed workflow fix: changed workflow fix: changed workflow fix: changed workflow fix: changed workflow fix: changed workflow fix: changed workflow fix: changed workflow fix: changed workflow fix: changed workflow fix: changed workflow fix: changed workflow * test: fixed postEditor test case --------- Co-authored-by: Awais Ansari <awais.ansari63@gmail.com>
This commit is contained in:
@@ -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)}
|
||||
</Alert>
|
||||
)}
|
||||
{reasonCodesEnabled && canSeeLastEditOrClosedAlert && (
|
||||
{ canSeeLastEditOrClosedAlert && (
|
||||
<>
|
||||
{lastEdit?.reason && (
|
||||
<AlertBar
|
||||
|
||||
@@ -90,7 +90,6 @@ describe.each([
|
||||
store = initializeStore({
|
||||
config: {
|
||||
hasModerationPrivileges: true,
|
||||
reasonCodesEnabled: true,
|
||||
},
|
||||
});
|
||||
const content = buildTestContent(type, props);
|
||||
|
||||
@@ -84,7 +84,6 @@ describe.each([
|
||||
store = initializeStore({
|
||||
config: {
|
||||
hasModerationPrivileges: true,
|
||||
reasonCodesEnabled: true,
|
||||
},
|
||||
});
|
||||
const content = buildTestContent(type, props);
|
||||
|
||||
@@ -30,7 +30,6 @@ import {
|
||||
selectIsCourseStaff,
|
||||
selectIsPostingEnabled,
|
||||
selectLearnersTabEnabled,
|
||||
selectModerationSettings,
|
||||
selectPostThreadCount,
|
||||
selectUserHasModerationPrivileges,
|
||||
selectUserIsGroupTa,
|
||||
@@ -159,13 +158,12 @@ export const useAlertBannerVisible = (
|
||||
) => {
|
||||
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)
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -24,7 +24,6 @@ const configSlice = createSlice({
|
||||
dividedInlineDiscussions: [],
|
||||
dividedCourseWideDiscussions: [],
|
||||
},
|
||||
reasonCodesEnabled: false,
|
||||
editReasons: [],
|
||||
postCloseReasons: [],
|
||||
enableInContext: false,
|
||||
|
||||
@@ -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,34 +404,12 @@ 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 });
|
||||
assertLastUpdateData({ closed: false });
|
||||
});
|
||||
|
||||
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 });
|
||||
},
|
||||
);
|
||||
|
||||
it('should show the editor if the post is edited', async () => {
|
||||
await setupCourseConfig(false);
|
||||
await waitFor(() => renderComponent(discussionPostId));
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user