Initial work for locking flag type and providing translations

This commit is contained in:
Wyatt Johnson
2017-10-03 17:20:40 -06:00
parent 8a02618d8a
commit 00de72a6eb
13 changed files with 80 additions and 53 deletions
+16 -2
View File
@@ -1,12 +1,26 @@
const DataLoader = require('dataloader');
const TagsService = require('../../services/tags');
const plugins = require('../../services/plugins');
const debug = require('debug')('talk:graph:loaders:tags');
const PLUGIN_TAGS = plugins.get('server', 'tags').reduce((acc, {plugin, tags}) => {
debug(`added plugin '${plugin.name}'`);
acc = acc.concat(tags);
return acc;
}, []);
/**
* Get all the tags for the context for the dataloader.
*/
const genAll = (context, queries) => {
return Promise.all(queries.map(({id, item_type, asset_id}) => {
return TagsService.getAll({id, item_type, asset_id});
return Promise.all(queries.map(async ({id, item_type, asset_id}) => {
let tags = await TagsService.getAll({id, item_type, asset_id});
// Merge in the global plugin tags as well.
tags = tags.concat(PLUGIN_TAGS);
return tags;
}));
};
+1 -13
View File
@@ -17,22 +17,12 @@ const {
ADD_COMMENT_TAG,
EDIT_COMMENT
} = require('../../perms/constants');
const debug = require('debug')('talk:graph:mutators:comment');
const {
DISABLE_AUTOFLAG_SUSPECT_WORDS
} = require('../../config');
const debug = require('debug')('talk:graph:mutators:tags');
const plugins = require('../../services/plugins');
const pluginTags = plugins.get('server', 'tags').reduce((acc, {plugin, tags}) => {
debug(`added plugin '${plugin.name}'`);
acc = acc.concat(tags);
return acc;
}, []);
const resolveTagsForComment = async ({user, loaders: {Tags}}, {asset_id, tags = []}) => {
const item_type = 'COMMENTS';
@@ -48,8 +38,6 @@ const resolveTagsForComment = async ({user, loaders: {Tags}}, {asset_id, tags =
globalTags = [];
}
globalTags = globalTags.concat(pluginTags);
// Merge in the tags for the given comment.
tags = tags.map((name) => {
+1 -1
View File
@@ -11,7 +11,7 @@ const modify = async ({user, loaders: {Tags}}, operation, {name, id, item_type,
const tags = await Tags.getAll.load({id, item_type, asset_id});
// Resolve the TagLink that should be used to insert to the user. This will
// addtionally return with an ownership property that can be used to determine
// additionally return with an ownership property that can be used to determine
// that the user who adds this tag must also be the owner of the resource.
let {tagLink, ownership} = TagsService.resolveLink(user, tags, {name, item_type});
+1 -7
View File
@@ -1,9 +1,3 @@
const DontAgreeAction = {
// Stored in the metadata, extract and return.
reason({metadata: {reason}}) {
return reason;
}
};
const DontAgreeAction = {};
module.exports = DontAgreeAction;
+1 -5
View File
@@ -1,7 +1,3 @@
const DontAgreeActionSummary = {
reason({group_id}) {
return group_id;
}
};
const DontAgreeActionSummary = {};
module.exports = DontAgreeActionSummary;
+2 -2
View File
@@ -13,8 +13,8 @@ const RootMutation = {
createFlag: async (_, {flag: {item_id, item_type, reason, message}}, {mutators: {Action}}) => ({
flag: Action.create({item_id, item_type, action_type: 'FLAG', group_id: reason, metadata: {message}}),
}),
createDontAgree: async (_, {dontagree: {item_id, item_type, reason, message}}, {mutators: {Action}}) => ({
dontagree: await Action.create({item_id, item_type, action_type: 'DONTAGREE', group_id: reason, metadata: {message}}),
createDontAgree: async (_, {dontagree: {item_id, item_type, message}}, {mutators: {Action}}) => ({
dontagree: await Action.create({item_id, item_type, action_type: 'DONTAGREE', metadata: {message}}),
}),
deleteAction: async (_, {id}, {mutators: {Action}}) => {
await Action.delete({id});
+33 -12
View File
@@ -518,6 +518,36 @@ type FlagAssetActionSummary implements AssetActionSummary {
actionableItemCount: Int
}
enum FLAG_REASON {
# The current user thinks that the flagged username is offensive.
USERNAME_OFFENSIVE
# The current user does not like the flagged username.
USERNAME_NOLIKE
# The current user thinks that the flagged username is being used to
# impersonate another user.
USERNAME_IMPERSONATING
# The current user thinks that the flagged username is spam.
USERNAME_SPAM
# The current user thinks that the flagged username is wrong for another
# reason.
USERNAME_OTHER
# The current user thinks that the flagged comment is offensive.
COMMENT_OFFENSIVE
# The current user thinks that the flagged comment is spam.
COMMENT_SPAM
# The current user thinks that the flagged comment is wrong for another
# reason.
COMMENT_OTHER
}
# A FLAG action that contains flag metadata.
type FlagAction implements Action {
@@ -525,7 +555,7 @@ type FlagAction implements Action {
id: ID!
# The reason for which the Flag Action was created.
reason: String
reason: FLAG_REASON
# An optional message sent with the flagging action by the user.
message: String
@@ -546,9 +576,6 @@ type DontAgreeAction implements Action {
# The ID of the DontAgree Action.
id: ID!
# The reason for which the DontAgree Action was created.
reason: String
# An optional message sent with the flagging action by the user.
message: String
@@ -569,7 +596,7 @@ type FlagActionSummary implements ActionSummary {
count: Int!
# The reason for which the Flag Action was created.
reason: String
reason: FLAG_REASON
# The flag by the current user against the parent entity with this reason.
current_user: FlagAction
@@ -581,9 +608,6 @@ type DontAgreeActionSummary implements ActionSummary {
# The total count of flags with this reason.
count: Int!
# The reason for which the Flag Action was created.
reason: String
# The don't agree action by the current user against the parent entity with this reason.
current_user: DontAgreeAction
}
@@ -948,7 +972,7 @@ input CreateFlagInput {
item_type: ACTION_ITEM_TYPE!
# The reason for flagging the item.
reason: String!
reason: FLAG_REASON
# An optional message sent with the flagging action by the user.
message: String
@@ -987,9 +1011,6 @@ input CreateDontAgreeInput {
# The type of the item for which we are to create the don't agree.
item_type: ACTION_ITEM_TYPE!
# The reason for not agreeing with the item.
reason: String
# An optional message sent with the don't agree action by the user.
message: String
}