mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: #8556, catch errors from admin check
This commit is contained in:
@@ -122,32 +122,27 @@ User.forcePasswordReset = async function (socket, uids) {
|
||||
};
|
||||
|
||||
User.deleteUsers = async function (socket, uids) {
|
||||
await canDeleteUids(uids);
|
||||
deleteUsers(socket, uids, async function (uid) {
|
||||
return await user.deleteAccount(uid);
|
||||
});
|
||||
};
|
||||
|
||||
User.deleteUsersContent = async function (socket, uids) {
|
||||
if (!Array.isArray(uids)) {
|
||||
throw new Error('[[error:invalid-data]]');
|
||||
}
|
||||
const isMembers = await groups.isMembers(uids, 'administrators');
|
||||
if (isMembers.includes(true)) {
|
||||
throw new Error('[[error:cant-delete-other-admins]]');
|
||||
}
|
||||
|
||||
await canDeleteUids(uids);
|
||||
await Promise.all(uids.map(async (uid) => {
|
||||
await user.deleteContent(socket.uid, uid);
|
||||
}));
|
||||
};
|
||||
|
||||
User.deleteUsersAndContent = async function (socket, uids) {
|
||||
await canDeleteUids(uids);
|
||||
deleteUsers(socket, uids, async function (uid) {
|
||||
return await user.delete(socket.uid, uid);
|
||||
});
|
||||
};
|
||||
|
||||
async function deleteUsers(socket, uids, method) {
|
||||
async function canDeleteUids(uids) {
|
||||
if (!Array.isArray(uids)) {
|
||||
throw new Error('[[error:invalid-data]]');
|
||||
}
|
||||
@@ -155,6 +150,9 @@ async function deleteUsers(socket, uids, method) {
|
||||
if (isMembers.includes(true)) {
|
||||
throw new Error('[[error:cant-delete-other-admins]]');
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteUsers(socket, uids, method) {
|
||||
async function doDelete(uid) {
|
||||
await flags.resolveFlag('user', uid, socket.uid);
|
||||
const userData = await method(uid);
|
||||
|
||||
Reference in New Issue
Block a user