fix: #10502, allow unblocking admin/mod

if they were blocked before becoming admin/mod it wasn't possible to unblock them
isekai-main
Barış Soner Uşaklı 3 years ago
parent b28f9f776a
commit b9f9164308

@ -45,11 +45,8 @@ module.exports = function (SocketUser) {
};
SocketUser.toggleBlock = async function (socket, data) {
const [is] = await Promise.all([
user.blocks.is(data.blockeeUid, data.blockerUid),
user.blocks.can(socket.uid, data.blockerUid, data.blockeeUid),
]);
const isBlocked = is;
const isBlocked = await user.blocks.is(data.blockeeUid, data.blockerUid);
await user.blocks.can(socket.uid, data.blockerUid, data.blockeeUid, isBlocked ? 'unblock' : 'block');
await user.blocks[isBlocked ? 'remove' : 'add'](data.blockeeUid, data.blockerUid);
return !isBlocked;
};

@ -22,7 +22,7 @@ module.exports = function (User) {
return isArray ? isBlocked : isBlocked[0];
};
User.blocks.can = async function (callerUid, blockerUid, blockeeUid) {
User.blocks.can = async function (callerUid, blockerUid, blockeeUid, type) {
// Guests can't block
if (blockerUid === 0 || blockeeUid === 0) {
throw new Error('[[error:cannot-block-guest]]');
@ -36,7 +36,7 @@ module.exports = function (User) {
User.isAdminOrGlobalMod(callerUid),
User.isAdminOrGlobalMod(blockeeUid),
]);
if (isBlockeeAdminOrMod) {
if (isBlockeeAdminOrMod && type === 'block') {
throw new Error('[[error:cannot-block-privileged]]');
}
if (parseInt(callerUid, 10) !== parseInt(blockerUid, 10) && !isCallerAdminOrMod) {

Loading…
Cancel
Save