isAdminOrMod

v1.18.x
barisusakli 10 years ago
parent de2f336d53
commit c0c38437a0

@ -4,17 +4,15 @@ var async = require('async'),
db = require('../database'), db = require('../database'),
user = require('../user'), user = require('../user'),
topics = require('../topics'), topics = require('../topics'),
plugins = require('../plugins'); plugins = require('../plugins'),
privileges = require('../privileges');
module.exports = function(Categories) { module.exports = function(Categories) {
Categories.getCategoryTopics = function(data, callback) { Categories.getCategoryTopics = function(data, callback) {
async.parallel({ async.parallel({
isAdmin: function(next) { isAdminOrMod: function(next) {
user.isAdministrator(data.uid, next); privileges.categories.isAdminOrMod(data.cid, data.uid, next);
},
isModerator: function(next) {
user.isModerator(data.uid, data.cid, next);
}, },
topics: function(next) { topics: function(next) {
async.waterfall([ async.waterfall([
@ -47,9 +45,9 @@ module.exports = function(Categories) {
if (err) { if (err) {
return callback(err); return callback(err);
} }
var isAdminOrMod = results.isAdmin || results.isModerator;
results.topics.forEach(function(topic) { 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.title = '[[topic:topic_is_deleted]]';
topic.slug = topic.tid; topic.slug = topic.tid;
topic.teaser = null; topic.teaser = null;

@ -90,39 +90,25 @@ SocketPosts.getVoters = function(socket, data, callback) {
return callback(new Error('[[error:invalid-data]]')); return callback(new Error('[[error:invalid-data]]'));
} }
var pid = data.pid, async.waterfall([
cid = data.cid; function (next) {
privileges.categories.isAdminOrMod(data.cid, socket.uid, next);
async.parallel({
isAdmin: function(next) {
user.isAdministrator(socket.uid, next);
}, },
isModerator: function(next) { function (isAdminOrMod, next) {
user.isModerator(socket.uid, cid, next); if (!isAdminOrMod) {
} return next(new Error('[[error:no-privileges]]'));
}, function(err, tests) {
if (err) {
return callback(err);
}
if (tests.isAdmin || tests.isModerator) {
getVoters(pid, callback);
} }
});
};
function getVoters(pid, callback) {
async.parallel({ async.parallel({
upvoteUids: function(next) { upvoteUids: function(next) {
db.getSetMembers('pid:' + pid + ':upvote', next); db.getSetMembers('pid:' + data.pid + ':upvote', next);
}, },
downvoteUids: function(next) { downvoteUids: function(next) {
db.getSetMembers('pid:' + pid + ':downvote', next); db.getSetMembers('pid:' + data.pid + ':downvote', next);
}
}, function(err, results) {
if (err) {
return callback(err);
} }
}, next);
},
function (results, next) {
async.parallel({ async.parallel({
upvoters: function(next) { upvoters: function(next) {
user.getMultipleUserFields(results.upvoteUids, ['username', 'userslug', 'picture'], next); user.getMultipleUserFields(results.upvoteUids, ['username', 'userslug', 'picture'], next);
@ -136,9 +122,10 @@ function getVoters(pid, callback) {
downvoteCount: function(next) { downvoteCount: function(next) {
next(null, results.downvoteUids.length); next(null, results.downvoteUids.length);
} }
}, callback); }, next);
}); }
} ], callback);
};
SocketPosts.upvote = function(socket, data, callback) { SocketPosts.upvote = function(socket, data, callback) {
favouriteCommand(socket, 'upvote', 'voted', 'notifications:upvoted_your_post_in', 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) { function(next) {
async.parallel({ async.parallel({
isAdmin: function(next) { isAdminOrMod: function(next) {
user.isAdministrator(socket.uid, next); privileges.categories.isAdminOrMod(post.topic.cid, next);
},
isModerator: function(next) {
user.isModerator(socket.uid, post.topic.cid, next);
}, },
userData: function(next) { userData: function(next) {
user.getUserFields(socket.uid, ['username', 'reputation'], next); user.getUserFields(socket.uid, ['username', 'reputation'], next);
@ -512,7 +496,7 @@ SocketPosts.flag = function(socket, pid, callback) {
}, next); }, next);
}, },
function(user, 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]]')); return next(new Error('[[error:not-enough-reputation-to-flag]]'));
} }

@ -42,16 +42,13 @@ module.exports = function(Topics) {
postData: function(next) { postData: function(next) {
posts.getPostData(mainPid, next); posts.getPostData(mainPid, next);
}, },
isAdmin: function(next) { isAdminOrMod: function(next) {
user.isAdministrator(uid, next); privileges.categories.isAdminOrMod(cid, uid, next);
},
isModerator: function(next) {
user.isModerator(uid, cid, next);
} }
}, next); }, next);
}, },
function(results, next) { function(results, next) {
if (!results.isAdmin && !results.isModerator) { if (!results.isAdminOrMod) {
return next(new Error('[[error:no-privileges]]')); return next(new Error('[[error:no-privileges]]'));
} }
Topics.create({uid: results.postData.uid, title: title, cid: cid}, next); Topics.create({uid: results.postData.uid, title: title, cid: cid}, next);

@ -2,7 +2,8 @@
var async = require('async'), var async = require('async'),
db = require('../database'), db = require('../database'),
meta = require('../meta'); meta = require('../meta'),
privileges = require('../privileges');
module.exports = function(User) { module.exports = function(User) {
@ -18,11 +19,8 @@ module.exports = function(User) {
exists: function(next) { exists: function(next) {
db.exists('user:' + uid, next); db.exists('user:' + uid, next);
}, },
isAdmin: function(next) { isAdminOrMod: function(next) {
User.isAdministrator(uid, next); privileges.categories.isAdminOrMod(cid, uid, next);
},
isModerator: function(next) {
User.isModerator(uid, cid, next);
} }
}, function(err, results) { }, function(err, results) {
if (err) { if (err) {
@ -33,7 +31,7 @@ module.exports = function(User) {
return callback(new Error('[[error:no-user]]')); return callback(new Error('[[error:no-user]]'));
} }
if (results.isAdmin || results.isModerator) { if (results.isAdminOrMod) {
return callback(); return callback();
} }
@ -46,6 +44,7 @@ module.exports = function(User) {
if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && parseInt(userData['email:confirmed'], 10) !== 1) { if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && parseInt(userData['email:confirmed'], 10) !== 1) {
return callback(new Error('[[error:email-not-confirmed]]')); return callback(new Error('[[error:email-not-confirmed]]'));
} }
var now = Date.now(); var now = Date.now();
if (now - parseInt(userData.joindate, 10) < parseInt(meta.config.initialPostDelay, 10) * 1000) { if (now - parseInt(userData.joindate, 10) < parseInt(meta.config.initialPostDelay, 10) * 1000) {
return callback(new Error('[[error:user-too-new, ' + meta.config.initialPostDelay + ']]')); return callback(new Error('[[error:user-too-new, ' + meta.config.initialPostDelay + ']]'));

Loading…
Cancel
Save