mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 04:25:55 +01:00
redirect if category is accessed directly
This commit is contained in:
@@ -45,11 +45,6 @@ var db = require('./database.js'),
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
var category_name = categoryData.name,
|
|
||||||
category_slug = categoryData.slug,
|
|
||||||
disabled = categoryData.disabled || '0',
|
|
||||||
category_description = categoryData.description;
|
|
||||||
|
|
||||||
function getTopicIds(next) {
|
function getTopicIds(next) {
|
||||||
Categories.getTopicIds(category_id, 0, 19, next);
|
Categories.getTopicIds(category_id, 0, 19, next);
|
||||||
}
|
}
|
||||||
@@ -69,10 +64,11 @@ var db = require('./database.js'),
|
|||||||
active_users = results[1],
|
active_users = results[1],
|
||||||
sidebars = results[2];
|
sidebars = results[2];
|
||||||
|
|
||||||
var categoryData = {
|
var category = {
|
||||||
'category_name': category_name,
|
'category_name': categoryData.name,
|
||||||
'category_description': category_description,
|
'category_description': categoryData.description,
|
||||||
'disabled': disabled,
|
'link': categoryData.link,
|
||||||
|
'disabled': categoryData.disabled || '0',
|
||||||
'show_sidebar': 'show',
|
'show_sidebar': 'show',
|
||||||
'show_topic_button': 'inline-block',
|
'show_topic_button': 'inline-block',
|
||||||
'no_topics_message': 'hidden',
|
'no_topics_message': 'hidden',
|
||||||
@@ -81,9 +77,9 @@ var db = require('./database.js'),
|
|||||||
'active_users': [],
|
'active_users': [],
|
||||||
'topics': [],
|
'topics': [],
|
||||||
'disableSocialButtons': meta.config.disableSocialButtons !== undefined ? parseInt(meta.config.disableSocialButtons, 10) !== 0 : false,
|
'disableSocialButtons': meta.config.disableSocialButtons !== undefined ? parseInt(meta.config.disableSocialButtons, 10) !== 0 : false,
|
||||||
'twitter-intent-url': 'https://twitter.com/intent/tweet?url=' + encodeURIComponent(nconf.get('url') + 'category/' + category_slug) + '&text=' + encodeURIComponent(category_name),
|
'twitter-intent-url': 'https://twitter.com/intent/tweet?url=' + encodeURIComponent(nconf.get('url') + 'category/' + categoryData.slug) + '&text=' + encodeURIComponent(categoryData.name),
|
||||||
'facebook-share-url': 'https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(nconf.get('url') + 'category/' + category_slug),
|
'facebook-share-url': 'https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(nconf.get('url') + 'category/' + categoryData.slug),
|
||||||
'google-share-url': 'https://plus.google.com/share?url=' + encodeURIComponent(nconf.get('url') + 'category/' + category_slug),
|
'google-share-url': 'https://plus.google.com/share?url=' + encodeURIComponent(nconf.get('url') + 'category/' + categoryData.slug),
|
||||||
'sidebars': sidebars
|
'sidebars': sidebars
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -105,20 +101,20 @@ var db = require('./database.js'),
|
|||||||
|
|
||||||
if (tids.length === 0) {
|
if (tids.length === 0) {
|
||||||
getModerators(function(err, moderators) {
|
getModerators(function(err, moderators) {
|
||||||
categoryData.moderator_block_class = moderators.length > 0 ? '' : 'none';
|
category.moderator_block_class = moderators.length > 0 ? '' : 'none';
|
||||||
categoryData.moderators = moderators;
|
category.moderators = moderators;
|
||||||
categoryData.show_sidebar = 'hidden';
|
category.show_sidebar = 'hidden';
|
||||||
categoryData.no_topics_message = 'show';
|
category.no_topics_message = 'show';
|
||||||
callback(null, categoryData);
|
callback(null, category);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
async.parallel([getTopics, getModerators, getActiveUsers], function(err, results) {
|
async.parallel([getTopics, getModerators, getActiveUsers], function(err, results) {
|
||||||
categoryData.topics = results[0];
|
category.topics = results[0];
|
||||||
categoryData.moderator_block_class = results[1].length > 0 ? '' : 'none';
|
category.moderator_block_class = results[1].length > 0 ? '' : 'none';
|
||||||
categoryData.moderators = results[1];
|
category.moderators = results[1];
|
||||||
categoryData.active_users = results[2];
|
category.active_users = results[2];
|
||||||
categoryData.show_sidebar = categoryData.topics.length > 0 ? 'show' : 'hidden';
|
category.show_sidebar = category.topics.length > 0 ? 'show' : 'hidden';
|
||||||
callback(null, categoryData);
|
callback(null, category);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -158,7 +158,11 @@ var path = require('path'),
|
|||||||
groups.getCategoryAccess(req.params.id, uid, function(err, access){
|
groups.getCategoryAccess(req.params.id, uid, function(err, access){
|
||||||
if (access){
|
if (access){
|
||||||
categories.getCategoryById(req.params.id, uid, function (err, data) {
|
categories.getCategoryById(req.params.id, uid, function (err, data) {
|
||||||
if (!err && data && parseInt(data.disabled, 10) === 0) {
|
if(err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data && parseInt(data.disabled, 10) === 0) {
|
||||||
res.json(data);
|
res.json(data);
|
||||||
} else {
|
} else {
|
||||||
next();
|
next();
|
||||||
|
|||||||
@@ -720,6 +720,10 @@ if(nconf.get('ssl')) {
|
|||||||
return res.redirect('404');
|
return res.redirect('404');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(data.categories.link) {
|
||||||
|
return res.redirect(data.categories.link);
|
||||||
|
}
|
||||||
|
|
||||||
var category_url = cid + (req.params.slug ? '/' + req.params.slug : '');
|
var category_url = cid + (req.params.slug ? '/' + req.params.slug : '');
|
||||||
|
|
||||||
res.send(
|
res.send(
|
||||||
|
|||||||
Reference in New Issue
Block a user