mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 02:25:55 +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) {
|
User.deleteUsers = async function (socket, uids) {
|
||||||
|
await canDeleteUids(uids);
|
||||||
deleteUsers(socket, uids, async function (uid) {
|
deleteUsers(socket, uids, async function (uid) {
|
||||||
return await user.deleteAccount(uid);
|
return await user.deleteAccount(uid);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
User.deleteUsersContent = async function (socket, uids) {
|
User.deleteUsersContent = async function (socket, uids) {
|
||||||
if (!Array.isArray(uids)) {
|
await canDeleteUids(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 Promise.all(uids.map(async (uid) => {
|
await Promise.all(uids.map(async (uid) => {
|
||||||
await user.deleteContent(socket.uid, uid);
|
await user.deleteContent(socket.uid, uid);
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
User.deleteUsersAndContent = async function (socket, uids) {
|
User.deleteUsersAndContent = async function (socket, uids) {
|
||||||
|
await canDeleteUids(uids);
|
||||||
deleteUsers(socket, uids, async function (uid) {
|
deleteUsers(socket, uids, async function (uid) {
|
||||||
return await user.delete(socket.uid, uid);
|
return await user.delete(socket.uid, uid);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
async function deleteUsers(socket, uids, method) {
|
async function canDeleteUids(uids) {
|
||||||
if (!Array.isArray(uids)) {
|
if (!Array.isArray(uids)) {
|
||||||
throw new Error('[[error:invalid-data]]');
|
throw new Error('[[error:invalid-data]]');
|
||||||
}
|
}
|
||||||
@@ -155,6 +150,9 @@ async function deleteUsers(socket, uids, method) {
|
|||||||
if (isMembers.includes(true)) {
|
if (isMembers.includes(true)) {
|
||||||
throw new Error('[[error:cant-delete-other-admins]]');
|
throw new Error('[[error:cant-delete-other-admins]]');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteUsers(socket, uids, method) {
|
||||||
async function doDelete(uid) {
|
async function doDelete(uid) {
|
||||||
await flags.resolveFlag('user', uid, socket.uid);
|
await flags.resolveFlag('user', uid, socket.uid);
|
||||||
const userData = await method(uid);
|
const userData = await method(uid);
|
||||||
|
|||||||
Reference in New Issue
Block a user