fix: #11766, allow privileged users to vote and chat

even if they don't have enough reputation
isekai-main
Barış Soner Uşaklı 2 years ago
parent a1110f10bd
commit 1bda90731a

@ -292,8 +292,11 @@ async function checkReputation(uid) {
if (meta.config['reputation:disabled']) { if (meta.config['reputation:disabled']) {
return; return;
} }
const reputation = await user.getUserField(uid, 'reputation'); const [reputation, isPrivileged] = await Promise.all([
if (meta.config['min:rep:chat'] > reputation) { 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']}]]`); 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) { async function checkVoteLimitation(pid, uid, type) {
// type = 'upvote' or 'downvote' // type = 'upvote' or 'downvote'
const oneDay = 86400000; const oneDay = 86400000;
const [reputation, targetUid, votedPidsToday] = await Promise.all([ const [reputation, isPrivileged, targetUid, votedPidsToday] = await Promise.all([
user.getUserField(uid, 'reputation'), user.getUserField(uid, 'reputation'),
user.isPrivileged(uid),
Posts.getPostField(pid, 'uid'), Posts.getPostField(pid, 'uid'),
db.getSortedSetRevRangeByScore( db.getSortedSetRevRangeByScore(
`uid:${uid}:${type}`, 0, -1, '+inf', Date.now() - oneDay `uid:${uid}:${type}`, 0, -1, '+inf', Date.now() - oneDay
), ),
]); ]);
if (isPrivileged) {
return;
}
if (reputation < meta.config[`min:rep:${type}`]) { if (reputation < meta.config[`min:rep:${type}`]) {
throw new Error(`[[error:not-enough-reputation-to-${type}, ${meta.config[`min:rep:${type}`]}]]`); throw new Error(`[[error:not-enough-reputation-to-${type}, ${meta.config[`min:rep:${type}`]}]]`);
} }

Loading…
Cancel
Save