mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-06 22:15:48 +01:00
updating privilege handling to fire two new hooks, filter:privileges.topics.get and filter:category.topics.get
This commit is contained in:
@@ -2,14 +2,16 @@
|
|||||||
|
|
||||||
var async = require('async'),
|
var async = require('async'),
|
||||||
db = require('../database'),
|
db = require('../database'),
|
||||||
topics = require('../topics');
|
topics = require('../topics'),
|
||||||
|
plugins = require('../plugins');
|
||||||
|
|
||||||
module.exports = function(Categories) {
|
module.exports = function(Categories) {
|
||||||
|
|
||||||
Categories.getCategoryTopics = function(data, callback) {
|
Categories.getCategoryTopics = function(data, callback) {
|
||||||
var tids;
|
var tids;
|
||||||
async.waterfall([
|
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);
|
Categories.getTopicIds(data.targetUid ? 'cid:' + data.cid + ':uid:' + data.targetUid + ':tids' : 'cid:' + data.cid + ':tids', data.start, data.stop, next);
|
||||||
},
|
},
|
||||||
function(topicIds, next) {
|
function(topicIds, next) {
|
||||||
|
|||||||
@@ -8,60 +8,48 @@ var async = require('async'),
|
|||||||
user = require('../user'),
|
user = require('../user'),
|
||||||
helpers = require('./helpers'),
|
helpers = require('./helpers'),
|
||||||
groups = require('../groups'),
|
groups = require('../groups'),
|
||||||
categories = require('../categories');
|
categories = require('../categories'),
|
||||||
|
plugins = require('../plugins');
|
||||||
|
|
||||||
module.exports = function(privileges) {
|
module.exports = function(privileges) {
|
||||||
|
|
||||||
privileges.topics = {};
|
privileges.topics = {};
|
||||||
|
|
||||||
privileges.topics.get = function(tid, uid, callback) {
|
privileges.topics.get = function(tid, uid, callback) {
|
||||||
|
async.waterfall([
|
||||||
topics.getTopicField(tid, 'cid', function(err, cid) {
|
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) {
|
if (err) {
|
||||||
return callback(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 disabled = parseInt(results.disabled, 10) === 1;
|
||||||
var isAdminOrMod = results.isAdministrator || results.isModerator;
|
var isAdminOrMod = results.isAdministrator || results.isModerator;
|
||||||
var editable = isAdminOrMod || results.manage_topic;
|
var editable = isAdminOrMod || results.manage_topic;
|
||||||
var deletable = isAdminOrMod || results.isOwner;
|
var deletable = isAdminOrMod || results.isOwner;
|
||||||
|
|
||||||
callback(null, {
|
plugins.fireHook('filter:privileges.topics.get', {
|
||||||
'topics:reply': results['topics:reply'][0] || isAdminOrMod,
|
'topics:reply': results['topics:reply'][0] || isAdminOrMod,
|
||||||
read: results.read[0] || isAdminOrMod,
|
read: results.read[0] || isAdminOrMod,
|
||||||
view_thread_tools: editable || deletable,
|
view_thread_tools: editable || deletable,
|
||||||
editable: editable,
|
editable: editable,
|
||||||
deletable: deletable,
|
deletable: deletable,
|
||||||
view_deleted: isAdminOrMod || results.manage_topic || results.isOwner,
|
view_deleted: isAdminOrMod || results.manage_topic || results.isOwner,
|
||||||
disabled: disabled
|
disabled: disabled,
|
||||||
});
|
tid: tid,
|
||||||
});
|
uid: uid
|
||||||
|
}, callback);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user