mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-01 21:30:30 +01:00
fix: #10502, allow unblocking admin/mod
if they were blocked before becoming admin/mod it wasn't possible to unblock them
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user