|
|
|
@ -15,6 +15,7 @@ module.exports = function (privileges) {
|
|
|
|
|
privileges.topics = {};
|
|
|
|
|
|
|
|
|
|
privileges.topics.get = function (tid, uid, callback) {
|
|
|
|
|
uid = parseInt(uid, 10);
|
|
|
|
|
var topic;
|
|
|
|
|
var privs = ['topics:reply', 'topics:read', 'topics:tag', 'topics:delete', 'posts:edit', 'posts:history', 'posts:delete', 'posts:view_deleted', 'read', 'purge'];
|
|
|
|
|
async.waterfall([
|
|
|
|
@ -30,23 +31,20 @@ module.exports = function (privileges) {
|
|
|
|
|
},
|
|
|
|
|
function (results, next) {
|
|
|
|
|
var privData = _.zipObject(privs, results.privileges);
|
|
|
|
|
var disabled = parseInt(results.disabled, 10) === 1;
|
|
|
|
|
var locked = parseInt(topic.locked, 10) === 1;
|
|
|
|
|
var deleted = parseInt(topic.deleted, 10) === 1;
|
|
|
|
|
var isOwner = !!parseInt(uid, 10) && parseInt(uid, 10) === parseInt(topic.uid, 10);
|
|
|
|
|
var isOwner = uid > 0 && uid === topic.uid;
|
|
|
|
|
var isAdminOrMod = results.isAdministrator || results.isModerator;
|
|
|
|
|
var editable = isAdminOrMod;
|
|
|
|
|
var deletable = isAdminOrMod || (isOwner && privData['topics:delete']);
|
|
|
|
|
var purge = results.isAdministrator || privData.purge;
|
|
|
|
|
|
|
|
|
|
plugins.fireHook('filter:privileges.topics.get', {
|
|
|
|
|
'topics:reply': (privData['topics:reply'] && !locked && !deleted) || isAdminOrMod,
|
|
|
|
|
'topics:reply': (privData['topics:reply'] && !topic.locked && !topic.deleted) || isAdminOrMod,
|
|
|
|
|
'topics:read': privData['topics:read'] || isAdminOrMod,
|
|
|
|
|
'topics:tag': privData['topics:tag'] || isAdminOrMod,
|
|
|
|
|
'topics:delete': (isOwner && privData['topics:delete']) || isAdminOrMod,
|
|
|
|
|
'posts:edit': (privData['posts:edit'] && !locked) || isAdminOrMod,
|
|
|
|
|
'posts:edit': (privData['posts:edit'] && !topic.locked) || isAdminOrMod,
|
|
|
|
|
'posts:history': privData['posts:history'] || isAdminOrMod,
|
|
|
|
|
'posts:delete': (privData['posts:delete'] && !locked) || isAdminOrMod,
|
|
|
|
|
'posts:delete': (privData['posts:delete'] && !topic.locked) || isAdminOrMod,
|
|
|
|
|
'posts:view_deleted': privData['posts:view_deleted'] || isAdminOrMod,
|
|
|
|
|
read: privData.read || isAdminOrMod,
|
|
|
|
|
view_thread_tools: editable || deletable,
|
|
|
|
@ -55,7 +53,7 @@ module.exports = function (privileges) {
|
|
|
|
|
purge: purge,
|
|
|
|
|
view_deleted: isAdminOrMod || isOwner,
|
|
|
|
|
isAdminOrMod: isAdminOrMod,
|
|
|
|
|
disabled: disabled,
|
|
|
|
|
disabled: results.disabled,
|
|
|
|
|
tid: tid,
|
|
|
|
|
uid: uid,
|
|
|
|
|
}, next);
|
|
|
|
@ -146,8 +144,8 @@ module.exports = function (privileges) {
|
|
|
|
|
},
|
|
|
|
|
function (results, next) {
|
|
|
|
|
uids = uids.filter(function (uid, index) {
|
|
|
|
|
return parseInt(results.disabled, 10) !== 1 &&
|
|
|
|
|
((results.allowedTo[index] && parseInt(topicData.deleted, 10) !== 1) || results.isAdmins[index] || results.isModerators[index]);
|
|
|
|
|
return !results.disabled &&
|
|
|
|
|
((results.allowedTo[index] && !topicData.deleted) || results.isAdmins[index] || results.isModerators[index]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
next(null, uids);
|
|
|
|
|