From f1442edf341f48068cf6838cd3a6fbaa13a950fc Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 6 Jun 2014 01:16:30 +0000 Subject: [PATCH] fix web perms --- modules/report/config.json | 2 +- modules/web/api.js | 38 +++++++++++++++++++------------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/modules/report/config.json b/modules/report/config.json index 477cf9f..bbcef47 100644 --- a/modules/report/config.json +++ b/modules/report/config.json @@ -6,7 +6,7 @@ "requireWebLogin": true, "webAccess": "regular", "pageAccess": { - "/report/:server/:channel": "power_users" + "/report/:server/:channel": "power_user" }, "colours": { "wherever": { diff --git a/modules/web/api.js b/modules/web/api.js index 35ae89e..64f7f05 100644 --- a/modules/web/api.js +++ b/modules/web/api.js @@ -22,35 +22,35 @@ var api = function(dbot) { 'hasAccess': function(req, res, next) { var path = req.route.path, module = dbot.pages[path].module, - mConfig = dbot.config.modules[module]; + mConfig = dbot.config.modules[module], + accessNeeded, + allowedNicks; if(mConfig.requireWebLogin == true) { if(req.isAuthenticated()) { - var accessNeeded = 'regular'; - if(_.has(mConfig, 'pageAccess') && _.has(mConfig.pageAccess, path)) { + if(_.has(mConfig.pageAccess, path)) { accessNeeded = mConfig.pageAccess[path]; } else if(!_.isUndefined(mConfig.webAccess)) { accessNeeded = mConfig.webAccess; } - if(accessNeeded != 'regular') { - var allowedUsers = dbot.config.admins; - if(mConfig.webAccess == 'moderators') { - allowedUsers = _.union(allowedUsers, dbot.config.moderators); - } - if(mConfig.webAccess == 'power_users') { - allowedUsers = _.union(allowedUsers, dbot.config.moderators); - allowedUsers = _.union(allowedUsers, dbot.config.power_users); - } - - if(_.include(allowedUsers, req.user.primaryNick)) { - return next(); - } else { - res.redirect('/'); - } - } else { + if(!_.isUndefined(accessNeeded) || accessNeeded == null) { return next(); } + + if(!_.isFunction(accessNeeded)) { + if(_.has(dbot.access, accessNeeded)) { + accessNeeded = dbot.access[accessNeeded]; + } else { + return next(); + } + } + + if(_.include(allowedUsers, req.user.primaryNick)) { + return next(); + } else { + res.redirect('/'); + } } else { res.render('login', { 'message': 'You need to log in to access this module.',