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
@@ -170,7 +170,8 @@ class ModerationContainer extends Component {
cursor: this.props.root[tab].endCursor,
sortOrder: this.props.data.variables.sortOrder,
asset_id: this.props.data.variables.asset_id,
statuses: this.props.queueConfig[tab].statuses,
statuses: this.props.queueConfig[tab].statuses || null,
tags: this.props.queueConfig[tab].tags || null,
action_type: this.props.queueConfig[tab].action_type,
};
return this.props.data.fetchMore({
@@ -214,7 +215,7 @@ class ModerationContainer extends Component {
return <Spinner />;
}
const premodEnabled = assetId ? isPremod(asset.settings.moderation) :
const premodEnabled = assetId ? isPremod(asset.settings.moderation) :
isPremod(settings.moderation);
const currentQueueConfig = Object.assign({}, this.props.queueConfig);
@@ -293,8 +294,8 @@ const COMMENT_REJECTED_SUBSCRIPTION = gql`
`;
const LOAD_MORE_QUERY = gql`
query CoralAdmin_Moderation_LoadMore($limit: Int = 10, $cursor: Cursor, $sortOrder: SORT_ORDER, $asset_id: ID, $statuses:[COMMENT_STATUS!], $action_type: ACTION_TYPE) {
comments(query: {limit: $limit, cursor: $cursor, asset_id: $asset_id, statuses: $statuses, sortOrder: $sortOrder, action_type: $action_type}) {
query CoralAdmin_Moderation_LoadMore($limit: Int = 10, $cursor: Cursor, $sortOrder: SORT_ORDER, $asset_id: ID, $tags:[String!], $statuses:[COMMENT_STATUS!], $action_type: ACTION_TYPE) {
comments(query: {limit: $limit, cursor: $cursor, asset_id: $asset_id, statuses: $statuses, sortOrder: $sortOrder, action_type: $action_type, tags: $tags}) {
nodes {
...${getDefinitionName(Comment.fragments.comment)}
}
@@ -319,10 +320,10 @@ const commentConnectionFragment = gql`
`;
const withModQueueQuery = withQuery(({queueConfig}) => gql`
query CoralAdmin_Moderation($asset_id: ID, $sortOrder: SORT_ORDER, $allAssets: Boolean!) {
query CoralAdmin_Moderation($asset_id: ID, $sortOrder: SORT_ORDER, $allAssets: Boolean!, $nullStatuses: [COMMENT_STATUS!]) {
${Object.keys(queueConfig).map((queue) => `
${queue}: comments(query: {
${queueConfig[queue].statuses ? `statuses: [${queueConfig[queue].statuses.join(', ')}],` : ''}
statuses: ${queueConfig[queue].statuses ? `[${queueConfig[queue].statuses.join(', ')}],` : '$nullStatuses'}
${queueConfig[queue].tags ? `tags: ["${queueConfig[queue].tags.join('", "')}"],` : ''}
${queueConfig[queue].action_type ? `action_type: ${queueConfig[queue].action_type}` : ''}
asset_id: $asset_id,
@@ -333,7 +334,7 @@ const withModQueueQuery = withQuery(({queueConfig}) => gql`
`)}
${Object.keys(queueConfig).map((queue) => `
${queue}Count: commentCount(query: {
${queueConfig[queue].statuses ? `statuses: [${queueConfig[queue].statuses.join(', ')}],` : ''}
statuses: ${queueConfig[queue].statuses ? `[${queueConfig[queue].statuses.join(', ')}],` : '$nullStatuses'}
${queueConfig[queue].tags ? `tags: ["${queueConfig[queue].tags.join('", "')}"],` : ''}
${queueConfig[queue].action_type ? `action_type: ${queueConfig[queue].action_type}` : ''}
asset_id: $asset_id,
@@ -361,6 +362,7 @@ const withModQueueQuery = withQuery(({queueConfig}) => gql`
asset_id: id,
sortOrder: props.moderation.sortOrder,
allAssets: id === null,
nullStatuses: null,
},
fetchPolicy: 'network-only'
};
+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!]
}