mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-21 07:50:37 +01:00
closes #3508
This commit is contained in:
@@ -22,14 +22,10 @@ var fs = require('fs'),
|
|||||||
|
|
||||||
function getUserDataByUserSlug(userslug, callerUID, callback) {
|
function getUserDataByUserSlug(userslug, callerUID, callback) {
|
||||||
user.getUidByUserslug(userslug, function(err, uid) {
|
user.getUidByUserslug(userslug, function(err, uid) {
|
||||||
if (err) {
|
if (err || !uid) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!uid) {
|
|
||||||
return callback(null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
async.parallel({
|
async.parallel({
|
||||||
userData : function(next) {
|
userData : function(next) {
|
||||||
user.getUserData(uid, next);
|
user.getUserData(uid, next);
|
||||||
@@ -111,17 +107,13 @@ accountsController.getUserByUID = function(req, res, next) {
|
|||||||
var uid = req.params.uid ? req.params.uid : 0;
|
var uid = req.params.uid ? req.params.uid : 0;
|
||||||
|
|
||||||
async.parallel({
|
async.parallel({
|
||||||
settings: async.apply(user.getSettings, uid),
|
userData: async.apply(user.getUserData, uid),
|
||||||
userData: async.apply(user.getUserData, uid)
|
settings: async.apply(user.getSettings, uid)
|
||||||
}, function(err, results) {
|
}, function(err, results) {
|
||||||
if (err) {
|
if (err || !results.userData) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!results.userData) {
|
|
||||||
return helpers.notFound(req, res);
|
|
||||||
}
|
|
||||||
|
|
||||||
results.userData.email = results.settings.showemail ? results.userData.email : undefined;
|
results.userData.email = results.settings.showemail ? results.userData.email : undefined;
|
||||||
results.userData.fullname = results.settings.showfullname ? results.userData.fullname : undefined;
|
results.userData.fullname = results.settings.showfullname ? results.userData.fullname : undefined;
|
||||||
|
|
||||||
@@ -141,14 +133,10 @@ accountsController.getAccount = function(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getUserDataByUserSlug(req.params.userslug, req.uid, function (err, userData) {
|
getUserDataByUserSlug(req.params.userslug, req.uid, function (err, userData) {
|
||||||
if (err) {
|
if (err || !userData) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!userData) {
|
|
||||||
return helpers.notFound(req, res);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.uid !== parseInt(userData.uid, 10)) {
|
if (req.uid !== parseInt(userData.uid, 10)) {
|
||||||
user.incrementUserFieldBy(userData.uid, 'profileviews', 1);
|
user.incrementUserFieldBy(userData.uid, 'profileviews', 1);
|
||||||
}
|
}
|
||||||
@@ -208,7 +196,7 @@ accountsController.getFollowers = function(req, res, next) {
|
|||||||
getFollow('account/followers', 'followers', req, res, next);
|
getFollow('account/followers', 'followers', req, res, next);
|
||||||
};
|
};
|
||||||
|
|
||||||
function getFollow(tpl, name, req, res, next) {
|
function getFollow(tpl, name, req, res, callback) {
|
||||||
var userData;
|
var userData;
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
@@ -218,14 +206,14 @@ function getFollow(tpl, name, req, res, next) {
|
|||||||
function(data, next) {
|
function(data, next) {
|
||||||
userData = data;
|
userData = data;
|
||||||
if (!userData) {
|
if (!userData) {
|
||||||
return helpers.notFound(req, res);
|
return callback();
|
||||||
}
|
}
|
||||||
var method = name === 'following' ? 'getFollowing' : 'getFollowers';
|
var method = name === 'following' ? 'getFollowing' : 'getFollowers';
|
||||||
user[method](userData.uid, 0, 49, next);
|
user[method](userData.uid, 0, 49, next);
|
||||||
}
|
}
|
||||||
], function(err, users) {
|
], function(err, users) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
userData.users = users;
|
userData.users = users;
|
||||||
@@ -254,14 +242,10 @@ accountsController.getTopics = function(req, res, next) {
|
|||||||
|
|
||||||
accountsController.getGroups = function(req, res, next) {
|
accountsController.getGroups = function(req, res, next) {
|
||||||
accountsController.getBaseUser(req.params.userslug, req.uid, function(err, userData) {
|
accountsController.getBaseUser(req.params.userslug, req.uid, function(err, userData) {
|
||||||
if (err) {
|
if (err || !userData) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!userData) {
|
|
||||||
return helpers.notFound(req, res);
|
|
||||||
}
|
|
||||||
|
|
||||||
groups.getUserGroups([userData.uid], function(err, groupsData) {
|
groups.getUserGroups([userData.uid], function(err, groupsData) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
@@ -284,13 +268,11 @@ function getFromUserSet(tpl, set, method, type, req, res, next) {
|
|||||||
accountsController.getBaseUser(req.params.userslug, req.uid, next);
|
accountsController.getBaseUser(req.params.userslug, req.uid, next);
|
||||||
}
|
}
|
||||||
}, function(err, results) {
|
}, function(err, results) {
|
||||||
if (err) {
|
if (err || !results.userData) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
var userData = results.userData;
|
var userData = results.userData;
|
||||||
if (!userData) {
|
|
||||||
return helpers.notFound(req, res);
|
|
||||||
}
|
|
||||||
|
|
||||||
var setName = 'uid:' + userData.uid + ':' + set;
|
var setName = 'uid:' + userData.uid + ':' + set;
|
||||||
|
|
||||||
@@ -385,7 +367,7 @@ accountsController.accountEdit = function(req, res, next) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
accountsController.accountSettings = function(req, res, next) {
|
accountsController.accountSettings = function(req, res, callback) {
|
||||||
var userData;
|
var userData;
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function(next) {
|
function(next) {
|
||||||
@@ -394,7 +376,7 @@ accountsController.accountSettings = function(req, res, next) {
|
|||||||
function(_userData, next) {
|
function(_userData, next) {
|
||||||
userData = _userData;
|
userData = _userData;
|
||||||
if (!userData) {
|
if (!userData) {
|
||||||
return helpers.notFound(req, res);
|
return callback();
|
||||||
}
|
}
|
||||||
async.parallel({
|
async.parallel({
|
||||||
settings: function(next) {
|
settings: function(next) {
|
||||||
@@ -421,7 +403,7 @@ accountsController.accountSettings = function(req, res, next) {
|
|||||||
}
|
}
|
||||||
], function(err) {
|
], function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
userData.dailyDigestFreqOptions = [
|
userData.dailyDigestFreqOptions = [
|
||||||
@@ -433,74 +415,23 @@ accountsController.accountSettings = function(req, res, next) {
|
|||||||
|
|
||||||
|
|
||||||
userData.bootswatchSkinOptions = [
|
userData.bootswatchSkinOptions = [
|
||||||
{
|
{ "name": "Default", "value": "default" },
|
||||||
"name": "Default",
|
{ "name": "Cerulean", "value": "cerulean" },
|
||||||
"value": "default"
|
{ "name": "Cosmo", "value": "cosmo" },
|
||||||
},
|
{ "name": "Cyborg", "value": "cyborg" },
|
||||||
{
|
{ "name": "Darkly", "value": "darkly" },
|
||||||
"name": "Cerulean",
|
{ "name": "Flatly", "value": "flatly" },
|
||||||
"value": "cerulean"
|
{ "name": "Journal", "value": "journal" },
|
||||||
},
|
{ "name": "Lumen", "value": "lumen" },
|
||||||
{
|
{ "name": "Paper", "value": "paper" },
|
||||||
"name": "Cosmo",
|
{ "name": "Readable", "value": "readable" },
|
||||||
"value": "cosmo"
|
{ "name": "Sandstone", "value": "sandstone" },
|
||||||
},
|
{ "name": "Simplex", "value": "simplex" },
|
||||||
{
|
{ "name": "Slate", "value": "slate" },
|
||||||
"name": "Cyborg",
|
{ "name": "Spacelab", "value": "spacelab" },
|
||||||
"value": "cyborg"
|
{ "name": "Superhero", "value": "superhero" },
|
||||||
},
|
{ "name": "United", "value": "united" },
|
||||||
{
|
{ "name": "Yeti", "value": "yeti" }
|
||||||
"name": "Darkly",
|
|
||||||
"value": "darkly"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Flatly",
|
|
||||||
"value": "flatly"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Journal",
|
|
||||||
"value": "journal"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Lumen",
|
|
||||||
"value": "lumen"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Paper",
|
|
||||||
"value": "paper"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Readable",
|
|
||||||
"value": "readable"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Sandstone",
|
|
||||||
"value": "sandstone"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Simplex",
|
|
||||||
"value": "simplex"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Slate",
|
|
||||||
"value": "slate"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Spacelab",
|
|
||||||
"value": "spacelab"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Superhero",
|
|
||||||
"value": "superhero"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "United",
|
|
||||||
"value": "united"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Yeti",
|
|
||||||
"value": "yeti"
|
|
||||||
}
|
|
||||||
];
|
];
|
||||||
|
|
||||||
userData.bootswatchSkinOptions.forEach(function(skin) {
|
userData.bootswatchSkinOptions.forEach(function(skin) {
|
||||||
@@ -574,9 +505,9 @@ accountsController.getNotifications = function(req, res, next) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
accountsController.getChats = function(req, res, next) {
|
accountsController.getChats = function(req, res, callback) {
|
||||||
if (parseInt(meta.config.disableChat) === 1) {
|
if (parseInt(meta.config.disableChat, 10) === 1) {
|
||||||
return helpers.notFound(req, res);
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
// In case a userNAME is passed in instead of a slug, the route should not 404
|
// In case a userNAME is passed in instead of a slug, the route should not 404
|
||||||
@@ -590,7 +521,7 @@ accountsController.getChats = function(req, res, next) {
|
|||||||
recentChats: async.apply(messaging.getRecentChats, req.user.uid, 0, 19)
|
recentChats: async.apply(messaging.getRecentChats, req.user.uid, 0, 19)
|
||||||
}, function(err, results) {
|
}, function(err, results) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Remove entries if they were already present as a followed contact
|
//Remove entries if they were already present as a followed contact
|
||||||
@@ -618,7 +549,7 @@ accountsController.getChats = function(req, res, next) {
|
|||||||
async.apply(user.getUidByUserslug, req.params.userslug),
|
async.apply(user.getUidByUserslug, req.params.userslug),
|
||||||
function(toUid, next) {
|
function(toUid, next) {
|
||||||
if (!toUid || parseInt(toUid, 10) === parseInt(req.user.uid, 10)) {
|
if (!toUid || parseInt(toUid, 10) === parseInt(req.user.uid, 10)) {
|
||||||
return helpers.notFound(req, res);
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
async.parallel({
|
async.parallel({
|
||||||
@@ -634,7 +565,7 @@ accountsController.getChats = function(req, res, next) {
|
|||||||
}
|
}
|
||||||
], function(err, data) {
|
], function(err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.render('chats', {
|
res.render('chats', {
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ groupsController.list = function(req, res, next) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
groupsController.get = function(req, res, next) {
|
groupsController.get = function(req, res, callback) {
|
||||||
var groupName = req.params.name;
|
var groupName = req.params.name;
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function(next){
|
function(next){
|
||||||
@@ -58,13 +58,13 @@ groupsController.get = function(req, res, next) {
|
|||||||
},
|
},
|
||||||
function(exists, next) {
|
function(exists, next) {
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
return helpers.notFound(req, res);
|
return callback();
|
||||||
}
|
}
|
||||||
groups.get(groupName, {uid: req.uid}, next);
|
groups.get(groupName, {uid: req.uid}, next);
|
||||||
}
|
}
|
||||||
], function(err, group) {
|
], function(err, group) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
res.render('admin/manage/group', {group: group});
|
res.render('admin/manage/group', {group: group});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -76,13 +76,13 @@ categoriesController.list = function(req, res, next) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
categoriesController.get = function(req, res, next) {
|
categoriesController.get = function(req, res, callback) {
|
||||||
var cid = req.params.category_id,
|
var cid = req.params.category_id,
|
||||||
page = parseInt(req.query.page, 10) || 1,
|
page = parseInt(req.query.page, 10) || 1,
|
||||||
userPrivileges;
|
userPrivileges;
|
||||||
|
|
||||||
if ((req.params.topic_index && !utils.isNumber(req.params.topic_index)) || !utils.isNumber(cid)) {
|
if ((req.params.topic_index && !utils.isNumber(req.params.topic_index)) || !utils.isNumber(cid)) {
|
||||||
return helpers.notFound(req, res);
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
@@ -106,7 +106,7 @@ categoriesController.get = function(req, res, next) {
|
|||||||
userPrivileges = results.privileges;
|
userPrivileges = results.privileges;
|
||||||
|
|
||||||
if (!results.exists || (results.categoryData && parseInt(results.categoryData.disabled, 10) === 1)) {
|
if (!results.exists || (results.categoryData && parseInt(results.categoryData.disabled, 10) === 1)) {
|
||||||
return helpers.notFound(req, res);
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!results.privileges.read) {
|
if (!results.privileges.read) {
|
||||||
@@ -127,7 +127,7 @@ categoriesController.get = function(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (settings.usePagination && (page < 1 || page > pageCount)) {
|
if (settings.usePagination && (page < 1 || page > pageCount)) {
|
||||||
return helpers.notFound(req, res);
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!settings.usePagination) {
|
if (!settings.usePagination) {
|
||||||
@@ -245,7 +245,7 @@ categoriesController.get = function(req, res, next) {
|
|||||||
}
|
}
|
||||||
], function (err, data) {
|
], function (err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
data.currentPage = page;
|
data.currentPage = page;
|
||||||
@@ -259,7 +259,7 @@ categoriesController.get = function(req, res, next) {
|
|||||||
|
|
||||||
plugins.fireHook('filter:category.build', {req: req, res: res, templateData: data}, function(err, data) {
|
plugins.fireHook('filter:category.build', {req: req, res: res, templateData: data}, function(err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
res.render('category', data.templateData);
|
res.render('category', data.templateData);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -42,39 +42,34 @@ groupsController.getGroupsFromSet = function(uid, sort, start, stop, callback) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
groupsController.details = function(req, res, next) {
|
groupsController.details = function(req, res, callback) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
async.apply(groups.exists, res.locals.groupName),
|
async.apply(groups.exists, res.locals.groupName),
|
||||||
function(exists, next) {
|
function(exists, next) {
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
return next(undefined, null);
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the group isn't hidden either
|
|
||||||
groups.isHidden(res.locals.groupName, next);
|
groups.isHidden(res.locals.groupName, next);
|
||||||
},
|
},
|
||||||
function(hidden, next) {
|
function(hidden, next) {
|
||||||
if (hidden === null) { return next(undefined, false); } // Group didn't exist, not ok
|
|
||||||
|
|
||||||
if (!hidden) {
|
if (!hidden) {
|
||||||
next(null, true);
|
return next();
|
||||||
} else {
|
|
||||||
// If not, only members are granted access
|
|
||||||
async.parallel([
|
|
||||||
async.apply(groups.isMember, req.uid, res.locals.groupName),
|
|
||||||
async.apply(groups.isInvited, req.uid, res.locals.groupName)
|
|
||||||
], function(err, checks) {
|
|
||||||
next(err, checks[0] || checks[1]);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
], function(err, ok) {
|
async.parallel({
|
||||||
if (err) {
|
isMember: async.apply(groups.isMember, req.uid, res.locals.groupName),
|
||||||
|
isInvited: async.apply(groups.isInvited, req.uid, res.locals.groupName)
|
||||||
|
}, function(err, checks) {
|
||||||
|
if (err || checks.isMember || checks.isInvited) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
callback();
|
||||||
if (!ok) {
|
});
|
||||||
return helpers.redirect(res, '/groups');
|
}
|
||||||
|
], function(err) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
async.parallel({
|
async.parallel({
|
||||||
@@ -90,12 +85,8 @@ groupsController.details = function(req, res, next) {
|
|||||||
},
|
},
|
||||||
isAdmin: async.apply(user.isAdministrator, req.uid)
|
isAdmin: async.apply(user.isAdministrator, req.uid)
|
||||||
}, function(err, results) {
|
}, function(err, results) {
|
||||||
if (err) {
|
if (err || !results.group) {
|
||||||
return next(err);
|
return callback(err);
|
||||||
}
|
|
||||||
|
|
||||||
if (!results.group) {
|
|
||||||
return helpers.notFound(req, res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
results.title = '[[pages:group, ' + results.group.displayName + ']]';
|
results.title = '[[pages:group, ' + results.group.displayName + ']]';
|
||||||
|
|||||||
@@ -11,28 +11,6 @@ var nconf = require('nconf'),
|
|||||||
|
|
||||||
var helpers = {};
|
var helpers = {};
|
||||||
|
|
||||||
helpers.notFound = function(req, res, error) {
|
|
||||||
if (plugins.hasListeners('action:meta.override404')) {
|
|
||||||
plugins.fireHook('action:meta.override404', {
|
|
||||||
req: req,
|
|
||||||
res: res,
|
|
||||||
error: error
|
|
||||||
});
|
|
||||||
} else if (res.locals.isAPI) {
|
|
||||||
res.status(404).json({
|
|
||||||
path: req.path.replace(/^\/api/, ''),
|
|
||||||
error: error,
|
|
||||||
title: '[[global:404.title]]'
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
res.status(404).render('404', {
|
|
||||||
path: req.path,
|
|
||||||
error: error,
|
|
||||||
title: '[[global:404.title]]'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
helpers.notAllowed = function(req, res, error) {
|
helpers.notAllowed = function(req, res, error) {
|
||||||
if (req.uid) {
|
if (req.uid) {
|
||||||
if (res.locals.isAPI) {
|
if (res.locals.isAPI) {
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ Controllers.register = function(req, res, next) {
|
|||||||
var registrationType = meta.config.registrationType || 'normal';
|
var registrationType = meta.config.registrationType || 'normal';
|
||||||
|
|
||||||
if (registrationType === 'disabled') {
|
if (registrationType === 'disabled') {
|
||||||
return helpers.notFound(req, res);
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
@@ -164,7 +164,7 @@ Controllers.confirmEmail = function(req, res, next) {
|
|||||||
|
|
||||||
Controllers.sitemap = function(req, res, next) {
|
Controllers.sitemap = function(req, res, next) {
|
||||||
if (parseInt(meta.config['feeds:disableSitemap'], 10) === 1) {
|
if (parseInt(meta.config['feeds:disableSitemap'], 10) === 1) {
|
||||||
return helpers.notFound(req, res);
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
var sitemap = require('../sitemap.js');
|
var sitemap = require('../sitemap.js');
|
||||||
@@ -204,7 +204,7 @@ Controllers.outgoing = function(req, res, next) {
|
|||||||
|
|
||||||
Controllers.termsOfUse = function(req, res, next) {
|
Controllers.termsOfUse = function(req, res, next) {
|
||||||
if (!meta.config.termsOfUse) {
|
if (!meta.config.termsOfUse) {
|
||||||
return helpers.notFound(req, res);
|
return next();
|
||||||
}
|
}
|
||||||
res.render('tos', {termsOfUse: meta.config.termsOfUse});
|
res.render('tos', {termsOfUse: meta.config.termsOfUse});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -16,12 +16,10 @@ postsController.getPost = function(req, res, next) {
|
|||||||
posts.getPostData(req.params.pid, next);
|
posts.getPostData(req.params.pid, next);
|
||||||
}
|
}
|
||||||
}, function(err, results) {
|
}, function(err, results) {
|
||||||
if (err) {
|
if (err || !results.postData) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
if (!results.postData) {
|
|
||||||
return helpers.notFound(req, res);
|
|
||||||
}
|
|
||||||
if (!results.canRead) {
|
if (!results.canRead) {
|
||||||
return helpers.notAllowed(req, res);
|
return helpers.notAllowed(req, res);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ var searchController = {},
|
|||||||
|
|
||||||
searchController.search = function(req, res, next) {
|
searchController.search = function(req, res, next) {
|
||||||
if (!plugins.hasListeners('filter:search.query')) {
|
if (!plugins.hasListeners('filter:search.query')) {
|
||||||
return helpers.notFound(req, res);
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
var breadcrumbs = helpers.buildBreadcrumbs([{text: '[[global:search]]'}]);
|
var breadcrumbs = helpers.buildBreadcrumbs([{text: '[[global:search]]'}]);
|
||||||
|
|||||||
@@ -16,13 +16,13 @@ var topicsController = {},
|
|||||||
pagination = require('../pagination'),
|
pagination = require('../pagination'),
|
||||||
utils = require('../../public/src/utils');
|
utils = require('../../public/src/utils');
|
||||||
|
|
||||||
topicsController.get = function(req, res, next) {
|
topicsController.get = function(req, res, callback) {
|
||||||
var tid = req.params.topic_id,
|
var tid = req.params.topic_id,
|
||||||
sort = req.query.sort,
|
sort = req.query.sort,
|
||||||
userPrivileges;
|
userPrivileges;
|
||||||
|
|
||||||
if ((req.params.post_index && !utils.isNumber(req.params.post_index)) || !utils.isNumber(tid)) {
|
if ((req.params.post_index && !utils.isNumber(req.params.post_index)) || !utils.isNumber(tid)) {
|
||||||
return helpers.notFound(req, res);
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
@@ -60,7 +60,7 @@ topicsController.get = function(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (settings.usePagination && (page < 1 || page > pageCount)) {
|
if (settings.usePagination && (page < 1 || page > pageCount)) {
|
||||||
return helpers.notFound(req, res);
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
var set = 'tid:' + tid + ':posts',
|
var set = 'tid:' + tid + ':posts',
|
||||||
@@ -109,7 +109,7 @@ topicsController.get = function(req, res, next) {
|
|||||||
|
|
||||||
topics.getTopicWithPosts(tid, set, req.uid, start, stop, reverse, function (err, topicData) {
|
topics.getTopicWithPosts(tid, set, req.uid, start, stop, reverse, function (err, topicData) {
|
||||||
if (err && err.message === '[[error:no-topic]]' && !topicData) {
|
if (err && err.message === '[[error:no-topic]]' && !topicData) {
|
||||||
return helpers.notFound(req, res);
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err && !topicData) {
|
if (err && !topicData) {
|
||||||
@@ -247,7 +247,7 @@ topicsController.get = function(req, res, next) {
|
|||||||
}
|
}
|
||||||
], function (err, data) {
|
], function (err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
data.privileges = userPrivileges;
|
data.privileges = userPrivileges;
|
||||||
@@ -264,7 +264,7 @@ topicsController.get = function(req, res, next) {
|
|||||||
|
|
||||||
plugins.fireHook('filter:topic.build', {req: req, res: res, templateData: data}, function(err, data) {
|
plugins.fireHook('filter:topic.build', {req: req, res: res, templateData: data}, function(err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
res.render('topic', data.templateData);
|
res.render('topic', data.templateData);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -296,11 +296,10 @@ var async = require('async'),
|
|||||||
Groups.isHidden = function(groupName, callback) {
|
Groups.isHidden = function(groupName, callback) {
|
||||||
Groups.getGroupFields(groupName, ['hidden'], function(err, values) {
|
Groups.getGroupFields(groupName, ['hidden'], function(err, values) {
|
||||||
if (err) {
|
if (err) {
|
||||||
winston.warn('[groups.isHidden] Could not determine group hidden state (group: ' + groupName + ')');
|
return callback(err);
|
||||||
return callback(null, true); // Default true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(null, parseInt(values.hidden, 10));
|
callback(null, parseInt(values.hidden, 10) === 1);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -134,10 +134,6 @@ middleware.checkAccountPermissions = function(req, res, next) {
|
|||||||
user.getUidByUserslug(req.params.userslug, next);
|
user.getUidByUserslug(req.params.userslug, next);
|
||||||
},
|
},
|
||||||
function (uid, next) {
|
function (uid, next) {
|
||||||
if (!uid) {
|
|
||||||
return controllers.helpers.notFound(req, res);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parseInt(uid, 10) === req.uid) {
|
if (parseInt(uid, 10) === req.uid) {
|
||||||
return next(null, true);
|
return next(null, true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ function hasPrivileges(method, id, req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateForTopic(req, res, next) {
|
function generateForTopic(req, res, next) {
|
||||||
|
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
var tid = req.params.topic_id;
|
var tid = req.params.topic_id;
|
||||||
|
|
||||||
privileges.topics.get(tid, req.uid, function(err, userPrivileges) {
|
privileges.topics.get(tid, req.uid, function(err, userPrivileges) {
|
||||||
@@ -52,7 +56,7 @@ function generateForTopic(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (topicData.deleted && !userPrivileges.view_deleted) {
|
if (topicData.deleted && !userPrivileges.view_deleted) {
|
||||||
return helpers.notFound(req, res);
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
var description = topicData.posts.length ? topicData.posts[0].content : '';
|
var description = topicData.posts.length ? topicData.posts[0].content : '';
|
||||||
@@ -94,6 +98,10 @@ function generateForTopic(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateForUserTopics(req, res, next) {
|
function generateForUserTopics(req, res, next) {
|
||||||
|
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
var userslug = req.params.userslug;
|
var userslug = req.params.userslug;
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
@@ -119,6 +127,9 @@ function generateForUserTopics(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateForCategory(req, res, next) {
|
function generateForCategory(req, res, next) {
|
||||||
|
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
var cid = req.params.category_id;
|
var cid = req.params.category_id;
|
||||||
|
|
||||||
categories.getCategoryById({
|
categories.getCategoryById({
|
||||||
@@ -149,6 +160,9 @@ function generateForCategory(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateForRecent(req, res, next) {
|
function generateForRecent(req, res, next) {
|
||||||
|
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
generateForTopics({
|
generateForTopics({
|
||||||
uid: req.uid,
|
uid: req.uid,
|
||||||
title: 'Recently Active Topics',
|
title: 'Recently Active Topics',
|
||||||
@@ -159,6 +173,9 @@ function generateForRecent(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateForPopular(req, res, next) {
|
function generateForPopular(req, res, next) {
|
||||||
|
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
var terms = {
|
var terms = {
|
||||||
daily: 'day',
|
daily: 'day',
|
||||||
weekly: 'week',
|
weekly: 'week',
|
||||||
@@ -187,14 +204,6 @@ function generateForPopular(req, res, next) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function disabledRSS(req, res, next) {
|
|
||||||
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
|
||||||
return helpers.notFound(req, res);
|
|
||||||
}
|
|
||||||
|
|
||||||
next();
|
|
||||||
}
|
|
||||||
|
|
||||||
function generateForTopics(options, set, req, res, next) {
|
function generateForTopics(options, set, req, res, next) {
|
||||||
topics.getTopicsFromSet(set, req.uid, 0, 19, function (err, data) {
|
topics.getTopicsFromSet(set, req.uid, 0, 19, function (err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -262,6 +271,10 @@ function generateTopicsFeed(feedOptions, feedTopics, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateForRecentPosts(req, res, next) {
|
function generateForRecentPosts(req, res, next) {
|
||||||
|
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
posts.getRecentPosts(req.uid, 0, 19, 'month', function(err, posts) {
|
posts.getRecentPosts(req.uid, 0, 19, 'month', function(err, posts) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
@@ -279,6 +292,9 @@ function generateForRecentPosts(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateForCategoryRecentPosts(req, res, next) {
|
function generateForCategoryRecentPosts(req, res, next) {
|
||||||
|
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
var cid = req.params.category_id;
|
var cid = req.params.category_id;
|
||||||
|
|
||||||
async.parallel({
|
async.parallel({
|
||||||
@@ -337,12 +353,12 @@ function sendFeed(feed, res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = function(app, middleware, controllers){
|
module.exports = function(app, middleware, controllers){
|
||||||
app.get('/topic/:topic_id.rss', hasTopicPrivileges, disabledRSS, generateForTopic);
|
app.get('/topic/:topic_id.rss', hasTopicPrivileges, generateForTopic);
|
||||||
app.get('/category/:category_id.rss', hasCategoryPrivileges, disabledRSS, generateForCategory);
|
app.get('/category/:category_id.rss', hasCategoryPrivileges, generateForCategory);
|
||||||
app.get('/recent.rss', disabledRSS, generateForRecent);
|
app.get('/recent.rss', generateForRecent);
|
||||||
app.get('/popular.rss', disabledRSS, generateForPopular);
|
app.get('/popular.rss', generateForPopular);
|
||||||
app.get('/popular/:term.rss', disabledRSS, generateForPopular);
|
app.get('/popular/:term.rss', generateForPopular);
|
||||||
app.get('/recentposts.rss', disabledRSS, generateForRecentPosts);
|
app.get('/recentposts.rss', generateForRecentPosts);
|
||||||
app.get('/category/:category_id/recentposts.rss', hasCategoryPrivileges, disabledRSS, generateForCategoryRecentPosts);
|
app.get('/category/:category_id/recentposts.rss', hasCategoryPrivileges, generateForCategoryRecentPosts);
|
||||||
app.get('/user/:userslug/topics.rss', disabledRSS, generateForUserTopics);
|
app.get('/user/:userslug/topics.rss', generateForUserTopics);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -44,11 +44,11 @@ module.exports = function(app, middleware, controllers) {
|
|||||||
if (matches.length) {
|
if (matches.length) {
|
||||||
res.sendFile(matches[0]);
|
res.sendFile(matches[0]);
|
||||||
} else {
|
} else {
|
||||||
helpers.notFound(req, res);
|
next();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
helpers.notFound(req, res);
|
next();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user