forked from GitHub/dbot
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]
This commit is contained in:
parent
165c9491a9
commit
405b3d47e4
@ -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);
|
||||
};
|
||||
|
||||
|
@ -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 = [];
|
||||
|
||||
|
@ -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 = [];
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -4,5 +4,5 @@ block content
|
||||
if message
|
||||
p #{message}
|
||||
#modulelinks
|
||||
- for(var i=0;i<routes.length;i++)
|
||||
a.module(href='/'+routes[i]) #{routes[i]}
|
||||
for title, route in routes
|
||||
a.module(href=route) #{title}
|
||||
|
@ -2,7 +2,7 @@ extends ../layout
|
||||
|
||||
block content
|
||||
div#backlink
|
||||
a(href='/kick/') « Servers
|
||||
a(href='/bans/') « Servers
|
||||
p
|
||||
div#profile_datatable
|
||||
table.table.table-hover.data
|
||||
|
@ -6,5 +6,5 @@ block content
|
||||
a(href='/') « Home
|
||||
ul#quotelist
|
||||
-each server in servers
|
||||
a(href='/kick/'+server)
|
||||
a(href='/bans/'+server)
|
||||
li.quotes #{server}
|
||||
|
@ -3,8 +3,8 @@ extends ../layout
|
||||
block content
|
||||
h3 Channels on #{server}
|
||||
div#backlink
|
||||
a(href='/report') « Server List
|
||||
a(href='/notify') « Server List
|
||||
ul#quotelist
|
||||
-each channel in channels
|
||||
a(href='/report/'+server+'/'+encodeURIComponent(channel))
|
||||
a(href='/notify/'+server+'/'+encodeURIComponent(channel))
|
||||
li.quotes #{channel}
|
||||
|
@ -3,7 +3,7 @@ extends ../layout
|
||||
block content
|
||||
h3 Notifications Missed by #{user.primaryNick}
|
||||
div#backlink
|
||||
a(href='/report') « Notifications
|
||||
a(href='/notify') « Notifications
|
||||
p
|
||||
if notifies
|
||||
div#profile_datatable
|
||||
|
@ -2,7 +2,7 @@ extends ../layout
|
||||
|
||||
block content
|
||||
div#backlink
|
||||
a(href='/report/'+server) « Server Channels
|
||||
a(href='/notify/'+server) « Server Channels
|
||||
p
|
||||
div#profile_datatable
|
||||
table.table.table-hover.data
|
||||
|
@ -5,8 +5,8 @@ block content
|
||||
div#backlink
|
||||
a(href='/') « Home
|
||||
div
|
||||
a(href='/report/'+user.server+'/missing') My Missed Notifications
|
||||
a(href='/notify/'+user.server+'/missing') My Missed Notifications
|
||||
ul#quotelist
|
||||
-each server in servers
|
||||
a(href='/report/'+server)
|
||||
a(href='/notify/'+server)
|
||||
li.quotes #{server}
|
||||
|
Loading…
Reference in New Issue
Block a user