From a494954275348ef875aae884d9e480fc06f88a62 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Wed, 10 Dec 2014 14:16:07 +0000 Subject: [PATCH] Add permissions and user menu --- nodes/core/core/20-inject.js | 28 +++--- nodes/core/core/58-debug.js | 2 +- public/index.html | 11 +- public/red/comms.js | 28 ++++-- public/red/main.js | 138 +++++++------------------- public/red/settings.js | 31 +++++- public/red/ui/menu.js | 8 +- public/red/user.js | 117 ++++++++++++++++++++++ red/api/auth/index.js | 14 ++- red/api/auth/permissions.js | 50 ++++++++++ red/api/auth/strategies.js | 30 +++++- red/api/auth/users.js | 88 ++++++++++++---- red/api/index.js | 29 +++--- red/comms.js | 88 ++++++++++------ red/red.js | 4 + red/settings.js | 3 - test/red/api/auth/permissions_spec.js | 0 17 files changed, 458 insertions(+), 211 deletions(-) create mode 100644 public/red/user.js create mode 100644 red/api/auth/permissions.js create mode 100644 test/red/api/auth/permissions_spec.js diff --git a/nodes/core/core/20-inject.js b/nodes/core/core/20-inject.js index b97f11900..f840f0d2f 100644 --- a/nodes/core/core/20-inject.js +++ b/nodes/core/core/20-inject.js @@ -79,20 +79,20 @@ module.exports = function(RED) { delete this.cronjob; } } - - RED.httpAdmin.post("/inject/:id", function(req,res) { - var node = RED.nodes.getNode(req.params.id); - if (node != null) { - try { - node.receive(); - res.send(200); - } catch(err) { - res.send(500); - node.error("Inject failed:"+err); - console.log(err.stack); - } - } else { - res.send(404); + + RED.httpAdmin.post("/inject/:id", RED.auth.needsPermission("inject.write"), function(req,res) { + var node = RED.nodes.getNode(req.params.id); + if (node != null) { + try { + node.receive(); + res.send(200); + } catch(err) { + res.send(500); + node.error("Inject failed:"+err); + console.log(err.stack); } + } else { + res.send(404); + } }); } diff --git a/nodes/core/core/58-debug.js b/nodes/core/core/58-debug.js index b8106e2b0..d89f2dbc0 100644 --- a/nodes/core/core/58-debug.js +++ b/nodes/core/core/58-debug.js @@ -119,7 +119,7 @@ module.exports = function(RED) { }); RED.log.addHandler(DebugNode.logHandler); - RED.httpAdmin.post("/debug/:id/:state", function(req,res) { + RED.httpAdmin.post("/debug/:id/:state", RED.auth.needsPermission("debug.write"), function(req,res) { var node = RED.nodes.getNode(req.params.id); var state = req.params.state; if (node !== null && typeof node !== "undefined" ) { diff --git a/public/index.html b/public/index.html index c4b4a2c41..2dfc882c9 100644 --- a/public/index.html +++ b/public/index.html @@ -36,7 +36,7 @@ Deploy -
  • +