diff --git a/client/coral-admin/src/containers/Configure/StreamSettings.js b/client/coral-admin/src/containers/Configure/StreamSettings.js index 51250e340..5530bc6cd 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}); @@ -94,6 +99,19 @@ const StreamSettings = ({updateSettings, settingsError, settings, errors}) => {

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

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

+
+
+
  • + +
  • @@ -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

    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; } diff --git a/graph/mutators/comment.js b/graph/mutators/comment.js index 553c3f44c..bcab347d7 100644 --- a/graph/mutators/comment.js +++ b/graph/mutators/comment.js @@ -3,6 +3,7 @@ const errors = require('../../errors'); const AssetsService = require('../../services/assets'); const ActionsService = require('../../services/actions'); const CommentsService = require('../../services/comments'); +const linkify = require('linkify-it')(); const Wordlist = require('../../services/wordlist'); @@ -54,13 +55,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)) + ]); }; /** @@ -72,7 +76,7 @@ const filterNewComment = (context, {body}) => { * @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 @@ -82,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) => { @@ -131,13 +137,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, settings) // 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. diff --git a/graph/typeDefs.graphql b/graph/typeDefs.graphql index d9041aa72..29000c84d 100644 --- a/graph/typeDefs.graphql +++ b/graph/typeDefs.graphql @@ -387,6 +387,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 }, diff --git a/package.json b/package.json index f67a36908..92442efd2 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",