From b9f916430873d537aa8786ea55bdadf772909dc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sun, 17 Apr 2022 18:15:49 -0400 Subject: [PATCH] fix: #10502, allow unblocking admin/mod if they were blocked before becoming admin/mod it wasn't possible to unblock them --- src/socket.io/user/profile.js | 7 ++----- src/user/blocks.js | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/socket.io/user/profile.js b/src/socket.io/user/profile.js index 1d65e814ab..2dcbb1af03 100644 --- a/src/socket.io/user/profile.js +++ b/src/socket.io/user/profile.js @@ -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; }; diff --git a/src/user/blocks.js b/src/user/blocks.js index 7eef264e20..6655965f2a 100644 --- a/src/user/blocks.js +++ b/src/user/blocks.js @@ -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) {