mirror of
https://github.com/wassname/talk.git
synced 2026-07-10 04:51:33 +08:00
Refactor users query
This commit is contained in:
@@ -19,7 +19,6 @@ const shortReasons = {
|
||||
// Render a single user for the list
|
||||
const User = (props) => {
|
||||
const {user, modActionButtons} = props;
|
||||
let userStatus = user.status;
|
||||
|
||||
const showSuspenUserDialog = () => props.showSuspendUserDialog({
|
||||
userId: user.id,
|
||||
@@ -31,9 +30,7 @@ const User = (props) => {
|
||||
username: user.username,
|
||||
});
|
||||
|
||||
// Do not display unless the user status is 'pending' or 'banned'.
|
||||
// This means that they have already been reviewed and approved.
|
||||
return (userStatus === 'PENDING' || userStatus === 'BANNED') &&
|
||||
return (
|
||||
<li tabIndex={props.index} className={`mdl-card ${props.selected ? 'mdl-shadow--8dp' : 'mdl-shadow--2dp'} ${styles.listItem} ${props.isActive && !props.hideActive ? styles.activeItem : ''}`}>
|
||||
<div className={styles.container}>
|
||||
<div className={styles.itemHeader}>
|
||||
@@ -111,7 +108,8 @@ const User = (props) => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>;
|
||||
</li>
|
||||
);
|
||||
};
|
||||
|
||||
export default User;
|
||||
|
||||
@@ -87,7 +87,7 @@ const LOAD_MORE_QUERY = gql`
|
||||
export const withFlaggedAccountsyQuery = withQuery(gql`
|
||||
query TalkAdmin_FlaggedAccounts {
|
||||
...${getDefinitionName(FlaggedUser.fragments.root)}
|
||||
users(query:{action_type: FLAG, limit: 10}){
|
||||
users(query:{action_type: FLAG, statuses: [PENDING], limit: 10}){
|
||||
hasNextPage
|
||||
endCursor
|
||||
nodes {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const DataLoader = require('dataloader');
|
||||
|
||||
const util = require('./util');
|
||||
const union = require('lodash/union');
|
||||
|
||||
const UsersService = require('../../services/users');
|
||||
const UserModel = require('../../models/user');
|
||||
@@ -26,10 +27,15 @@ const genUserByIDs = async (context, ids) => {
|
||||
* @param {Object} context graph context
|
||||
* @param {Object} query query terms to apply to the users query
|
||||
*/
|
||||
const getUsersByQuery = async ({user}, {ids, limit, cursor, statuses = null, sortOrder}) => {
|
||||
const getUsersByQuery = async ({user, loaders: {Actions}}, {ids, limit, cursor, statuses, action_type, sortOrder}) => {
|
||||
|
||||
let query = UserModel.find();
|
||||
|
||||
if (action_type) {
|
||||
const userIds = await Actions.getByTypes({action_type, item_type: 'USERS'});
|
||||
ids = ids ? union(ids, userIds) : userIds;
|
||||
}
|
||||
|
||||
if (ids) {
|
||||
query = query.find({
|
||||
id: {
|
||||
@@ -38,7 +44,7 @@ const getUsersByQuery = async ({user}, {ids, limit, cursor, statuses = null, sor
|
||||
});
|
||||
}
|
||||
|
||||
if (statuses != null) {
|
||||
if (statuses) {
|
||||
query = query.where({
|
||||
status: {
|
||||
$in: statuses
|
||||
|
||||
@@ -92,17 +92,11 @@ 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.
|
||||
async users(_, {query}, {user, loaders: {Users, Actions}}) {
|
||||
async users(_, {query}, {user, loaders: {Users}}) {
|
||||
if (user == null || !user.can(SEARCH_OTHER_USERS)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const {action_type} = query;
|
||||
if (action_type) {
|
||||
query.ids = await Actions.getByTypes({action_type, item_type: 'USERS'});
|
||||
query.statuses = ['PENDING'];
|
||||
}
|
||||
|
||||
return Users.getByQuery(query);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -141,6 +141,9 @@ type UserConnection {
|
||||
input UsersQuery {
|
||||
action_type: ACTION_TYPE
|
||||
|
||||
# Current status of a user. Requires the `ADMIN` role.
|
||||
statuses: [USER_STATUS!]
|
||||
|
||||
# Limit the number of results to be returned.
|
||||
limit: Int = 10
|
||||
|
||||
|
||||
Reference in New Issue
Block a user