Skip to content

Commit

Permalink
fix: #8556, catch errors from admin check
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Aug 13, 2020
1 parent 3268273 commit bfaf648
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/socket.io/admin/user.js
Expand Up @@ -122,39 +122,37 @@ 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]]');
}
const isMembers = await groups.isMembers(uids, 'administrators');
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);
Expand Down

1 comment on commit bfaf648

@julianlam
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah 😄

Please sign in to comment.