|
|
|
@ -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);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|