From b92ea72b789d8e120d33691050da9f0452fabc82 Mon Sep 17 00:00:00 2001 From: David Jay Date: Thu, 2 Mar 2017 16:44:36 -0500 Subject: [PATCH 1/7] Re-enabling premod links in settings. --- .../components/ConfigureCommentStream.js | 12 ++++++++++++ .../containers/ConfigureStreamContainer.js | 18 +++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/client/coral-configure/components/ConfigureCommentStream.js b/client/coral-configure/components/ConfigureCommentStream.js index d80e487de..348d26f53 100644 --- a/client/coral-configure/components/ConfigureCommentStream.js +++ b/client/coral-configure/components/ConfigureCommentStream.js @@ -34,6 +34,18 @@ export default ({handleChange, handleApply, changed, updateQuestionBoxContent, . description: lang.t('configureCommentStream.enablePremodDescription') }} /> +
  • + +
  • @@ -88,11 +88,11 @@ class ConfigureStreamContainer extends Component { handleChange={this.handleChange} handleApply={this.handleApply} changed={this.state.changed} - premodLinks={false} + premodLinks={settings.premodLinks} premod={premod} updateQuestionBoxContent={this.updateQuestionBoxContent} - questionBoxEnable={questionBoxEnable} - questionBoxContent={questionBoxContent} + questionBoxEnable={settings.questionBoxEnable} + questionBoxContent={settings.questionBoxContent} />

    {status === 'open' ? 'Close' : 'Open'} Comment Stream

    From cb88f0a9b79c91d2e0fb3b1a82f18d7046002e1a Mon Sep 17 00:00:00 2001 From: David Jay Date: Fri, 3 Mar 2017 14:32:57 -0500 Subject: [PATCH 2/7] 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 }, From 2e5d453ea7eb32415aa4cb32a6597f43557b9628 Mon Sep 17 00:00:00 2001 From: David Jay Date: Fri, 3 Mar 2017 15:44:03 -0500 Subject: [PATCH 3/7] Updating link search and adding settings in admin panel. --- .../src/containers/Configure/StreamSettings.js | 18 ++++++++++++++++++ .../ModerationQueue/components/Comment.js | 1 + client/coral-admin/src/translations.json | 2 ++ graph/mutators/comment.js | 3 ++- package.json | 1 + 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/client/coral-admin/src/containers/Configure/StreamSettings.js b/client/coral-admin/src/containers/Configure/StreamSettings.js index 568e0a075..950c5a2aa 100644 --- a/client/coral-admin/src/containers/Configure/StreamSettings.js +++ b/client/coral-admin/src/containers/Configure/StreamSettings.js @@ -32,6 +32,11 @@ const updateInfoBoxEnable = (updateSettings, infoBox) => () => { updateSettings({infoBoxEnable}); }; +const updatePremodLinksEnable = (updateSettings, premodLinks) => () => { + const premodLinksEnable = !premodLinks; + updateSettings({premodLinksEnable}); +}; + const updateInfoBoxContent = (updateSettings) => (event) => { const infoBoxContent = event.target.value; updateSettings({infoBoxContent}); @@ -92,6 +97,19 @@ const StreamSettings = ({updateSettings, settingsError, settings, errors}) => {

    + +
    + +
    +
    + {lang.t('configure.enable-premod-links')} +

    + {lang.t('configure.enable-premod-links-text')} +

    +
    +
    { const links = linkify.getMatches(props.comment.body); + console.log('Links', links); const actionSummaries = props.comment.action_summaries; return (
  • { } // If the comment contains a link. - if (settings.premodLinksEnable && /\S+\.\S+/.exec(comment.body)) { + if (settings.premodLinksEnable && linkify.test(comment.body)) { return ActionsService.insertUserAction({ item_id: comment.id, item_type: 'COMMENTS', diff --git a/package.json b/package.json index 740063dd1..6f0fd24c1 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "inquirer": "^3.0.1", "jsonwebtoken": "^7.1.9", "kue": "^0.11.5", + "linkify-it": "^2.0.3", "lodash": "^4.16.6", "metascraper": "^1.0.6", "minimist": "^1.2.0", From b912b60428a286014e1634a756118ffe48cd4d32 Mon Sep 17 00:00:00 2001 From: David Jay Date: Fri, 3 Mar 2017 16:01:53 -0500 Subject: [PATCH 4/7] Removing unecessary log statement. --- .../src/containers/ModerationQueue/components/Comment.js | 1 - 1 file changed, 1 deletion(-) diff --git a/client/coral-admin/src/containers/ModerationQueue/components/Comment.js b/client/coral-admin/src/containers/ModerationQueue/components/Comment.js index 44f693ff5..3a82af2cd 100644 --- a/client/coral-admin/src/containers/ModerationQueue/components/Comment.js +++ b/client/coral-admin/src/containers/ModerationQueue/components/Comment.js @@ -19,7 +19,6 @@ const lang = new I18n(translations); const Comment = ({actions = [], ...props}) => { const links = linkify.getMatches(props.comment.body); - console.log('Links', links); const actionSummaries = props.comment.action_summaries; return (
  • Date: Fri, 3 Mar 2017 16:09:34 -0500 Subject: [PATCH 5/7] Updating moderation. --- client/coral-admin/src/translations.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/coral-admin/src/translations.json b/client/coral-admin/src/translations.json index c729bb2e5..3294fe84a 100644 --- a/client/coral-admin/src/translations.json +++ b/client/coral-admin/src/translations.json @@ -66,8 +66,8 @@ "include-comment-stream": "Include Comment Stream Description for Readers.", "include-comment-stream-desc": "Write a message to be added to the top of your comment stream. Pose a topic, include community guidelines, etc.", "include-text": "Include your text here.", - "enable-premod-links": "Moderate all comments with links", - "enable-premod-links-text": "Automatically send comments with links to the moderation queue.", + "enable-premod-links": "Pre-Moderate Comments Containing Links", + "enable-premod-links-text": "Moderators must approve any comment containing a link before its published.", "comment-settings": "Settings", "embed-comment-stream": "Embed Stream", "banned-word-text": "Comments which contain these words or phrases (not case-sensitive) will be automatically removed from the comment stream. Type a word and press Enter or Tab to add. Optionally paste a comma-separated list.", @@ -195,6 +195,8 @@ "include-text": "Incluir tu texto aqui.", "comment-settings": "Configuración de Comentarios", "embed-comment-stream": "Colocar Hilo de Comentarios", + "enable-premod-links": "Pre-Moderar Commentarios que contienen Links", + "enable-premod-links-text": "Los y las Moderadoras deben probar cualquier comentario que contengan links antes de su publicación.", "wordlist": "Palabras Suspendidas y Suspechosas", "banned-word-text": "Comentarios que contengan estas palabras o frases, no separadas por comas y en mayusculas o minusuculas, serán automaticamente separadas de los comentarios publicados.", "suspect-word-text": "Comments which contain these words or phrases (not case-sensitive) will be highlighted in the comment stream. Type a word and press Enter or Tab to add. Optionally paste a comma-separated list.", From be8332da667ab099323cdb5fc034a6ec01fe1ad9 Mon Sep 17 00:00:00 2001 From: David Jay Date: Fri, 3 Mar 2017 16:12:53 -0500 Subject: [PATCH 6/7] Switching link action from flag to premod. --- graph/mutators/comment.js | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/graph/mutators/comment.js b/graph/mutators/comment.js index 3f6664cfc..620601851 100644 --- a/graph/mutators/comment.js +++ b/graph/mutators/comment.js @@ -76,7 +76,7 @@ const filterNewComment = (context, {body, asset_id}) => { * @param {Object} [wordlist={}] the results of the wordlist scan * @return {Promise} resolves to the comment's status */ -const resolveNewCommentStatus = (context, {asset_id, body}, wordlist = {}) => { +const resolveNewCommentStatus = (context, {asset_id, body}, wordlist = {}, settings) => { // 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 @@ -86,6 +86,8 @@ const resolveNewCommentStatus = (context, {asset_id, body}, wordlist = {}) => { if (wordlist.banned) { status = Promise.resolve('REJECTED'); + } else if (settings.premodLinksEnable && linkify.test(body)) { + status = Promise.resolve('PREMOD'); } else { status = AssetsService .rectifySettings(AssetsService.findById(asset_id).then((asset) => { @@ -135,7 +137,7 @@ 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, settings]) => resolveNewCommentStatus(context, commentInput, wordlist) + .then(([wordlist, settings]) => resolveNewCommentStatus(context, commentInput, wordlist, settings) // Then we actually create the comment with the new status. .then((status) => createComment(context, commentInput, status)) @@ -162,19 +164,6 @@ const createPublicComment = (context, commentInput) => { .then(() => comment); } - // If the comment contains a link. - if (settings.premodLinksEnable && linkify.test(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; })); From 78a2a64671670e85ce32ba974b1aa9dfc92e82de Mon Sep 17 00:00:00 2001 From: David Jay Date: Tue, 7 Mar 2017 13:13:21 -0500 Subject: [PATCH 7/7] Not displaying premod or rejected comments. --- client/coral-framework/graphql/mutations/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/coral-framework/graphql/mutations/index.js b/client/coral-framework/graphql/mutations/index.js index a874f8f0c..7dd8bf12b 100644 --- a/client/coral-framework/graphql/mutations/index.js +++ b/client/coral-framework/graphql/mutations/index.js @@ -42,7 +42,7 @@ export const postComment = graphql(POST_COMMENT, { updateQueries: { AssetQuery: (oldData, {mutationResult:{data:{createComment:{comment}}}}) => { - if (oldData.asset.settings.moderation === 'PRE') { + if (oldData.asset.settings.moderation === 'PRE' || comment.status === 'PREMOD' || comment.status === 'REJECTED') { return oldData; }