From 86c3c286eec17a9537f95ad3783f4769d6f444a9 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Fri, 6 Oct 2017 16:10:39 -0600 Subject: [PATCH] Graph fixes and migrations - Added migrations for mapping old keys - Added migration for fixing old dont agree flags - Removed enum requirement for output --- graph/mutators/comment.js | 4 +-- graph/typeDefs.graphql | 4 +-- locales/en.yml | 5 +++ migrations/1507310316_flags.js | 50 ++++++++++++++++++++++++++++++ migrations/1507322128_dontagree.js | 21 +++++++++++++ package.json | 2 +- 6 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 migrations/1507310316_flags.js create mode 100644 migrations/1507322128_dontagree.js diff --git a/graph/mutators/comment.js b/graph/mutators/comment.js index a0ee0a039..75d0f8564 100644 --- a/graph/mutators/comment.js +++ b/graph/mutators/comment.js @@ -267,7 +267,7 @@ const moderationPhases = [ actions: [{ action_type: 'FLAG', user_id: null, - group_id: 'Matched suspect word filter', + group_id: 'SUSPECT_WORD', metadata: {} }], }; @@ -302,7 +302,7 @@ const moderationPhases = [ // Add the flag related to Trust to the comment. return { - status:'SYSTEM_WITHHELD', + status: 'SYSTEM_WITHHELD', actions: [{ action_type: 'FLAG', user_id: null, diff --git a/graph/typeDefs.graphql b/graph/typeDefs.graphql index 73a674191..18baedf17 100644 --- a/graph/typeDefs.graphql +++ b/graph/typeDefs.graphql @@ -555,7 +555,7 @@ type FlagAction implements Action { id: ID! # The reason for which the Flag Action was created. - reason: FLAG_REASON + reason: String # An optional message sent with the flagging action by the user. message: String @@ -596,7 +596,7 @@ type FlagActionSummary implements ActionSummary { count: Int! # The reason for which the Flag Action was created. - reason: FLAG_REASON + reason: String # The flag by the current user against the parent entity with this reason. current_user: FlagAction diff --git a/locales/en.yml b/locales/en.yml index 464277aee..69a6fb3f7 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -263,6 +263,11 @@ en: comment_spam: "Spam" comment_noagree: "Disagree" comment_other: "Other" + suspect_word: "Suspect Word" + banned_word: "Banned Word" + body_count: "Body exceeds max length" + links: "Links" + trust: "Trust" modqueue: account: "account flags" actions: Actions diff --git a/migrations/1507310316_flags.js b/migrations/1507310316_flags.js new file mode 100644 index 000000000..28b9d00cd --- /dev/null +++ b/migrations/1507310316_flags.js @@ -0,0 +1,50 @@ +const ActionModel = require('../models/action'); + +const mapping = { + COMMENTS: { + 'Comment contains toxic language': 'TOXIC_COMMENT', + 'Matched suspect word filter': 'SUSPECT_WORD', + 'other': 'COMMENT_OTHER', + 'Other': 'COMMENT_OTHER', + 'This looks like an ad/marketing': 'COMMENT_SPAM', + 'This comment is offensive': 'COMMENT_OFFENSIVE', + }, +}; + +module.exports = { + async up() { + + // Setup the batch operation. + const batch = ActionModel.collection.initializeUnorderedBulkOp(); + + for (const item_type in mapping) { + const mappings = mapping[item_type]; + + for (const OLD_GROUP_ID in mappings) { + const NEW_GROUP_ID = mappings[OLD_GROUP_ID]; + + // OLD + // { + // group_id: + // } + // NEW + // { + // group_id: + // } + + batch.find({ + group_id: OLD_GROUP_ID, + item_type, + }).update({ + $set: { + group_id: NEW_GROUP_ID, + }, + }); + } + } + + // Execute the batch update operation. + await batch.execute(); + } +}; + diff --git a/migrations/1507322128_dontagree.js b/migrations/1507322128_dontagree.js new file mode 100644 index 000000000..bb8ffc36f --- /dev/null +++ b/migrations/1507322128_dontagree.js @@ -0,0 +1,21 @@ +const ActionModel = require('../models/action'); + +module.exports = { + async up() { + + // This will update all the old flags that are 'COMMENT_NOAGREE' to change + // them to DONTAGREE actions instead. + return ActionModel.update({ + action_type: 'FLAG', + group_id: 'COMMENT_NOAGREE', + }, { + $set: { + action_type: 'DONTAGREE', + group_id: null, + }, + }, { + multi: true, + }); + } +}; + diff --git a/package.json b/package.json index 57abb4f1d..27d6a387e 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ }, "talk": { "migration": { - "minVersion": 1496771633 + "minVersion": 1507322128 } }, "config": {