mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: #11766, allow privileged users to vote and chat
even if they don't have enough reputation
This commit is contained in:
@@ -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']}]]`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}`]}]]`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user