mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
isAdminOrMod
This commit is contained in:
@@ -4,17 +4,15 @@ var async = require('async'),
|
||||
db = require('../database'),
|
||||
user = require('../user'),
|
||||
topics = require('../topics'),
|
||||
plugins = require('../plugins');
|
||||
plugins = require('../plugins'),
|
||||
privileges = require('../privileges');
|
||||
|
||||
module.exports = function(Categories) {
|
||||
|
||||
Categories.getCategoryTopics = function(data, callback) {
|
||||
async.parallel({
|
||||
isAdmin: function(next) {
|
||||
user.isAdministrator(data.uid, next);
|
||||
},
|
||||
isModerator: function(next) {
|
||||
user.isModerator(data.uid, data.cid, next);
|
||||
isAdminOrMod: function(next) {
|
||||
privileges.categories.isAdminOrMod(data.cid, data.uid, next);
|
||||
},
|
||||
topics: function(next) {
|
||||
async.waterfall([
|
||||
@@ -47,9 +45,9 @@ module.exports = function(Categories) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
var isAdminOrMod = results.isAdmin || results.isModerator;
|
||||
|
||||
results.topics.forEach(function(topic) {
|
||||
if (!(!topic.deleted || isAdminOrMod || topic.isOwner)) {
|
||||
if (!(!topic.deleted || results.isAdminOrMod || topic.isOwner)) {
|
||||
topic.title = '[[topic:topic_is_deleted]]';
|
||||
topic.slug = topic.tid;
|
||||
topic.teaser = null;
|
||||
|
||||
@@ -90,39 +90,25 @@ SocketPosts.getVoters = function(socket, data, callback) {
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
var pid = data.pid,
|
||||
cid = data.cid;
|
||||
|
||||
async.parallel({
|
||||
isAdmin: function(next) {
|
||||
user.isAdministrator(socket.uid, next);
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
privileges.categories.isAdminOrMod(data.cid, socket.uid, next);
|
||||
},
|
||||
isModerator: function(next) {
|
||||
user.isModerator(socket.uid, cid, next);
|
||||
}
|
||||
}, function(err, tests) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
function (isAdminOrMod, next) {
|
||||
if (!isAdminOrMod) {
|
||||
return next(new Error('[[error:no-privileges]]'));
|
||||
}
|
||||
|
||||
if (tests.isAdmin || tests.isModerator) {
|
||||
getVoters(pid, callback);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function getVoters(pid, callback) {
|
||||
async.parallel({
|
||||
upvoteUids: function(next) {
|
||||
db.getSetMembers('pid:' + pid + ':upvote', next);
|
||||
db.getSetMembers('pid:' + data.pid + ':upvote', next);
|
||||
},
|
||||
downvoteUids: function(next) {
|
||||
db.getSetMembers('pid:' + pid + ':downvote', next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
db.getSetMembers('pid:' + data.pid + ':downvote', next);
|
||||
}
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
async.parallel({
|
||||
upvoters: function(next) {
|
||||
user.getMultipleUserFields(results.upvoteUids, ['username', 'userslug', 'picture'], next);
|
||||
@@ -136,9 +122,10 @@ function getVoters(pid, callback) {
|
||||
downvoteCount: function(next) {
|
||||
next(null, results.downvoteUids.length);
|
||||
}
|
||||
}, callback);
|
||||
});
|
||||
}
|
||||
}, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
SocketPosts.upvote = function(socket, data, callback) {
|
||||
favouriteCommand(socket, 'upvote', 'voted', 'notifications:upvoted_your_post_in', data, callback);
|
||||
@@ -500,11 +487,8 @@ SocketPosts.flag = function(socket, pid, callback) {
|
||||
},
|
||||
function(next) {
|
||||
async.parallel({
|
||||
isAdmin: function(next) {
|
||||
user.isAdministrator(socket.uid, next);
|
||||
},
|
||||
isModerator: function(next) {
|
||||
user.isModerator(socket.uid, post.topic.cid, next);
|
||||
isAdminOrMod: function(next) {
|
||||
privileges.categories.isAdminOrMod(post.topic.cid, next);
|
||||
},
|
||||
userData: function(next) {
|
||||
user.getUserFields(socket.uid, ['username', 'reputation'], next);
|
||||
@@ -512,7 +496,7 @@ SocketPosts.flag = function(socket, pid, callback) {
|
||||
}, next);
|
||||
},
|
||||
function(user, next) {
|
||||
if (!user.isAdmin && !user.isModerator && parseInt(user.userData.reputation, 10) < parseInt(meta.config['privileges:flag'] || 1, 10)) {
|
||||
if (!user.isAdminOrMod && parseInt(user.userData.reputation, 10) < parseInt(meta.config['privileges:flag'] || 1, 10)) {
|
||||
return next(new Error('[[error:not-enough-reputation-to-flag]]'));
|
||||
}
|
||||
|
||||
|
||||
@@ -42,16 +42,13 @@ module.exports = function(Topics) {
|
||||
postData: function(next) {
|
||||
posts.getPostData(mainPid, next);
|
||||
},
|
||||
isAdmin: function(next) {
|
||||
user.isAdministrator(uid, next);
|
||||
},
|
||||
isModerator: function(next) {
|
||||
user.isModerator(uid, cid, next);
|
||||
isAdminOrMod: function(next) {
|
||||
privileges.categories.isAdminOrMod(cid, uid, next);
|
||||
}
|
||||
}, next);
|
||||
},
|
||||
function(results, next) {
|
||||
if (!results.isAdmin && !results.isModerator) {
|
||||
if (!results.isAdminOrMod) {
|
||||
return next(new Error('[[error:no-privileges]]'));
|
||||
}
|
||||
Topics.create({uid: results.postData.uid, title: title, cid: cid}, next);
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
var async = require('async'),
|
||||
db = require('../database'),
|
||||
meta = require('../meta');
|
||||
meta = require('../meta'),
|
||||
privileges = require('../privileges');
|
||||
|
||||
module.exports = function(User) {
|
||||
|
||||
@@ -18,11 +19,8 @@ module.exports = function(User) {
|
||||
exists: function(next) {
|
||||
db.exists('user:' + uid, next);
|
||||
},
|
||||
isAdmin: function(next) {
|
||||
User.isAdministrator(uid, next);
|
||||
},
|
||||
isModerator: function(next) {
|
||||
User.isModerator(uid, cid, next);
|
||||
isAdminOrMod: function(next) {
|
||||
privileges.categories.isAdminOrMod(cid, uid, next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
if (err) {
|
||||
@@ -33,7 +31,7 @@ module.exports = function(User) {
|
||||
return callback(new Error('[[error:no-user]]'));
|
||||
}
|
||||
|
||||
if (results.isAdmin || results.isModerator) {
|
||||
if (results.isAdminOrMod) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
@@ -46,6 +44,7 @@ module.exports = function(User) {
|
||||
if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && parseInt(userData['email:confirmed'], 10) !== 1) {
|
||||
return callback(new Error('[[error:email-not-confirmed]]'));
|
||||
}
|
||||
|
||||
var now = Date.now();
|
||||
if (now - parseInt(userData.joindate, 10) < parseInt(meta.config.initialPostDelay, 10) * 1000) {
|
||||
return callback(new Error('[[error:user-too-new, ' + meta.config.initialPostDelay + ']]'));
|
||||
|
||||
Reference in New Issue
Block a user