From 4af4b47d65715fd2366dea661174e7b475fdd73d Mon Sep 17 00:00:00 2001 From: OldHawk Date: Mon, 4 Dec 2017 16:39:37 +0800 Subject: [PATCH] fix(forums): fixed normal user and vip/oper only forum access issues normal user cannot view the vip/oper forum topics in 'global topics' normal user can not view forum by url link enter, system well nav to forums home #40 #20 --- .../controllers/core.server.controller.js | 6 ++--- .../forums-topic.client.controller.js | 25 +++++++++-------- .../forums-view.client.controller.js | 17 +++++++----- .../forums/client/views/view.client.view.html | 2 +- .../controllers/forums.server.controller.js | 27 ++++++++++++++++--- 5 files changed, 52 insertions(+), 25 deletions(-) diff --git a/modules/core/server/controllers/core.server.controller.js b/modules/core/server/controllers/core.server.controller.js index b397de68..5ca7a2f0 100644 --- a/modules/core/server/controllers/core.server.controller.js +++ b/modules/core/server/controllers/core.server.controller.js @@ -18,7 +18,7 @@ exports.renderIndex = function (req, res) { res.render('modules/core/server/views/index', { user: JSON.stringify(safeUserObject), sharedConfig: JSON.stringify(config.shared), - meanTorrentConfig: JSON.stringify(getSafeMeanTorrentConfig(config.meanTorrentConfig)), + meanTorrentConfig: JSON.stringify(getSafeMeanTorrentConfig(config.meanTorrentConfig)) }); }; @@ -68,7 +68,7 @@ exports.renderNotFound = function (req, res) { * @param cfg * @returns {*} */ -function getSafeMeanTorrentConfig(cfg){ +function getSafeMeanTorrentConfig(cfg) { //ignore backup settings cfg.backup = undefined; @@ -85,4 +85,4 @@ function getSafeMeanTorrentConfig(cfg){ cfg.tmdbConfig.key = undefined; return cfg; -}; +} diff --git a/modules/forums/client/controllers/forums-topic.client.controller.js b/modules/forums/client/controllers/forums-topic.client.controller.js index cfdf0fde..c40bcad5 100644 --- a/modules/forums/client/controllers/forums-topic.client.controller.js +++ b/modules/forums/client/controllers/forums-topic.client.controller.js @@ -89,20 +89,23 @@ forumId: $stateParams.forumId }, function (item) { vm.forum = item; - vm.forumPath.splice(0, 0, {name: vm.forum.name, state: 'forums.view', params: {forumId: vm.forum._id}}); - }); - // get topics - TopicsService.get({ - forumId: $stateParams.forumId, - topicId: $stateParams.topicId - }, function (topic) { - mtDebug.info(topic); - vm.topic = topic; - vm.buildPager(); + // get topics + TopicsService.get({ + forumId: $stateParams.forumId, + topicId: $stateParams.topicId + }, function (topic) { + mtDebug.info(topic); + vm.topic = topic; + vm.buildPager(); - vm.forumPath.push({name: topic.title, state: undefined}); + vm.forumPath.push({name: topic.title, state: undefined}); + }); + }, function (res) { + if (typeof res.data.redirect == 'string') { + $state.go(res.data.redirect); + } }); }; diff --git a/modules/forums/client/controllers/forums-view.client.controller.js b/modules/forums/client/controllers/forums-view.client.controller.js index 482f0776..081e8c60 100644 --- a/modules/forums/client/controllers/forums-view.client.controller.js +++ b/modules/forums/client/controllers/forums-view.client.controller.js @@ -65,14 +65,17 @@ forumId: $stateParams.forumId }, function (item) { vm.forum = item; - vm.forumPath.push({name: vm.forum.name, state: undefined}); - }); - - // get global topics list - TopicsService.getGlobalTopics(function (topics) { - mtDebug.info(topics); - vm.globalTopics = topics; + vm.buildPager(); + // get global topics list + TopicsService.getGlobalTopics(function (topics) { + mtDebug.info(topics); + vm.globalTopics = topics; + }); + }, function (res) { + if (typeof res.data.redirect == 'string') { + $state.go(res.data.redirect); + } }); }; diff --git a/modules/forums/client/views/view.client.view.html b/modules/forums/client/views/view.client.view.html index 38609c4d..8f8c6cee 100644 --- a/modules/forums/client/views/view.client.view.html +++ b/modules/forums/client/views/view.client.view.html @@ -1,4 +1,4 @@ -
+
diff --git a/modules/forums/server/controllers/forums.server.controller.js b/modules/forums/server/controllers/forums.server.controller.js index b3eadeb7..444c0625 100644 --- a/modules/forums/server/controllers/forums.server.controller.js +++ b/modules/forums/server/controllers/forums.server.controller.js @@ -138,7 +138,20 @@ exports.list = function (req, res) { * @param res */ exports.read = function (req, res) { - res.json(req.forum); + var forum = req.forum; + var user = req.user; + + if (forum.vipOnly && !user.isVip && !user.isOper) { + return res.status(422).send({ + redirect: 'forums.list' + }); + } else if (forum.operOnly && !user.isOper) { + return res.status(422).send({ + redirect: 'forums.list' + }); + } else { + res.json(req.forum); + } }; /** @@ -280,6 +293,8 @@ exports.listTopics = function (req, res) { * @param res */ exports.globalTopics = function (req, res) { + var user = req.user; + Forum.find().exec(function (err, forums) { if (err) { return res.status(422).send({ @@ -287,10 +302,16 @@ exports.globalTopics = function (req, res) { }); } else { var ids = forums.map(function (el) { - return el._id; + if (el.vipOnly && !user.isVip && !user.isOper) { + return undefined; + } else if (el.operOnly && !user.isOper) { + return undefined; + } else { + return el._id; + } }); - console.log(ids); + //console.log(ids); Topic.find({ isGlobal: true,