diff --git a/client/coral-admin/src/graphql/queries/modUserFlaggedQuery.graphql b/client/coral-admin/src/graphql/queries/modUserFlaggedQuery.graphql index 55090d8e4..63697ca6c 100644 --- a/client/coral-admin/src/graphql/queries/modUserFlaggedQuery.graphql +++ b/client/coral-admin/src/graphql/queries/modUserFlaggedQuery.graphql @@ -1,15 +1,12 @@ -query Users { - usersFlagged { +query Users ($n: ACTION_TYPE) { + users (query:{action_type: $n}){ id username status roles actions{ id - reason - user { - username - } + created_at } action_summaries { count diff --git a/graph/loaders/users.js b/graph/loaders/users.js index 2928e41f3..145b0dfdb 100644 --- a/graph/loaders/users.js +++ b/graph/loaders/users.js @@ -19,13 +19,6 @@ const getUsersByQuery = ({user}, {ids, limit, cursor, sort}) => { let users = UserModel.find(); - // Only administrators can search for users - if (user == null || !user.hasRoles('ADMIN')) { - return null; - } - - users = users.find(); - if (ids) { users = users.find({ id: { diff --git a/graph/resolvers/root_query.js b/graph/resolvers/root_query.js index 852bc41ad..fa3ea9ce7 100644 --- a/graph/resolvers/root_query.js +++ b/graph/resolvers/root_query.js @@ -76,18 +76,24 @@ const RootQuery = { // 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. - usersFlagged(_, args, {user, loaders: {Users, Actions}}) { + users(_, {query: {action_type, limit, cursor, sort}}, {user, loaders: {Users, Actions}}) { if (user == null || !user.hasRoles('ADMIN')) { return null; } - return Actions.getByTypes({action_type: 'FLAG', item_type: 'USERS'}) - .then((ids) => { + const query = {limit, cursor, sort}; - // Perform the query using the available resolver. - return Users.getByQuery({ids}); - }); + if (action_type) { + return Actions.getByTypes({action_type, item_type: 'USERS'}) + .then((ids) => { + + // Perform the query using the available resolver. + return Users.getByQuery({ids, limit, cursor, sort}); + }); + } + + return Users.getByQuery(query); } }; diff --git a/graph/resolvers/user.js b/graph/resolvers/user.js index 13efe29e9..448c1b746 100644 --- a/graph/resolvers/user.js +++ b/graph/resolvers/user.js @@ -27,6 +27,15 @@ const User = { return roles; } + return null; + }, + users({id}, _, {loaders: {Users}, user}) { + + // Only administrators can search for users + if (user && user.hasRoles('ADMIN')) { + return Users.getByQuery(); + } + return null; } }; diff --git a/graph/typeDefs.graphql b/graph/typeDefs.graphql index 9af2abbbb..15846b859 100644 --- a/graph/typeDefs.graphql +++ b/graph/typeDefs.graphql @@ -34,7 +34,7 @@ type User { action_summaries: [FlagActionSummary] # Actions completed on the parent. - actions: [FlagAction] + actions: [Action] # the current roles of the user. roles: [USER_ROLES] @@ -45,6 +45,9 @@ type User { # returns all comments based on a query. comments(query: CommentsQuery): [Comment] + # returns all users based on a query. + users(query: UsersQuery): [User] + # returns user status status: USER_STATUS } @@ -60,8 +63,9 @@ type Tag { created_at: Date! } -# UsersQuery allows the ability to query users by a specific methods. +# UsersQuery allows the ability to query users by a specific fields. input UsersQuery { + action_type: ACTION_TYPE # Limit the number of results to be returned. limit: Int = 10 @@ -512,7 +516,7 @@ type RootQuery { metrics(from: Date!, to: Date!, sort: ACTION_TYPE!, limit: Int = 10): [Asset] # Users returned based on a query. - usersFlagged(query: UsersQuery): [User] + users(query: UsersQuery): [User] } ################################################################################