3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-27 14:29:29 +01:00

fine tuned web permissions [close #553]

This commit is contained in:
reality 2013-08-18 17:32:57 +00:00
parent 45eb778560
commit e5c51682fb
4 changed files with 24 additions and 7 deletions

View File

@ -4,5 +4,8 @@
"dependencies": [ "users" ],
"dbType": "redis",
"requireWebLogin": true,
"webAccess": "power_users"
"webAccess": "regular",
"pageAccess": {
"/report/:server/:channel": "power_users"
}
}

View File

@ -1,7 +1,7 @@
var _ = require('underscore')._;
var pages = function(dbot) {
return {
var pages = {
'/report': function(req, res) {
res.render('servers', {
'name': dbot.config.name,
@ -54,6 +54,8 @@ var pages = function(dbot) {
});
}
};
return pages;
};
exports.fetch = function(dbot) {

View File

@ -63,8 +63,9 @@ var webInterface = function(dbot) {
var pages = dbot.pages;
for(var p in pages) {
if(_.has(pages, p)) {
var func = pages[p];
var mod = func.module;
var func = pages[p],
mod = func.module;
this.app.get(p, this.api.hasAccess, (function(req, resp) {
// Crazy shim to seperate module views.
var shim = Object.create(resp);
@ -149,12 +150,21 @@ var webInterface = function(dbot) {
},
'hasAccess': function(req, res, next) {
var module = req.route.path.split('/')[1];
var path = req.route.path,
module = path.split('/')[1],
mConfig = dbot.config.modules[module];
module = dbot.modules[module];
if(module.config.requireWebLogin == true) {
if(mConfig.requireWebLogin == true) {
if(req.isAuthenticated()) {
if(!_.isUndefined(module.config.webAccess)) {
var accessNeeded = 'regular';
if(_.has(mConfig, 'pageAccess') && _.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(module.config.webAccess == 'moderators') {
allowedUsers = _.union(allowedUsers, dbot.config.moderators);

View File

@ -1,6 +1,8 @@
extends layout
block content
if message
p #{message}
#modulelinks
- for(var i=0;i<routes.length;i++)
a.module(href='/'+routes[i]) #{routes[i]}