diff --git a/package.json b/package.json index bab3c6bcb4..a1fac5f4de 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "nodebb-plugin-dbsearch": "^0.1.0", "nodebb-plugin-emoji-extended": "^0.4.1-4", "nodebb-plugin-markdown": "^1.0.0", - "nodebb-plugin-mentions": "^0.9.0", + "nodebb-plugin-mentions": "^0.10.0", "nodebb-plugin-soundpack-default": "~0.1.1", "nodebb-plugin-spam-be-gone": "^0.4.0", "nodebb-theme-lavender": "^1.0.6", diff --git a/public/src/admin/extend/widgets.js b/public/src/admin/extend/widgets.js index 239d5bd809..b57453ffab 100644 --- a/public/src/admin/extend/widgets.js +++ b/public/src/admin/extend/widgets.js @@ -3,7 +3,7 @@ define('admin/extend/widgets', function() { var Widgets = {}; - + Widgets.init = function() { $('#widgets .nav-pills a').on('click', function(ev) { var $this = $(this); diff --git a/src/controllers/categories.js b/src/controllers/categories.js index 5264e0e5f4..18bbd57f8b 100644 --- a/src/controllers/categories.js +++ b/src/controllers/categories.js @@ -200,8 +200,7 @@ categoriesController.get = function(req, res, next) { var topicCount = parseInt(results.categoryData.topic_count, 10); if (topicIndex < 0 || topicIndex > Math.max(topicCount - 1, 0)) { - var url = '/category/' + cid + '/' + req.params.slug + (topicIndex > topicCount ? '/' + topicCount : ''); - return res.locals.isAPI ? res.status(302).json(url) : res.redirect(url); + return helpers.redirect(res, '/category/' + cid + '/' + req.params.slug + (topicIndex > topicCount ? '/' + topicCount : '')); } userPrivileges = results.privileges; diff --git a/src/controllers/groups.js b/src/controllers/groups.js index 51200d0a40..7371c924e7 100644 --- a/src/controllers/groups.js +++ b/src/controllers/groups.js @@ -51,31 +51,35 @@ groupsController.details = function(req, res, next) { } } ], function(err, ok) { - if (ok) { - async.parallel({ - group: function(next) { - groups.get(res.locals.groupName, { - expand: true, - uid: uid - }, next); - }, - posts: function(next) { - groups.getLatestMemberPosts(res.locals.groupName, 10, uid, next); - } - }, function(err, results) { - if (err) { - return next(err); - } - - if (!results.group) { - return helpers.notFound(req, res); - } + if (err) { + return next(err); + } - res.render('groups/details', results); - }); - } else { - return res.locals.isAPI ? res.status(302).json('/groups') : res.redirect('/groups'); + if (!ok) { + return helpers.redirect(res, '/groups'); } + + async.parallel({ + group: function(next) { + groups.get(res.locals.groupName, { + expand: true, + uid: uid + }, next); + }, + posts: function(next) { + groups.getLatestMemberPosts(res.locals.groupName, 10, uid, next); + } + }, function(err, results) { + if (err) { + return next(err); + } + + if (!results.group) { + return helpers.notFound(req, res); + } + + res.render('groups/details', results); + }); }); }; diff --git a/src/controllers/helpers.js b/src/controllers/helpers.js index dd5961839b..12a3327c55 100644 --- a/src/controllers/helpers.js +++ b/src/controllers/helpers.js @@ -45,6 +45,14 @@ helpers.notAllowed = function(req, res, error) { } }; +helpers.redirect = function(res, url) { + if (res.locals.isAPI) { + res.status(302).json(url); + } else { + res.redirect(url); + } +}; + helpers.buildCategoryBreadcrumbs = function(cid, callback) { var breadcrumbs = []; diff --git a/src/controllers/topics.js b/src/controllers/topics.js index 1d756b4189..8429e19396 100644 --- a/src/controllers/topics.js +++ b/src/controllers/topics.js @@ -56,12 +56,8 @@ topicsController.get = function(req, res, next) { var postCount = parseInt(results.topic.postcount, 10); var pageCount = Math.max(1, Math.ceil((postCount - 1) / settings.postsPerPage)); - if (utils.isNumber(req.params.post_index)) { - var url = ''; - if (req.params.post_index < 1 || req.params.post_index > postCount) { - url = '/topic/' + req.params.topic_id + '/' + req.params.slug + (req.params.post_index > postCount ? '/' + postCount : ''); - return res.locals.isAPI ? res.status(302).json(url) : res.redirect(url); - } + if (utils.isNumber(req.params.post_index) && (req.params.post_index < 1 || req.params.post_index > postCount)) { + return helpers.redirect(res, '/topic/' + req.params.topic_id + '/' + req.params.slug + (req.params.post_index > postCount ? '/' + postCount : '')); } if (settings.usePagination && (req.query.page < 1 || req.query.page > pageCount)) { @@ -266,7 +262,7 @@ topicsController.get = function(req, res, next) { }); topics.increaseViewCount(tid); - + plugins.fireHook('filter:topic.build', {req: req, res: res, templateData: data}, function(err, data) { if (err) { return next(err); diff --git a/src/groups.js b/src/groups.js index 452b47d56c..0645fc55ac 100644 --- a/src/groups.js +++ b/src/groups.js @@ -16,6 +16,7 @@ var async = require('async'), posts = require('./posts'), privileges = require('./privileges'), utils = require('../public/src/utils'), + util = require('util'), uploadsController = require('./controllers/uploads'); @@ -952,7 +953,11 @@ var async = require('async'), var memberOf = []; isMembers.forEach(function(isMember, index) { if (isMember) { - memberOf.push(groupData[index]); + if (uids.length > 1) { + memberOf.push(util._extend({}, groupData[index])); + } else { + memberOf.push(groupData[index]); + } } }); @@ -1084,7 +1089,7 @@ var async = require('async'), case 'alpha': // intentional fall-through default: groups = groups.sort(function(a, b) { - return a.slug > b.slug; + return a.slug > b.slug ? 1 : -1; }); } diff --git a/src/middleware/middleware.js b/src/middleware/middleware.js index 85cc10c908..62575d066b 100644 --- a/src/middleware/middleware.js +++ b/src/middleware/middleware.js @@ -60,12 +60,7 @@ middleware.redirectToAccountIfLoggedIn = function(req, res, next) { if (err) { return next(err); } - - if (res.locals.isAPI) { - res.status(302).json(nconf.get('relative_path') + '/user/' + userslug); - } else { - res.redirect(nconf.get('relative_path') + '/user/' + userslug); - } + helpers.redirect(res, '/user/' + userslug); }); }; @@ -85,13 +80,7 @@ middleware.addSlug = function(req, res, next) { return next(err); } - var url = nconf.get('relative_path') + name + encodeURI(slug); - - if (res.locals.isAPI) { - res.status(302).json(url); - } else { - res.redirect(url); - } + helpers.redirect(res, name + encodeURI(slug)); }); } diff --git a/src/posts/user.js b/src/posts/user.js index de563d86b5..494b1dbc6f 100644 --- a/src/posts/user.js +++ b/src/posts/user.js @@ -34,8 +34,8 @@ module.exports = function(Posts) { var userData = results.userData; userData.forEach(function(userData, i) { userData.groups = results.groups[i]; - - results.groups[i].forEach(function(group, index) { + + userData.groups.forEach(function(group) { group.selected = group.name === results.userSettings[i].groupTitle; }); userData.status = user.getStatus(userData.status, results.online[i]); diff --git a/src/routes/index.js b/src/routes/index.js index a6c51b17c9..37ce391e54 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -218,7 +218,7 @@ function handleErrors(app, middleware) { } if (parseInt(err.status, 10) === 302 && err.path) { - return res.locals.isAPI ? res.status(302).json(err) : res.redirect(err.path); + return res.locals.isAPI ? res.status(302).json(err.path) : res.redirect(err.path); } res.status(err.status || 500); diff --git a/src/views/admin/extend/widgets.tpl b/src/views/admin/extend/widgets.tpl index d2aca20177..91fc127d89 100644 --- a/src/views/admin/extend/widgets.tpl +++ b/src/views/admin/extend/widgets.tpl @@ -6,7 +6,7 @@
@@ -14,10 +14,10 @@