mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Handle scoped node modules in the api
This commit is contained in:
parent
d7715b05ee
commit
9e26aeea1d
@ -126,12 +126,12 @@ function init(_server,_runtime) {
|
|||||||
adminApp.get("/nodes",needsPermission("nodes.read"),nodes.getAll,errorHandler);
|
adminApp.get("/nodes",needsPermission("nodes.read"),nodes.getAll,errorHandler);
|
||||||
adminApp.post("/nodes",needsPermission("nodes.write"),nodes.post,errorHandler);
|
adminApp.post("/nodes",needsPermission("nodes.write"),nodes.post,errorHandler);
|
||||||
|
|
||||||
adminApp.get("/nodes/:mod",needsPermission("nodes.read"),nodes.getModule,errorHandler);
|
adminApp.get(/\/nodes\/((@[^\/]+\/)?[^\/]+)$/,needsPermission("nodes.read"),nodes.getModule,errorHandler);
|
||||||
adminApp.put("/nodes/:mod",needsPermission("nodes.write"),nodes.putModule,errorHandler);
|
adminApp.put(/\/nodes\/((@[^\/]+\/)?[^\/]+)$/,needsPermission("nodes.write"),nodes.putModule,errorHandler);
|
||||||
adminApp.delete("/nodes/:mod",needsPermission("nodes.write"),nodes.delete,errorHandler);
|
adminApp.delete(/\/nodes\/((@[^\/]+\/)?[^\/]+)$/,needsPermission("nodes.write"),nodes.delete,errorHandler);
|
||||||
|
|
||||||
adminApp.get("/nodes/:mod/:set",needsPermission("nodes.read"),nodes.getSet,errorHandler);
|
adminApp.get(/\/nodes\/((@[^\/]+\/)?[^\/]+)\/([^\/]+)$/,needsPermission("nodes.read"),nodes.getSet,errorHandler);
|
||||||
adminApp.put("/nodes/:mod/:set",needsPermission("nodes.write"),nodes.putSet,errorHandler);
|
adminApp.put(/\/nodes\/((@[^\/]+\/)?[^\/]+)\/([^\/]+)$/,needsPermission("nodes.write"),nodes.putSet,errorHandler);
|
||||||
|
|
||||||
adminApp.get('/credentials/:type/:id', needsPermission("credentials.read"),credentials.get,errorHandler);
|
adminApp.get('/credentials/:type/:id', needsPermission("credentials.read"),credentials.get,errorHandler);
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ module.exports = {
|
|||||||
res.status(400).json({error:"settings_unavailable", message:"Settings unavailable"});
|
res.status(400).json({error:"settings_unavailable", message:"Settings unavailable"});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var mod = req.params.mod;
|
var mod = req.params[0];
|
||||||
try {
|
try {
|
||||||
var promise = null;
|
var promise = null;
|
||||||
var module = redNodes.getModuleInfo(mod);
|
var module = redNodes.getModuleInfo(mod);
|
||||||
@ -114,7 +114,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getSet: function(req,res) {
|
getSet: function(req,res) {
|
||||||
var id = req.params.mod + "/" + req.params.set;
|
var id = req.params[0] + "/" + req.params[2];
|
||||||
var result = null;
|
var result = null;
|
||||||
if (req.get("accept") === "application/json") {
|
if (req.get("accept") === "application/json") {
|
||||||
result = redNodes.getNodeInfo(id);
|
result = redNodes.getNodeInfo(id);
|
||||||
@ -140,7 +140,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getModule: function(req,res) {
|
getModule: function(req,res) {
|
||||||
var module = req.params.mod;
|
var module = req.params[0];
|
||||||
var result = redNodes.getModuleInfo(module);
|
var result = redNodes.getModuleInfo(module);
|
||||||
if (result) {
|
if (result) {
|
||||||
log.audit({event: "nodes.module.get",module:module},req);
|
log.audit({event: "nodes.module.get",module:module},req);
|
||||||
@ -163,7 +163,7 @@ module.exports = {
|
|||||||
res.status(400).json({error:"invalid_request", message:"Invalid request"});
|
res.status(400).json({error:"invalid_request", message:"Invalid request"});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var id = req.params.mod + "/" + req.params.set;
|
var id = req.params[0] + "/" + req.params[2];
|
||||||
try {
|
try {
|
||||||
var node = redNodes.getNodeInfo(id);
|
var node = redNodes.getNodeInfo(id);
|
||||||
var info;
|
var info;
|
||||||
@ -195,7 +195,7 @@ module.exports = {
|
|||||||
res.status(400).json({error:"invalid_request", message:"Invalid request"});
|
res.status(400).json({error:"invalid_request", message:"Invalid request"});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var mod = req.params.mod;
|
var mod = req.params[0];
|
||||||
try {
|
try {
|
||||||
var module = redNodes.getModuleInfo(mod);
|
var module = redNodes.getModuleInfo(mod);
|
||||||
if (!module) {
|
if (!module) {
|
||||||
|
@ -67,11 +67,13 @@ function filterNodeInfo(n) {
|
|||||||
|
|
||||||
|
|
||||||
function getModule(id) {
|
function getModule(id) {
|
||||||
return id.split("/")[0];
|
var parts = id.split("/");
|
||||||
|
return parts.slice(0,parts.length-1).join("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNode(id) {
|
function getNode(id) {
|
||||||
return id.split("/")[1];
|
var parts = id.split("/");
|
||||||
|
return parts[parts.length-1];
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveNodeList() {
|
function saveNodeList() {
|
||||||
|
@ -44,10 +44,10 @@ describe("nodes api", function() {
|
|||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
app.get("/nodes",nodes.getAll);
|
app.get("/nodes",nodes.getAll);
|
||||||
app.post("/nodes",nodes.post);
|
app.post("/nodes",nodes.post);
|
||||||
app.get("/nodes/:mod",nodes.getModule);
|
app.get(/\/nodes\/((@[^\/]+\/)?[^\/]+)$/,nodes.getModule);
|
||||||
app.get("/nodes/:mod/:set",nodes.getSet);
|
app.get(/\/nodes\/((@[^\/]+\/)?[^\/]+)\/([^\/]+)$/,nodes.getSet);
|
||||||
app.put("/nodes/:mod",nodes.putModule);
|
app.put(/\/nodes\/((@[^\/]+\/)?[^\/]+)$/,nodes.putModule);
|
||||||
app.put("/nodes/:mod/:set",nodes.putSet);
|
app.put(/\/nodes\/((@[^\/]+\/)?[^\/]+)\/([^\/]+)$/,nodes.putSet);
|
||||||
app.delete("/nodes/:id",nodes.delete);
|
app.delete("/nodes/:id",nodes.delete);
|
||||||
sinon.stub(comms,"publish");
|
sinon.stub(comms,"publish");
|
||||||
sinon.stub(locales,"determineLangFromHeaders", function() {
|
sinon.stub(locales,"determineLangFromHeaders", function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user