Embed doesn't show comments from ignored users

This commit is contained in:
Benjamin Goering
2017-04-11 14:20:37 -07:00
parent c7d8c40770
commit 873da1cea9
10 changed files with 135 additions and 22 deletions
+15 -1
View File
@@ -6,6 +6,7 @@ const {
const DataLoader = require('dataloader');
const CommentModel = require('../../models/comment');
const UsersService = require('../../services/users');
/**
* Returns the comment count for all comments that are public based on their
@@ -142,7 +143,7 @@ const getCommentCountByQuery = (context, {ids, statuses, asset_id, parent_id}) =
* @param {Object} context graph context
* @param {Object} query query terms to apply to the comments query
*/
const getCommentsByQuery = ({user}, {ids, statuses, asset_id, parent_id, author_id, limit, cursor, sort}) => {
const getCommentsByQuery = async ({user}, {ids, statuses, asset_id, parent_id, author_id, limit, cursor, sort, notIgnoredBy}) => {
let comments = CommentModel.find();
// Only administrators can search for comments with statuses that are not
@@ -184,6 +185,19 @@ const getCommentsByQuery = ({user}, {ids, statuses, asset_id, parent_id, author_
comments = comments.where({parent_id});
}
if (notIgnoredBy) {
if (user.id !== notIgnoredBy) {
throw new Error(`You are not authorized to query for comments notIgnoredBy ${notIgnoredBy}`);
}
// load afresh, as `user` may be from cache and not have recent ignores
const freshUser = await UsersService.findById(user.id);
const ignoredUsers = freshUser.ignoresUsers;
comments = comments.where({
author_id: {$nin: ignoredUsers}
});
}
if (cursor) {
if (sort === 'REVERSE_CHRONOLOGICAL') {
comments = comments.where({
-1
View File
@@ -18,7 +18,6 @@ const ignoreUser = async ({user}, userToIgnore) => {
};
const stopIgnoringUser = async ({user}, userToStopIgnoring) => {
console.log('stopIgnoringUser!!');
return await UsersService.stopIgnoringUsers(user.id, [userToStopIgnoring.id]);
};
+3 -2
View File
@@ -2,12 +2,13 @@ const Asset = {
recentComments({id}, _, {loaders: {Comments}}) {
return Comments.genRecentComments.load(id);
},
comments({id}, {sort, limit}, {loaders: {Comments}}) {
comments({id}, {sort, limit, notIgnoredBy}, {loaders: {Comments}}) {
return Comments.getByQuery({
asset_id: id,
sort,
limit,
parent_id: null
parent_id: null,
notIgnoredBy,
});
},
commentCount({id, commentCount}, _, {loaders: {Comments}}) {
+4 -2
View File
@@ -12,12 +12,14 @@ const Comment = {
recentReplies({id}, _, {loaders: {Comments}}) {
return Comments.genRecentReplies.load(id);
},
replies({id, asset_id}, {sort, limit}, {loaders: {Comments}}) {
replies({id, asset_id}, {sort, limit, notIgnoredBy}, {loaders: {Comments}}) {
console.log('replies notIgnoredBy', notIgnoredBy);
return Comments.getByQuery({
asset_id,
parent_id: id,
sort,
limit
limit,
notIgnoredBy,
});
},
replyCount({id}, _, {loaders: {Comments}}) {
+3 -3
View File
@@ -19,15 +19,15 @@ 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}}, {user, loaders: {Comments, Actions}}) {
let query = {statuses, asset_id, parent_id, limit, cursor, sort};
comments(_, {query: {action_type, statuses, asset_id, parent_id, limit, cursor, sort, notIgnoredBy}}, {user, loaders: {Comments, Actions}}) {
let query = {statuses, asset_id, parent_id, limit, cursor, sort, notIgnoredBy};
if (user != null && user.hasRoles('ADMIN') && action_type) {
return Actions.getByTypes({action_type, item_type: 'COMMENTS'})
.then((ids) => {
// Perform the query using the available resolver.
return Comments.getByQuery({ids, statuses, asset_id, parent_id, limit, cursor, sort});
return Comments.getByQuery({ids, statuses, asset_id, parent_id, limit, cursor, sort, notIgnoredBy});
});
}
+5 -2
View File
@@ -140,6 +140,9 @@ input CommentsQuery {
# Sort the results by created_at.
sort: SORT_ORDER = REVERSE_CHRONOLOGICAL
# Exclude comments ignored by this user ID
notIgnoredBy: String
}
# CommentCountQuery allows the ability to query comment counts by specific
@@ -185,7 +188,7 @@ type Comment {
recentReplies: [Comment]
# the replies that were made to the comment.
replies(sort: SORT_ORDER = CHRONOLOGICAL, limit: Int = 3): [Comment]
replies(sort: SORT_ORDER = CHRONOLOGICAL, limit: Int = 3, notIgnoredBy: String): [Comment]
# The count of replies on a comment.
replyCount: Int
@@ -417,7 +420,7 @@ type Asset {
recentComments: [Comment]
# The top level comments that are attached to the asset.
comments(sort: SORT_ORDER = REVERSE_CHRONOLOGICAL, limit: Int = 10): [Comment]
comments(sort: SORT_ORDER = REVERSE_CHRONOLOGICAL, limit: Int = 10, notIgnoredBy: String): [Comment]
# The count of top level comments on the asset.
commentCount: Int