mirror of
https://github.com/reality/dbot.git
synced 2024-11-23 12:29:26 +01:00
fine tuned web permissions [close #553]
This commit is contained in:
parent
45eb778560
commit
e5c51682fb
@ -4,5 +4,8 @@
|
||||
"dependencies": [ "users" ],
|
||||
"dbType": "redis",
|
||||
"requireWebLogin": true,
|
||||
"webAccess": "power_users"
|
||||
"webAccess": "regular",
|
||||
"pageAccess": {
|
||||
"/report/:server/:channel": "power_users"
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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]}
|
||||
|
Loading…
Reference in New Issue
Block a user