From cb88f0a9b79c91d2e0fb3b1a82f18d7046002e1a Mon Sep 17 00:00:00 2001 From: David Jay Date: Fri, 3 Mar 2017 14:32:57 -0500 Subject: [PATCH] Flagging links when settings are set appropriately. --- .../containers/ConfigureStreamContainer.js | 4 ++-- graph/mutators/comment.js | 24 +++++++++++++++---- graph/typeDefs.graphql | 1 + models/setting.js | 4 ++++ 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/client/coral-configure/containers/ConfigureStreamContainer.js b/client/coral-configure/containers/ConfigureStreamContainer.js index 35942288e..a621f0cbd 100644 --- a/client/coral-configure/containers/ConfigureStreamContainer.js +++ b/client/coral-configure/containers/ConfigureStreamContainer.js @@ -31,14 +31,14 @@ class ConfigureStreamContainer extends Component { const questionBoxEnable = elements.qboxenable.checked; const questionBoxContent = elements.qboxcontent.value; - const premodLinks = elements.premodLinks.checked; + const premodLinksEnable = elements.premodLinks.checked; const {changed} = this.state; const newConfig = { moderation: premod ? 'PRE' : 'POST', questionBoxEnable, questionBoxContent, - premodLinks + premodLinksEnable }; if (changed) { diff --git a/graph/mutators/comment.js b/graph/mutators/comment.js index d608eee57..73510d67a 100644 --- a/graph/mutators/comment.js +++ b/graph/mutators/comment.js @@ -54,13 +54,16 @@ const createComment = ({user, loaders: {Comments}}, {body, asset_id, parent_id = * @param {String} body body of a comment * @return {Object} resolves to the wordlist results */ -const filterNewComment = (context, {body}) => { +const filterNewComment = (context, {body, asset_id}) => { // Create a new instance of the Wordlist. const wl = new Wordlist(); // Load the wordlist and filter the comment content. - return wl.load().then(() => wl.scan('body', body)); + return Promise.all([ + wl.load().then(() => wl.scan('body', body)), + AssetsService.rectifySettings(AssetsService.findById(asset_id)) + ]); }; /** @@ -131,13 +134,13 @@ const createPublicComment = (context, commentInput) => { // We then take the wordlist and the comment into consideration when // considering what status to assign the new comment, and resolve the new // status to set the comment to. - .then((wordlist) => resolveNewCommentStatus(context, commentInput, wordlist) + .then(([wordlist, settings]) => resolveNewCommentStatus(context, commentInput, wordlist) // Then we actually create the comment with the new status. .then((status) => createComment(context, commentInput, status)) .then((comment) => { - // If the comment was flagged as being suspect, we need to add a + // If the comment has a suspect word or a link, we need to add a // flag to it to indicate that it needs to be looked at. // Otherwise just return the new comment. @@ -158,6 +161,19 @@ const createPublicComment = (context, commentInput) => { .then(() => comment); } + // If the comment contains a link. + if (settings.premodLinksEnable && /\S+\.\S+/.exec(comment.body)) { + return ActionsService.insertUserAction({ + item_id: comment.id, + item_type: 'COMMENTS', + action_type: 'FLAG', + user_id: null, + group_id: 'Contains link', + metadata: {} + }) + .then(() => comment); + } + // Finally, we return the comment. return comment; })); diff --git a/graph/typeDefs.graphql b/graph/typeDefs.graphql index 92f0d41e2..2777e7bdb 100644 --- a/graph/typeDefs.graphql +++ b/graph/typeDefs.graphql @@ -370,6 +370,7 @@ type Settings { infoBoxEnable: Boolean infoBoxContent: String + premodLinksEnable: Boolean questionBoxEnable: Boolean questionBoxContent: String closeTimeout: Int diff --git a/models/setting.js b/models/setting.js index 993384ff1..ac54584a4 100644 --- a/models/setting.js +++ b/models/setting.js @@ -40,6 +40,10 @@ const SettingSchema = new Schema({ type: String, default: '' }, + premodLinksEnable: { + type: Boolean, + default: false + }, organizationName: { type: String },