Allow querying for all statuses

This commit is contained in:
Chi Vinh Le
2017-09-20 02:39:31 +07:00
parent 6e89b8c1aa
commit b482976c58
5 changed files with 37 additions and 22 deletions
+16 -10
View File
@@ -91,12 +91,19 @@ const getParentCountsByAssetID = (context, asset_ids) => {
const getCommentCountByQuery = (context, {ids, statuses, asset_id, parent_id, author_id, tags, action_type}) => {
let query = CommentModel.find();
if (ids) {
query = query.where({id: {$in: ids}});
if (
(context.user != null && context.user.can(SEARCH_NON_NULL_OR_ACCEPTED_COMMENTS)) ||
statuses && statuses.every((status) => ['NONE', 'ACCEPTED'].includes(status))
) {
if (statuses) {
query = query.where({status: {$in: statuses}});
}
} else {
return null;
}
if (statuses) {
query = query.where({status: {$in: statuses}});
if (ids) {
query = query.where({id: {$in: ids}});
}
if (asset_id != null) {
@@ -281,7 +288,10 @@ const getCommentsByQuery = async (ctx, {ids, statuses, asset_id, parent_id, auth
// Only administrators can search for comments with statuses that are not
// `null`, or `'ACCEPTED'`.
if (ctx.user != null && ctx.user.can(SEARCH_NON_NULL_OR_ACCEPTED_COMMENTS)) {
if (
(ctx.user != null && ctx.user.can(SEARCH_NON_NULL_OR_ACCEPTED_COMMENTS)) ||
statuses && statuses.every((status) => ['NONE', 'ACCEPTED'].includes(status))
) {
if (statuses && statuses.length > 0) {
comments = comments.where({
status: {
@@ -290,11 +300,7 @@ const getCommentsByQuery = async (ctx, {ids, statuses, asset_id, parent_id, auth
});
}
} else {
comments = comments.where({
status: {
$in: ['NONE', 'ACCEPTED']
}
});
return null;
}
if (ctx.user != null && ctx.user.can(SEARCH_OTHERS_COMMENTS) && action_type) {
+1
View File
@@ -23,6 +23,7 @@ const Asset = {
// Include the asset id in the search.
query.asset_id = id;
query.statuses = ['NONE', 'ACCEPTED'];
return Comments.getByQuery(query);
},
+1
View File
@@ -26,6 +26,7 @@ const Comment = {
query.asset_id = asset_id;
query.parent_id = id;
query.statuses = ['NONE', 'ACCEPTED'];
return Comments.getByQuery(query);
},
+10 -5
View File
@@ -264,8 +264,9 @@ input CommentsQuery {
# Author of the comments
author_id: ID
# Current status of a comment. Requires the `ADMIN` role.
statuses: [COMMENT_STATUS!]
# Current status of a comment.
# This field is restricted.
statuses: [COMMENT_STATUS!] = [NONE, ACCEPTED]
# Asset that a comment is on.
asset_id: ID
@@ -317,8 +318,9 @@ input RepliesQuery {
# methods.
input CommentCountQuery {
# Current status of a comment. Requires the `ADMIN` role.
statuses: [COMMENT_STATUS!]
# Current status of a comment.
# This field is restricted.
statuses: [COMMENT_STATUS!] = [NONE, ACCEPTED]
# Asset that a comment is on.
asset_id: ID
@@ -688,7 +690,7 @@ type Asset {
# The comments that are attached to the asset. When `deep` is true, the
# comments returned will be at all depths.
comments(query: CommentsQuery = {}, deep: Boolean = false): CommentConnection!
comments(query: CommentsQuery = {}, deep: Boolean = false): CommentConnection
# A Comment from the Asset by comment's ID
comment(id: ID!): Comment
@@ -875,6 +877,9 @@ type CreateCommentResponse implements Response {
# The comment that was created.
comment: Comment
# Flags that was assigned during creation of the comment.
flags: [FlagAction]
# An array of errors relating to the mutation that occurred.
errors: [UserError!]
}