From 49f09b87a06a1ac42b126ef63d02bde1ef46e3f4 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Mon, 11 Sep 2017 11:09:21 -0600 Subject: [PATCH] Added new SYSTEM_WITHHELD comment status --- client/coral-admin/src/actions/userDetail.js | 6 ++---- client/coral-admin/src/reducers/userDetail.js | 2 +- client/coral-embed-stream/src/containers/Stream.js | 2 +- client/coral-embed-stream/src/graphql/index.js | 4 ++-- client/talk-plugin-commentbox/CommentBox.js | 2 +- graph/mutators/comment.js | 12 +++++++++--- graph/typeDefs.graphql | 4 ++++ models/enum/comment_status.js | 1 + plugins/talk-plugin-toxic-comments/server/hooks.js | 4 +--- services/comments.js | 6 ++++-- test/server/graph/mutations/editComment.js | 2 +- 11 files changed, 27 insertions(+), 18 deletions(-) diff --git a/client/coral-admin/src/actions/userDetail.js b/client/coral-admin/src/actions/userDetail.js index fe9aa2df5..504183f97 100644 --- a/client/coral-admin/src/actions/userDetail.js +++ b/client/coral-admin/src/actions/userDetail.js @@ -4,10 +4,8 @@ export const viewUserDetail = (userId) => ({type: actions.VIEW_USER_DETAIL, user export const hideUserDetail = () => ({type: actions.HIDE_USER_DETAIL}); export const changeUserDetailStatuses = (tab) => { - let statuses; - if (tab === 'all') { - statuses = ['NONE', 'ACCEPTED', 'REJECTED', 'PREMOD']; - } else if (tab === 'rejected') { + let statuses = []; + if (tab === 'rejected') { statuses = ['REJECTED']; } return {type: actions.CHANGE_USER_DETAIL_STATUSES, tab, statuses}; diff --git a/client/coral-admin/src/reducers/userDetail.js b/client/coral-admin/src/reducers/userDetail.js index 8e1d35885..524dcfa31 100644 --- a/client/coral-admin/src/reducers/userDetail.js +++ b/client/coral-admin/src/reducers/userDetail.js @@ -3,7 +3,7 @@ import * as actions from '../constants/userDetail'; const initialState = { userId: null, activeTab: 'all', - statuses: ['NONE', 'ACCEPTED', 'REJECTED', 'PREMOD'], + statuses: [], selectedCommentIds: [], }; diff --git a/client/coral-embed-stream/src/containers/Stream.js b/client/coral-embed-stream/src/containers/Stream.js index 273d39589..0a701a029 100644 --- a/client/coral-embed-stream/src/containers/Stream.js +++ b/client/coral-embed-stream/src/containers/Stream.js @@ -51,7 +51,7 @@ class StreamContainer extends React.Component { return prev; } - if (['PREMOD', 'REJECTED'].includes(commentEdited.status)) { + if (['PREMOD', 'REJECTED', 'SYSTEM_WITHHELD'].includes(commentEdited.status)) { return removeCommentFromEmbedQuery(prev, commentEdited.id); } }, diff --git a/client/coral-embed-stream/src/graphql/index.js b/client/coral-embed-stream/src/graphql/index.js index ad281ce0c..884a9c86a 100644 --- a/client/coral-embed-stream/src/graphql/index.js +++ b/client/coral-embed-stream/src/graphql/index.js @@ -166,7 +166,7 @@ export default { }, updateQueries: { CoralEmbedStream_Embed: (prev, {mutationResult: {data: {createComment: {comment}}}}) => { - if (prev.asset.settings.moderation === 'PRE' || comment.status === 'PREMOD' || comment.status === 'REJECTED') { + if (prev.asset.settings.moderation === 'PRE' || comment.status === 'PREMOD' || comment.status === 'REJECTED' || comment.status === 'SYSTEM_WITHHELD') { return prev; } return insertCommentIntoEmbedQuery(prev, comment); @@ -185,7 +185,7 @@ export default { EditComment: () => ({ updateQueries: { CoralEmbedStream_Embed: (prev, {mutationResult: {data: {editComment: {comment}}}}) => { - if (!['PREMOD', 'REJECTED'].includes(comment.status)) { + if (!['PREMOD', 'REJECTED', 'SYSTEM_WITHHELD'].includes(comment.status)) { return null; } return removeCommentFromEmbedQuery(prev, comment.id); diff --git a/client/talk-plugin-commentbox/CommentBox.js b/client/talk-plugin-commentbox/CommentBox.js index 8bdfb9a24..33b46e245 100644 --- a/client/talk-plugin-commentbox/CommentBox.js +++ b/client/talk-plugin-commentbox/CommentBox.js @@ -16,7 +16,7 @@ export const name = 'talk-plugin-commentbox'; export const notifyForNewCommentStatus = (notify, status) => { if (status === 'REJECTED') { notify('error', t('comment_box.comment_post_banned_word')); - } else if (status === 'PREMOD') { + } else if (status === 'PREMOD' || status === 'SYSTEM_WITHHELD') { notify('success', t('comment_box.comment_post_notif_premod')); } }; diff --git a/graph/mutators/comment.js b/graph/mutators/comment.js index c6e335018..16a736d36 100644 --- a/graph/mutators/comment.js +++ b/graph/mutators/comment.js @@ -239,6 +239,12 @@ const resolveNewCommentStatus = async (context, {asset_id, body, status}, wordli throw errors.ErrCommentTooShort; } + // If the status was already defined, don't redefine it. It's only defined + // when specific external conditions exist, we don't want to override that. + if (status && status.length > 0) { + return status; + } + // Decide the status based on whether or not the current asset/settings // has pre-mod enabled or not. If the comment was rejected based on the // wordlist, then reject it, otherwise if the moderation setting is @@ -248,7 +254,7 @@ const resolveNewCommentStatus = async (context, {asset_id, body, status}, wordli } if (settings.premodLinksEnable && linkify.test(body)) { - return 'PREMOD'; + return 'SYSTEM_WITHHELD'; } let asset = await AssetsService.findById(asset_id); @@ -282,11 +288,11 @@ const resolveNewCommentStatus = async (context, {asset_id, body, status}, wordli // Update the response from the comment creation to add the PREMOD so that // that user's UI will reflect the fact that their comment is in pre-mod. - return 'PREMOD'; + return 'SYSTEM_WITHHELD'; } } - return (moderation === 'PRE' || status === 'PREMOD') ? 'PREMOD' : 'NONE'; + return moderation === 'PRE' ? 'PREMOD' : 'NONE'; }; /** diff --git a/graph/typeDefs.graphql b/graph/typeDefs.graphql index 916c0ade5..0ffb6e755 100644 --- a/graph/typeDefs.graphql +++ b/graph/typeDefs.graphql @@ -242,6 +242,10 @@ enum COMMENT_STATUS { # new comments that haven't been moderated yet are referred to as # "premoderated" or "premod" comments. PREMOD + + # SYSTEM_WITHHELD represents a comment that was withheld by the system because + # it was flagged by an internal process for further review. + SYSTEM_WITHHELD } # The types of action there are as enums. diff --git a/models/enum/comment_status.js b/models/enum/comment_status.js index 64633e9de..a0648f72e 100644 --- a/models/enum/comment_status.js +++ b/models/enum/comment_status.js @@ -2,5 +2,6 @@ module.exports = [ 'ACCEPTED', 'REJECTED', 'PREMOD', + 'SYSTEM_WITHHELD', 'NONE' ]; diff --git a/plugins/talk-plugin-toxic-comments/server/hooks.js b/plugins/talk-plugin-toxic-comments/server/hooks.js index 7fd138641..931ca0f60 100644 --- a/plugins/talk-plugin-toxic-comments/server/hooks.js +++ b/plugins/talk-plugin-toxic-comments/server/hooks.js @@ -37,9 +37,7 @@ module.exports = { }); if (commentIsToxic) { - - // TODO: this should have a different status than Premod. - input.status = 'PREMOD'; + input.status = 'SYSTEM_WITHHELD'; } }, async post(_, _input, _context, _info, result) { diff --git a/services/comments.js b/services/comments.js index 82914bcd0..ec55cfb4d 100644 --- a/services/comments.js +++ b/services/comments.js @@ -81,11 +81,13 @@ module.exports = class CommentsService { * @param {String} status the new Comment status */ static async edit({id, author_id, body, status}) { + const EDITABLE_STATUSES = ['NONE', 'PREMOD', 'ACCEPTED']; + const query = { id, author_id, status: { - $in: ['NONE', 'PREMOD', 'ACCEPTED'], + $in: EDITABLE_STATUSES, }, }; @@ -130,7 +132,7 @@ module.exports = class CommentsService { } // Check to see if the comment had a status that was editable. - if (!['NONE', 'PREMOD', 'ACCEPTED'].includes(comment.status)) { + if (!EDITABLE_STATUSES.includes(comment.status)) { debug('rejecting comment edit because original comment has a non-editable status'); throw errors.ErrNotAuthorized; } diff --git a/test/server/graph/mutations/editComment.js b/test/server/graph/mutations/editComment.js index 8507fdc36..234bb308e 100644 --- a/test/server/graph/mutations/editComment.js +++ b/test/server/graph/mutations/editComment.js @@ -215,7 +215,7 @@ describe('graph.mutations.editComment', () => { body: 'I have been edited to add a link: https://coralproject.net/' }, afterEdit: { - status: 'PREMOD', + status: 'SYSTEM_WITHHELD', }, }, ].forEach(({description, settings, beforeEdit, edit, afterEdit, error}) => {