mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 04:25:55 +01:00
removed extra isAdminOrMod check
This commit is contained in:
@@ -5,57 +5,49 @@ var async = require('async');
|
|||||||
var db = require('../database');
|
var db = require('../database');
|
||||||
var topics = require('../topics');
|
var topics = require('../topics');
|
||||||
var plugins = require('../plugins');
|
var plugins = require('../plugins');
|
||||||
var privileges = require('../privileges');
|
|
||||||
|
|
||||||
module.exports = function(Categories) {
|
module.exports = function(Categories) {
|
||||||
|
|
||||||
Categories.getCategoryTopics = function(data, callback) {
|
Categories.getCategoryTopics = function(data, callback) {
|
||||||
async.parallel({
|
async.waterfall([
|
||||||
isAdminOrMod: function(next) {
|
function (next) {
|
||||||
privileges.categories.isAdminOrMod(data.cid, data.uid, next);
|
plugins.fireHook('filter:category.topics.prepare', data, next);
|
||||||
},
|
},
|
||||||
topics: function(next) {
|
function (data, next) {
|
||||||
async.waterfall([
|
Categories.getTopicIds(data.set, data.reverse, data.start, data.stop, next);
|
||||||
function(next) {
|
},
|
||||||
plugins.fireHook('filter:category.topics.prepare', data, next);
|
function (tids, next) {
|
||||||
},
|
topics.getTopicsByTids(tids, data.uid, next);
|
||||||
function(data, next) {
|
},
|
||||||
Categories.getTopicIds(data.set, data.reverse, data.start, data.stop, next);
|
function (topics, next) {
|
||||||
},
|
if (!Array.isArray(topics) || !topics.length) {
|
||||||
function(tids, next) {
|
return next(null, {topics: [], uid: data.uid});
|
||||||
topics.getTopicsByTids(tids, data.uid, next);
|
|
||||||
},
|
|
||||||
function(topics, next) {
|
|
||||||
if (!Array.isArray(topics) || !topics.length) {
|
|
||||||
return next(null, {topics: [], uid: data.uid});
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i=0; i<topics.length; ++i) {
|
|
||||||
topics[i].index = data.start + i;
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins.fireHook('filter:category.topics.get', {topics: topics, uid: data.uid}, next);
|
|
||||||
},
|
|
||||||
function(results, next) {
|
|
||||||
next(null, results.topics);
|
|
||||||
}
|
|
||||||
], next);
|
|
||||||
}
|
|
||||||
}, function(err, results) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
results.topics.forEach(function(topic) {
|
|
||||||
if (!(!topic.deleted || results.isAdminOrMod || topic.isOwner)) {
|
|
||||||
topic.title = '[[topic:topic_is_deleted]]';
|
|
||||||
topic.slug = topic.tid;
|
|
||||||
topic.teaser = null;
|
|
||||||
topic.noAnchor = true;
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
callback(null, {topics: results.topics, nextStart: data.stop + 1});
|
for (var i=0; i<topics.length; ++i) {
|
||||||
|
topics[i].index = data.start + i;
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins.fireHook('filter:category.topics.get', {topics: topics, uid: data.uid}, next);
|
||||||
|
},
|
||||||
|
function (results, next) {
|
||||||
|
next(null, {topics: results.topics, nextStart: data.stop + 1});
|
||||||
|
}
|
||||||
|
], callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
Categories.modifyTopicsByPrivilege = function(topics, privileges) {
|
||||||
|
if (!Array.isArray(topics) || !topics.length || privileges.isAdminOrMod) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
topics.forEach(function(topic) {
|
||||||
|
if (topic.deleted && !topic.isOwner) {
|
||||||
|
topic.title = '[[topic:topic_is_deleted]]';
|
||||||
|
topic.slug = topic.tid;
|
||||||
|
topic.teaser = null;
|
||||||
|
topic.noAnchor = true;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -111,6 +111,9 @@ categoryController.get = function(req, res, callback) {
|
|||||||
categories.getCategoryById(payload, next);
|
categories.getCategoryById(payload, next);
|
||||||
},
|
},
|
||||||
function (categoryData, next) {
|
function (categoryData, next) {
|
||||||
|
|
||||||
|
categories.modifyTopicsByPrivilege(categoryData.topics, userPrivileges);
|
||||||
|
|
||||||
if (categoryData.link) {
|
if (categoryData.link) {
|
||||||
db.incrObjectField('category:' + categoryData.cid, 'timesClicked');
|
db.incrObjectField('category:' + categoryData.cid, 'timesClicked');
|
||||||
return res.redirect(categoryData.link);
|
return res.redirect(categoryData.link);
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ topicsController.get = function(req, res, callback) {
|
|||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
topics.modifyByPrivilege(topicData.posts, userPrivileges);
|
topics.modifyPostsByPrivilege(topicData.posts, userPrivileges);
|
||||||
|
|
||||||
plugins.fireHook('filter:controllers.topic.get', {topicData: topicData, uid: req.uid}, next);
|
plugins.fireHook('filter:controllers.topic.get', {topicData: topicData, uid: req.uid}, next);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ function generateForTopic(req, res, callback) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
topics.modifyByPrivilege(topicData.posts, userPrivileges);
|
topics.modifyPostsByPrivilege(topicData.posts, userPrivileges);
|
||||||
|
|
||||||
var description = topicData.posts.length ? topicData.posts[0].content : '';
|
var description = topicData.posts.length ? topicData.posts[0].content : '';
|
||||||
var image_url = topicData.posts.length ? topicData.posts[0].picture : '';
|
var image_url = topicData.posts.length ? topicData.posts[0].picture : '';
|
||||||
|
|||||||
@@ -119,6 +119,8 @@ SocketCategories.loadMore = function(socket, data, callback) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
categories.modifyTopicsByPrivilege(data.topics, results.privileges);
|
||||||
|
|
||||||
data.privileges = results.privileges;
|
data.privileges = results.privileges;
|
||||||
data.template = {
|
data.template = {
|
||||||
category: true,
|
category: true,
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ module.exports = function(SocketTopics) {
|
|||||||
topicData['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1;
|
topicData['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1;
|
||||||
topicData['downvote:disabled'] = parseInt(meta.config['downvote:disabled'], 10) === 1;
|
topicData['downvote:disabled'] = parseInt(meta.config['downvote:disabled'], 10) === 1;
|
||||||
|
|
||||||
topics.modifyByPrivilege(topicData.posts, results.privileges);
|
topics.modifyPostsByPrivilege(topicData.posts, results.privileges);
|
||||||
callback(null, topicData);
|
callback(null, topicData);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ module.exports = function(Topics) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Topics.modifyByPrivilege = function(postData, topicPrivileges) {
|
Topics.modifyPostsByPrivilege = function(postData, topicPrivileges) {
|
||||||
postData.forEach(function(post) {
|
postData.forEach(function(post) {
|
||||||
if (post) {
|
if (post) {
|
||||||
post.display_moderator_tools = topicPrivileges.isAdminOrMod || post.selfPost;
|
post.display_moderator_tools = topicPrivileges.isAdminOrMod || post.selfPost;
|
||||||
|
|||||||
Reference in New Issue
Block a user