merge master

This commit is contained in:
riley
2017-05-16 16:33:41 -06:00
219 changed files with 3845 additions and 1847 deletions
+17 -11
View File
@@ -4,7 +4,7 @@ const Asset = {
asset_id: id,
limit: 1,
parent_id: null
}).then(data => data[0]);
}).then((data) => data[0]);
},
recentComments({id}, _, {loaders: {Comments}}) {
return Comments.genRecentComments.load(id);
@@ -19,6 +19,8 @@ const Asset = {
});
},
commentCount({id, commentCount}, {excludeIgnored}, {user, loaders: {Comments}}) {
// TODO: remove
if (user && excludeIgnored) {
return Comments.parentCountByAssetIDPersonalized({assetId: id, excludeIgnored});
}
@@ -28,6 +30,8 @@ const Asset = {
return Comments.parentCountByAssetID.load(id);
},
totalCommentCount({id, totalCommentCount}, {excludeIgnored}, {user, loaders: {Comments}}) {
// TODO: remove
if (user && excludeIgnored) {
return Comments.countByAssetIDPersonalized({assetId: id, excludeIgnored});
}
@@ -36,16 +40,18 @@ const Asset = {
}
return Comments.countByAssetID.load(id);
},
settings({settings = null}, _, {loaders: {Settings}}) {
return Settings.load()
.then((globalSettings) => {
if (settings) {
settings = Object.assign({}, globalSettings.toObject(), settings);
} else {
settings = globalSettings.toObject();
}
return settings;
});
async settings({settings = null}, _, {loaders: {Settings}}) {
// Load the global settings, and merge them into the asset specific settings
// if we have some.
let globalSettings = await Settings.load();
if (settings !== null) {
settings = Object.assign({}, globalSettings.toObject(), settings);
} else {
settings = globalSettings.toObject();
}
return settings;
}
};
+8
View File
@@ -22,6 +22,8 @@ const Comment = {
});
},
replyCount({id}, {excludeIgnored}, {user, loaders: {Comments}}) {
// TODO: remove
if (user && excludeIgnored) {
return Comments.countByParentIDPersonalized({id, excludeIgnored});
}
@@ -44,6 +46,12 @@ const Comment = {
},
asset({asset_id}, _, {loaders: {Assets}}) {
return Assets.getByID.load(asset_id);
},
editing(comment) {
return {
edited: comment.edited,
editableUntil: comment.editableUntil
};
}
};
+4 -1
View File
@@ -5,6 +5,9 @@ const RootMutation = {
createComment(_, {comment}, {mutators: {Comment}}) {
return wrapResponse('comment')(Comment.create(comment));
},
editComment(_, {id, asset_id, edit: {body}}, {mutators: {Comment}}) {
return wrapResponse('comment')(Comment.edit({id, asset_id, edit: {body}}));
},
createFlag(_, {flag: {item_id, item_type, reason, message}}, {mutators: {Action}}) {
return wrapResponse('flag')(Action.create({item_id, item_type, action_type: 'FLAG', group_id: reason, metadata: {message}}));
},
@@ -27,7 +30,7 @@ const RootMutation = {
return wrapResponse(null)(User.stopIgnoringUser({id}));
},
setCommentStatus(_, {id, status}, {mutators: {Comment}}) {
return wrapResponse(null)(Comment.setCommentStatus({id, status}));
return wrapResponse(null)(Comment.setStatus({id, status}));
},
addCommentTag(_, {id, tag}, {mutators: {Comment}}) {
return wrapResponse('comment')(Comment.addCommentTag({id, tag}).then(() => CommentsService.findById(id)));
+12 -31
View File
@@ -19,16 +19,14 @@ const RootQuery = {
// This endpoint is used for loading moderation queues, so hide it in the
// event that we aren't an admin.
comments(_, {query: {action_type, statuses, asset_id, parent_id, limit, cursor, sort, excludeIgnored}}, {user, loaders: {Comments, Actions}}) {
async comments(_, {query: {action_type, statuses, asset_id, parent_id, limit, cursor, sort, excludeIgnored}}, {user, loaders: {Comments, Actions}}) {
let query = {statuses, asset_id, parent_id, limit, cursor, sort, excludeIgnored};
if (user != null && user.can('SEARCH_OTHERS_COMMENTS') && action_type) {
return Actions.getByTypes({action_type, item_type: 'COMMENTS'})
.then((ids) => {
let ids = await Actions.getByTypes({action_type, item_type: 'COMMENTS'});
// Perform the query using the available resolver.
return Comments.getByQuery({ids, statuses, asset_id, parent_id, limit, cursor, sort, excludeIgnored});
});
// Perform the query using the available resolver.
return Comments.getByQuery({ids, statuses, asset_id, parent_id, limit, cursor, sort, excludeIgnored});
}
return Comments.getByQuery(query);
@@ -36,18 +34,16 @@ const RootQuery = {
comment(_, {id}, {loaders: {Comments}}) {
return Comments.get.load(id);
},
commentCount(_, {query: {action_type, statuses, asset_id, parent_id}}, {user, loaders: {Actions, Comments}}) {
async commentCount(_, {query: {action_type, statuses, asset_id, parent_id}}, {user, loaders: {Actions, Comments}}) {
if (user == null || !user.can('SEARCH_OTHERS_COMMENTS')) {
return null;
}
if (action_type) {
return Actions.getByTypes({action_type, item_type: 'COMMENTS'})
.then((ids) => {
let ids = await Actions.getByTypes({action_type, item_type: 'COMMENTS'});
// Perform the query using the available resolver.
return Comments.getCountByQuery({ids, statuses, asset_id, parent_id});
});
// Perform the query using the available resolver.
return Comments.getCountByQuery({ids, statuses, asset_id, parent_id});
}
return Comments.getCountByQuery({statuses, asset_id, parent_id});
@@ -83,22 +79,9 @@ const RootQuery = {
return user;
},
myIgnoredUsers: async (_, args, {user, loaders: {Users}}) => {
if (!user) {
return null;
}
// get currentUser again since context.user was out of date when running test/graph/mutations/ignoreUser
const currentUser = (await Users.getByQuery({ids: [user.id], limit: 1}))[0];
if ( ! (currentUser && Array.isArray(currentUser.ignoresUsers) && currentUser.ignoresUsers.length)) {
return [];
}
return await Users.getByQuery({ids: currentUser.ignoresUsers});
},
// This endpoint is used for loading the user moderation queues (users whose username has been flagged),
// so hide it in the event that we aren't an admin.
users(_, {query: {action_type, limit, cursor, sort}}, {user, loaders: {Users, Actions}}) {
async users(_, {query: {action_type, limit, cursor, sort}}, {user, loaders: {Users, Actions}}) {
if (user == null || !user.can('SEARCH_OTHER_USERS')) {
return null;
@@ -107,12 +90,10 @@ const RootQuery = {
const query = {limit, cursor, sort};
if (action_type) {
return Actions.getByTypes({action_type, item_type: 'USERS'})
.then((ids) => {
let ids = await Actions.getByTypes({action_type, item_type: 'USERS'});
// Perform the query using the available resolver.
return Users.getByQuery({ids, limit, cursor, sort}).find({status: 'PENDING'});
});
// Perform the query using the available resolver.
return Users.getByQuery({ids, limit, cursor, sort}).find({status: 'PENDING'});
}
return Users.getByQuery(query);
+15
View File
@@ -20,6 +20,21 @@ const User = {
return null;
},
ignoredUsers({id}, args, {user, loaders: {Users}}) {
// Only allow a logged in user that is either the current user or is a staff
// member to access the ignoredUsers of a given user.
if (!user || ((user.id !== id) && !(user.hasRoles('ADMIN') || user.hasRoles('MODERATOR')))) {
return null;
}
// Return nothing if there is nothing to query for.
if (!user.ignoresUsers || user.ignoresUsers.length <= 0) {
return [];
}
return Users.getByQuery({ids: user.ignoresUsers});
},
roles({id, roles}, _, {user}) {
// If the user is not an admin, only return the current user's roles.