updating privilege handling to fire two new hooks, filter:privileges.topics.get and filter:category.topics.get

v1.18.x
Julian Lam 10 years ago
parent eada3daf9f
commit c0fc7e9ca4

@ -2,14 +2,16 @@
var async = require('async'),
db = require('../database'),
topics = require('../topics');
topics = require('../topics'),
plugins = require('../plugins');
module.exports = function(Categories) {
Categories.getCategoryTopics = function(data, callback) {
var tids;
async.waterfall([
function(next) {
async.apply(plugins.fireHook, 'filter:category.topics.get', data),
function(data, next) {
Categories.getTopicIds(data.targetUid ? 'cid:' + data.cid + ':uid:' + data.targetUid + ':tids' : 'cid:' + data.cid + ':tids', data.start, data.stop, next);
},
function(topicIds, next) {

@ -8,60 +8,48 @@ var async = require('async'),
user = require('../user'),
helpers = require('./helpers'),
groups = require('../groups'),
categories = require('../categories');
categories = require('../categories'),
plugins = require('../plugins');
module.exports = function(privileges) {
privileges.topics = {};
privileges.topics.get = function(tid, uid, callback) {
topics.getTopicField(tid, 'cid', function(err, cid) {
async.waterfall([
async.apply(topics.getTopicField, tid, 'cid'),
function(cid, next) {
async.parallel({
'topics:reply': async.apply(helpers.isUserAllowedTo, 'topics:reply', uid, [cid]),
read: async.apply(helpers.isUserAllowedTo, 'read', uid, [cid]),
isOwner: async.apply(topics.isOwner, tid, uid),
manage_topic: async.apply(helpers.hasEnoughReputationFor, 'privileges:manage_topic', uid),
isAdministrator: async.apply(user.isAdministrator, uid),
isModerator: async.apply(user.isModerator, uid, cid),
disabled: async.apply(categories.getCategoryField, cid, 'disabled')
}, next);
}
], function(err, results) {
if (err) {
return callback(err);
}
async.parallel({
'topics:reply': function(next) {
helpers.isUserAllowedTo('topics:reply', uid, [cid], next);
},
read: function(next) {
helpers.isUserAllowedTo('read', uid, [cid], next);
},
isOwner: function(next) {
topics.isOwner(tid, uid, next);
},
manage_topic: function(next) {
helpers.hasEnoughReputationFor('privileges:manage_topic', uid, next);
},
isAdministrator: function(next) {
user.isAdministrator(uid, next);
},
isModerator: function(next) {
user.isModerator(uid, cid, next);
},
disabled: function(next) {
categories.getCategoryField(cid, 'disabled', next);
}
}, function(err, results) {
if(err) {
return callback(err);
}
var disabled = parseInt(results.disabled, 10) === 1;
var isAdminOrMod = results.isAdministrator || results.isModerator;
var editable = isAdminOrMod || results.manage_topic;
var deletable = isAdminOrMod || results.isOwner;
callback(null, {
'topics:reply': results['topics:reply'][0] || isAdminOrMod,
read: results.read[0] || isAdminOrMod,
view_thread_tools: editable || deletable,
editable: editable,
deletable: deletable,
view_deleted: isAdminOrMod || results.manage_topic || results.isOwner,
disabled: disabled
});
});
var disabled = parseInt(results.disabled, 10) === 1;
var isAdminOrMod = results.isAdministrator || results.isModerator;
var editable = isAdminOrMod || results.manage_topic;
var deletable = isAdminOrMod || results.isOwner;
plugins.fireHook('filter:privileges.topics.get', {
'topics:reply': results['topics:reply'][0] || isAdminOrMod,
read: results.read[0] || isAdminOrMod,
view_thread_tools: editable || deletable,
editable: editable,
deletable: deletable,
view_deleted: isAdminOrMod || results.manage_topic || results.isOwner,
disabled: disabled,
tid: tid,
uid: uid
}, callback);
});
};

Loading…
Cancel
Save