From 84f1d3ece26354b38da156783a6464a92bacd7cd Mon Sep 17 00:00:00 2001 From: gaba Date: Thu, 23 Mar 2017 16:02:25 -0700 Subject: [PATCH] Use findONeAndUpdate and the moderation queue for account flags should only give back pending accounts. --- client/coral-admin/src/constants/comments.js | 2 + .../Community/components/SuspendUserDialog.js | 2 +- graph/resolvers/root_query.js | 2 +- services/users.js | 42 +++++++++---------- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/client/coral-admin/src/constants/comments.js b/client/coral-admin/src/constants/comments.js index 603a3ce00..98f2e039d 100644 --- a/client/coral-admin/src/constants/comments.js +++ b/client/coral-admin/src/constants/comments.js @@ -1,5 +1,7 @@ export const SHOW_BANUSER_DIALOG = 'SHOW_BANUSER_DIALOG'; export const HIDE_BANUSER_DIALOG = 'HIDE_BANUSER_DIALOG'; +export const SHOW_SUSPENDUSER_DIALOG = 'SHOW_SUSPENDUSER_DIALOG'; +export const HIDE_SUSPENDUSER_DIALOG = 'HIDE_SUSPENDUSER_DIALOG'; export const COMMENTS_MODERATION_QUEUE_FETCH_REQUEST = 'COMMENTS_MODERATION_QUEUE_FETCH_REQUEST'; export const COMMENTS_MODERATION_QUEUE_FETCH_SUCCESS = 'COMMENTS_MODERATION_QUEUE_FETCH_SUCCESS'; export const COMMENT_CREATE_SUCCESS = 'COMMENT_CREATE_SUCCESS'; diff --git a/client/coral-admin/src/containers/Community/components/SuspendUserDialog.js b/client/coral-admin/src/containers/Community/components/SuspendUserDialog.js index 44f38f796..20e221c48 100644 --- a/client/coral-admin/src/containers/Community/components/SuspendUserDialog.js +++ b/client/coral-admin/src/containers/Community/components/SuspendUserDialog.js @@ -49,7 +49,7 @@ class SuspendUserDialog extends Component { const {suspendUser, user} = this.props; const {stage} = this.state; - const cancel = this.props.onClose; + const cancel = this.props.handleClose; const next = () => this.setState({stage: stage + 1}); const suspend = () => { suspendUser({userId: user.user.id, message: this.state.email}) diff --git a/graph/resolvers/root_query.js b/graph/resolvers/root_query.js index ce11fcae9..6f4151ff6 100644 --- a/graph/resolvers/root_query.js +++ b/graph/resolvers/root_query.js @@ -103,7 +103,7 @@ const RootQuery = { .then((ids) => { // Perform the query using the available resolver. - return Users.getByQuery({ids, limit, cursor, sort}); + return Users.getByQuery({ids, limit, cursor, sort}).find({status: 'PENDING'}); }); } diff --git a/services/users.js b/services/users.js index 4e1196252..6c309977f 100644 --- a/services/users.js +++ b/services/users.js @@ -456,7 +456,7 @@ module.exports = class UsersService { * @param {Function} done callback after the operation is complete */ static suspendUser(id, message) { - return UserModel.update({ + return UserModel.findOneAndUpdate({ id }, { $set: { @@ -464,31 +464,27 @@ module.exports = class UsersService { canEditName: true } }) - .then(() => { - return UsersService.findById(id) - .then((user) => { - if (message) { - let localProfile = user.profiles.find((profile) => profile.provider === 'local'); + .then((user) => { + if (message) { + let localProfile = user.profiles.find((profile) => profile.provider === 'local'); - if (localProfile) { - const options = - { - template: 'suspension', // needed to know which template to render! - locals: { // specifies the template locals. - body: message - }, - subject: 'Email Suspension', - to: localProfile.id // This only works if the user has registered via e-mail. - // We may want a standard way to access a user's e-mail address in the future - }; + if (localProfile) { + const options = + { + template: 'suspension', // needed to know which template to render! + locals: { // specifies the template locals. + body: message + }, + subject: 'Email Suspension', + to: localProfile.id // This only works if the user has registered via e-mail. + // We may want a standard way to access a user's e-mail address in the future + }; - return MailerService.sendSimple(options); - } else { - return Promise.reject(errors.ErrMissingEmail); - } + return MailerService.sendSimple(options); + } else { + return Promise.reject(errors.ErrMissingEmail); } - }); - + } }); }