From 738b8920747bfc989eea24e4aa87fea57108c4e3 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 23 Feb 2016 14:41:15 +0200 Subject: [PATCH] closes #4217 --- src/controllers/tags.js | 59 +++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/src/controllers/tags.js b/src/controllers/tags.js index 89fb4e3311..60f4c1d028 100644 --- a/src/controllers/tags.js +++ b/src/controllers/tags.js @@ -1,48 +1,44 @@ "use strict"; -var tagsController = {}, - async = require('async'), - nconf = require('nconf'), - validator = require('validator'), - meta = require('../meta'), - user = require('../user'), - topics = require('../topics'), - helpers = require('./helpers'); + +var async = require('async'); +var nconf = require('nconf'); +var validator = require('validator'); + +var meta = require('../meta'); +var topics = require('../topics'); +var helpers = require('./helpers'); + +var tagsController = {}; tagsController.getTag = function(req, res, next) { var tag = validator.escape(req.params.tag); var stop = (parseInt(meta.config.topicsPerList, 10) || 20) - 1; + var templateData = { + topics: [], + tag: tag, + breadcrumbs: helpers.buildBreadcrumbs([{text: '[[tags:tags]]', url: '/tags'}, {text: tag}]), + title: '[[pages:tag, ' + tag + ']]' + }; + async.waterfall([ - function(next) { + function (next) { topics.getTagTids(req.params.tag, 0, stop, next); }, - function(tids, next) { + function (tids, next) { if (Array.isArray(tids) && !tids.length) { topics.deleteTag(req.params.tag); - return res.render('tag', { - topics: [], - tag: tag, - breadcrumbs: helpers.buildBreadcrumbs([{text: '[[tags:tags]]', url: '/tags'}, {text: tag}]) - }); + return res.render('tag', templateData); } - async.parallel({ - isAdmin: async.apply(user.isAdministrator, req.uid), - topics: async.apply(topics.getTopics, tids, req.uid) - }, next); + topics.getTopics(tids, req.uid, next); } - ], function(err, results) { + ], function(err, topics) { if (err) { return next(err); } - if (!results.isAdmin) { - results.topics = results.topics.filter(function(topic) { - return topic && !topic.deleted; - }); - } - res.locals.metaTags = [ { name: 'title', @@ -57,15 +53,10 @@ tagsController.getTag = function(req, res, next) { content: nconf.get('url') + '/tags/' + tag } ]; + templateData.topics = topics; + templateData.nextStart = stop + 1; - var data = { - topics: results.topics, - tag: tag, - nextStart: stop + 1, - breadcrumbs: helpers.buildBreadcrumbs([{text: '[[tags:tags]]', url: '/tags'}, {text: tag}]), - title: '[[pages:tag, ' + tag + ']]' - }; - res.render('tag', data); + res.render('tag', templateData); }); };