Added new SYSTEM_WITHHELD comment status

This commit is contained in:
Wyatt Johnson
2017-09-11 11:09:21 -06:00
parent ab1f1dee3e
commit 49f09b87a0
11 changed files with 27 additions and 18 deletions
+2 -4
View File
@@ -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};
@@ -3,7 +3,7 @@ import * as actions from '../constants/userDetail';
const initialState = {
userId: null,
activeTab: 'all',
statuses: ['NONE', 'ACCEPTED', 'REJECTED', 'PREMOD'],
statuses: [],
selectedCommentIds: [],
};
@@ -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);
}
},
@@ -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);
+1 -1
View File
@@ -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'));
}
};
+9 -3
View File
@@ -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';
};
/**
+4
View File
@@ -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.
+1
View File
@@ -2,5 +2,6 @@ module.exports = [
'ACCEPTED',
'REJECTED',
'PREMOD',
'SYSTEM_WITHHELD',
'NONE'
];
@@ -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) {
+4 -2
View File
@@ -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;
}
+1 -1
View File
@@ -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}) => {