From 405b3d47e4d55ad681b6a467f51265356db53d04 Mon Sep 17 00:00:00 2001 From: reality Date: Sat, 24 Aug 2013 13:56:45 +0000 Subject: [PATCH] Create addIndexLink api func for web to link to index not based on module name. Correct titles for notifications + bans. Also hopefully fix the fineWebPerms access for PUs/Mods [close #565] --- modules/kick/kick.js | 4 ++++ modules/kick/pages.js | 4 ++-- modules/report/pages.js | 8 ++++---- modules/report/report.js | 6 ++++++ modules/web/web.js | 28 ++++++++++++++++------------ views/index.jade | 4 ++-- views/kick/bans.jade | 2 +- views/kick/servers.jade | 2 +- views/report/channels.jade | 4 ++-- views/report/missing_notifies.jade | 2 +- views/report/notifies.jade | 2 +- views/report/servers.jade | 4 ++-- 12 files changed, 42 insertions(+), 28 deletions(-) diff --git a/modules/kick/kick.js b/modules/kick/kick.js index a4902a9..f32188b 100644 --- a/modules/kick/kick.js +++ b/modules/kick/kick.js @@ -126,6 +126,10 @@ var kick = function(dbot) { this.internalAPI.addTempBan(server, nick, timeout); }, this); }, this); + + if(_.has(dbot.modules, 'web')) { + dbot.api.web.addIndexLink('/bans', 'Ban List'); + } }.bind(this); }; diff --git a/modules/kick/pages.js b/modules/kick/pages.js index a16c91d..ed9626f 100644 --- a/modules/kick/pages.js +++ b/modules/kick/pages.js @@ -2,13 +2,13 @@ var _ = require('underscore')._; var pages = function(dbot) { return { - '/kick': function(req, res) { + '/bans': function(req, res) { res.render('servers', { 'servers': _.keys(dbot.config.servers) }); }, - '/kick/:server': function(req, res) { + '/bans/:server': function(req, res) { var server = req.params.server, bans = []; diff --git a/modules/report/pages.js b/modules/report/pages.js index ba1e0fd..f85bf1f 100644 --- a/modules/report/pages.js +++ b/modules/report/pages.js @@ -2,14 +2,14 @@ var _ = require('underscore')._; var pages = function(dbot) { var pages = { - '/report': function(req, res) { + '/notify': function(req, res) { res.render('servers', { 'name': dbot.config.name, 'servers': _.keys(dbot.config.servers) }); }, - '/report/:server': function(req, res) { + '/notify/:server': function(req, res) { var server = req.params.server; res.render('channels', { 'name': dbot.config.name, @@ -18,7 +18,7 @@ var pages = function(dbot) { }); }, - '/report/:server/missing': function(req, res) { + '/notify/:server/missing': function(req, res) { var server = req.params.server, user = req.user, notifies = this.pending[user.id]; @@ -35,7 +35,7 @@ var pages = function(dbot) { } }, - '/report/:server/:channel': function(req, res) { + '/notify/:server/:channel': function(req, res) { var server = req.params.server, channel = req.params.channel, notifies = []; diff --git a/modules/report/report.js b/modules/report/report.js index 4a8d8ff..9cc606f 100644 --- a/modules/report/report.js +++ b/modules/report/report.js @@ -184,6 +184,12 @@ var report = function(dbot) { commands['~report'].regex = [/^~report ([^ ]+) ([^ ]+) (.+)$/, 4]; commands['~notify'].regex = [/^~notify ([^ ]+) (.+)$/, 3]; this.commands = commands; + + this.onLoad = function() { + if(_.has(dbot.modules, 'web')) { + dbot.api.web.addIndexLink('/notify', 'Notifications'); + } + }; }; exports.fetch = function(dbot) { diff --git a/modules/web/web.js b/modules/web/web.js index 7b7efd1..58aaccb 100644 --- a/modules/web/web.js +++ b/modules/web/web.js @@ -8,6 +8,7 @@ var express = require('express'), var webInterface = function(dbot) { this.config = dbot.config.modules.web; + this.indexLinks = {}; this.pub = 'public'; this.app = express(); @@ -85,25 +86,25 @@ var webInterface = function(dbot) { }.bind(this); this.onLoad = function() { - var routes = _.pluck(dbot.modules.web.app.routes.get, 'path'); - var moduleNames = _.keys(dbot.modules); - var indexModules = []; + var routes = _.pluck(dbot.modules.web.app.routes.get, 'path'), + moduleNames = _.keys(dbot.modules); - // fix the thingy _.each(moduleNames, function(moduleName) { var modulePath = '/' + moduleName; if(_.include(routes, modulePath)) { - indexModules.push(moduleName); + moduleName = moduleName.charAt(0).toUpperCase() + + moduleName.slice(1); + this.indexLinks[modulePath] = moduleName; } - }); + }.bind(this)); this.app.get('/', function(req, res) { res.render('index', { 'name': dbot.config.name, 'user': req.user, - 'routes': indexModules + 'routes': this.indexLinks }); - }); + }.bind(this)); this.app.get('/login', function(req, res) { res.render('login', { @@ -147,6 +148,10 @@ var webInterface = function(dbot) { } }, + 'addIndexLink': function(route, title) { + this.indexLinks[route] = title; + }, + 'getWebUser': function(id, callback) { this.db.read('web_users', id, function(err, webUser) { callback(webUser); @@ -155,9 +160,8 @@ var webInterface = function(dbot) { 'hasAccess': function(req, res, next) { var path = req.route.path, - module = path.split('/')[1], + module = dbot.pages[path].module, mConfig = dbot.config.modules[module]; - module = dbot.modules[module]; if(mConfig.requireWebLogin == true) { if(req.isAuthenticated()) { @@ -170,10 +174,10 @@ var webInterface = function(dbot) { if(accessNeeded != 'regular') { var allowedUsers = dbot.config.admins; - if(module.config.webAccess == 'moderators') { + if(mConfig.webAccess == 'moderators') { allowedUsers = _.union(allowedUsers, dbot.config.moderators); } - if(module.config.webAccess == 'power_users') { + if(mConfig.webAccess == 'power_users') { allowedUsers = _.union(allowedUsers, dbot.config.moderators); allowedUsers = _.union(allowedUsers, dbot.config.power_users); } diff --git a/views/index.jade b/views/index.jade index 96f13c9..c3a7829 100644 --- a/views/index.jade +++ b/views/index.jade @@ -4,5 +4,5 @@ block content if message p #{message} #modulelinks - - for(var i=0;i