mirror of
https://github.com/wassname/talk.git
synced 2026-07-18 12:40:13 +08:00
fixed based on e2e finding a bug!
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const errors = require('../../errors');
|
||||
const UsersService = require('../../services/users');
|
||||
const {CREATE_ACTION, DELETE_ACTION} = require('../../perms/constants');
|
||||
const {
|
||||
IGNORE_FLAGS_AGAINST_STAFF,
|
||||
@@ -82,11 +83,17 @@ const createAction = async (ctx, {item_id, item_type, action_type, group_id, met
|
||||
metadata
|
||||
});
|
||||
|
||||
if (action_type === 'FLAG' && item_type === 'COMMENTS') {
|
||||
if (action_type === 'FLAG') {
|
||||
if (item_type === 'USERS') {
|
||||
|
||||
// The item is a comment, and this is a flag. Push that the comment was
|
||||
// flagged, don't wait for it to finish.
|
||||
pubsub.publish('commentFlagged', item);
|
||||
// Set the user's status as pending, as we need to review it.
|
||||
await UsersService.setStatus(item_id, 'PENDING');
|
||||
} else if (item_type === 'COMMENTS') {
|
||||
|
||||
// The item is a comment, and this is a flag. Push that the comment was
|
||||
// flagged, don't wait for it to finish.
|
||||
pubsub.publish('commentFlagged', item);
|
||||
}
|
||||
}
|
||||
|
||||
return action;
|
||||
|
||||
+28
-12
@@ -395,18 +395,34 @@ module.exports = class UsersService {
|
||||
throw new Error(`status ${status} is not supported`);
|
||||
}
|
||||
|
||||
// TODO: current updating status behavior is weird.
|
||||
// once a user has been `APPROVED` its status cannot be
|
||||
// changed anymore.
|
||||
const user = await UserModel.findOneAndUpdate({
|
||||
id,
|
||||
status: {
|
||||
$ne: 'APPROVED'
|
||||
}
|
||||
}, {
|
||||
// Compose the query.
|
||||
const query = {id};
|
||||
|
||||
// Insert extra validations into the query.
|
||||
switch (status) {
|
||||
case 'ACTIVE':
|
||||
case 'BANNED':
|
||||
case 'APPROVED':
|
||||
|
||||
// A user cannot become change their status from what it is already.
|
||||
query.status = {
|
||||
$ne: status,
|
||||
};
|
||||
break;
|
||||
case 'PENDING':
|
||||
|
||||
// A user cannot become pending if they are already approved, pending, or
|
||||
// banned
|
||||
query.status = {
|
||||
$nin: [status, 'APPROVED', 'BANNED'],
|
||||
};
|
||||
break;
|
||||
}
|
||||
|
||||
const user = await UserModel.findOneAndUpdate(query, {
|
||||
$set: {
|
||||
status
|
||||
}
|
||||
status,
|
||||
},
|
||||
}, {
|
||||
new: true,
|
||||
});
|
||||
@@ -426,8 +442,8 @@ module.exports = class UsersService {
|
||||
};
|
||||
await MailerService.sendSimple(options);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user