Tie auth middleware to needsPermission api

This commit is contained in:
Nick O'Leary
2015-02-05 23:43:35 +00:00
parent 3ef6f29d6e
commit c31ffb98b0
11 changed files with 36 additions and 135 deletions

View File

@@ -17,10 +17,11 @@
var redApp = null;
var storage = require("../storage");
var log = require("../log");
var needsPermission = require("./auth").needsPermission;
function createLibrary(type) {
if (redApp) {
redApp.get(new RegExp("/library/"+type+"($|\/(.*))"),function(req,res) {
redApp.get(new RegExp("/library/"+type+"($|\/(.*))"),needsPermission("library.read"),function(req,res) {
var path = req.params[1]||"";
storage.getLibraryEntry(type,path).then(function(result) {
if (typeof result === "string") {
@@ -42,7 +43,7 @@ function createLibrary(type) {
});
});
redApp.post(new RegExp("/library/"+type+"\/(.*)"),function(req,res) {
redApp.post(new RegExp("/library/"+type+"\/(.*)"),needsPermission("library.write"),function(req,res) {
var path = req.params[0];
var fullBody = '';
req.on('data', function(chunk) {