mirror of
https://github.com/reality/dbot.git
synced 2024-11-23 20:39:25 +01:00
fine tuned web permissions [close #553]
This commit is contained in:
parent
45eb778560
commit
e5c51682fb
@ -4,5 +4,8 @@
|
|||||||
"dependencies": [ "users" ],
|
"dependencies": [ "users" ],
|
||||||
"dbType": "redis",
|
"dbType": "redis",
|
||||||
"requireWebLogin": true,
|
"requireWebLogin": true,
|
||||||
"webAccess": "power_users"
|
"webAccess": "regular",
|
||||||
|
"pageAccess": {
|
||||||
|
"/report/:server/:channel": "power_users"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
var _ = require('underscore')._;
|
var _ = require('underscore')._;
|
||||||
|
|
||||||
var pages = function(dbot) {
|
var pages = function(dbot) {
|
||||||
return {
|
var pages = {
|
||||||
'/report': function(req, res) {
|
'/report': function(req, res) {
|
||||||
res.render('servers', {
|
res.render('servers', {
|
||||||
'name': dbot.config.name,
|
'name': dbot.config.name,
|
||||||
@ -54,6 +54,8 @@ var pages = function(dbot) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return pages;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.fetch = function(dbot) {
|
exports.fetch = function(dbot) {
|
||||||
|
@ -63,8 +63,9 @@ var webInterface = function(dbot) {
|
|||||||
var pages = dbot.pages;
|
var pages = dbot.pages;
|
||||||
for(var p in pages) {
|
for(var p in pages) {
|
||||||
if(_.has(pages, p)) {
|
if(_.has(pages, p)) {
|
||||||
var func = pages[p];
|
var func = pages[p],
|
||||||
var mod = func.module;
|
mod = func.module;
|
||||||
|
|
||||||
this.app.get(p, this.api.hasAccess, (function(req, resp) {
|
this.app.get(p, this.api.hasAccess, (function(req, resp) {
|
||||||
// Crazy shim to seperate module views.
|
// Crazy shim to seperate module views.
|
||||||
var shim = Object.create(resp);
|
var shim = Object.create(resp);
|
||||||
@ -149,12 +150,21 @@ var webInterface = function(dbot) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
'hasAccess': function(req, res, next) {
|
'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];
|
module = dbot.modules[module];
|
||||||
|
|
||||||
if(module.config.requireWebLogin == true) {
|
if(mConfig.requireWebLogin == true) {
|
||||||
if(req.isAuthenticated()) {
|
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;
|
var allowedUsers = dbot.config.admins;
|
||||||
if(module.config.webAccess == 'moderators') {
|
if(module.config.webAccess == 'moderators') {
|
||||||
allowedUsers = _.union(allowedUsers, dbot.config.moderators);
|
allowedUsers = _.union(allowedUsers, dbot.config.moderators);
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
extends layout
|
extends layout
|
||||||
|
|
||||||
block content
|
block content
|
||||||
|
if message
|
||||||
|
p #{message}
|
||||||
#modulelinks
|
#modulelinks
|
||||||
- for(var i=0;i<routes.length;i++)
|
- for(var i=0;i<routes.length;i++)
|
||||||
a.module(href='/'+routes[i]) #{routes[i]}
|
a.module(href='/'+routes[i]) #{routes[i]}
|
||||||
|
Loading…
Reference in New Issue
Block a user