From 1bda90731aed8f0ee3d2ef665db8348c4a93a669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Wed, 5 Jul 2023 15:24:34 -0400 Subject: [PATCH] fix: #11766, allow privileged users to vote and chat even if they don't have enough reputation --- src/messaging/index.js | 7 +++++-- src/posts/votes.js | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/messaging/index.js b/src/messaging/index.js index 729ec8fedf..e532043a12 100644 --- a/src/messaging/index.js +++ b/src/messaging/index.js @@ -292,8 +292,11 @@ async function checkReputation(uid) { if (meta.config['reputation:disabled']) { return; } - const reputation = await user.getUserField(uid, 'reputation'); - if (meta.config['min:rep:chat'] > reputation) { + const [reputation, isPrivileged] = await Promise.all([ + user.getUserField(uid, 'reputation'), + user.isPrivileged(uid), + ]); + if (!isPrivileged && meta.config['min:rep:chat'] > reputation) { throw new Error(`[[error:not-enough-reputation-to-chat, ${meta.config['min:rep:chat']}]]`); } } diff --git a/src/posts/votes.js b/src/posts/votes.js index dfdfad2899..bfe5e1e47f 100644 --- a/src/posts/votes.js +++ b/src/posts/votes.js @@ -142,14 +142,17 @@ module.exports = function (Posts) { async function checkVoteLimitation(pid, uid, type) { // type = 'upvote' or 'downvote' const oneDay = 86400000; - const [reputation, targetUid, votedPidsToday] = await Promise.all([ + const [reputation, isPrivileged, targetUid, votedPidsToday] = await Promise.all([ user.getUserField(uid, 'reputation'), + user.isPrivileged(uid), Posts.getPostField(pid, 'uid'), db.getSortedSetRevRangeByScore( `uid:${uid}:${type}`, 0, -1, '+inf', Date.now() - oneDay ), ]); - + if (isPrivileged) { + return; + } if (reputation < meta.config[`min:rep:${type}`]) { throw new Error(`[[error:not-enough-reputation-to-${type}, ${meta.config[`min:rep:${type}`]}]]`); }