1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Allow nodes to be imported with their credentials

This commit is contained in:
Nick O'Leary 2016-09-30 14:15:04 +01:00
parent 300a8d3a89
commit 538a16a5fb
2 changed files with 30 additions and 6 deletions

View File

@ -426,11 +426,12 @@ RED.nodes = (function() {
for (var cred in n._def.credentials) { for (var cred in n._def.credentials) {
if (n._def.credentials.hasOwnProperty(cred)) { if (n._def.credentials.hasOwnProperty(cred)) {
if (n._def.credentials[cred].type == 'password') { if (n._def.credentials[cred].type == 'password') {
if (n.credentials["has_"+cred] != n.credentials._["has_"+cred] || if (!n.credentials._ ||
n.credentials["has_"+cred] != n.credentials._["has_"+cred] ||
(n.credentials["has_"+cred] && n.credentials[cred])) { (n.credentials["has_"+cred] && n.credentials[cred])) {
credentialSet[cred] = n.credentials[cred]; credentialSet[cred] = n.credentials[cred];
} }
} else if (n.credentials[cred] != null && n.credentials[cred] != n.credentials._[cred]) { } else if (n.credentials[cred] != null && (!n.credentials._ || n.credentials[cred] != n.credentials._[cred])) {
credentialSet[cred] = n.credentials[cred]; credentialSet[cred] = n.credentials[cred];
} }
} }
@ -722,6 +723,7 @@ RED.nodes = (function() {
var def; var def;
var configNode; var configNode;
var missingWorkspace = null; var missingWorkspace = null;
var d;
// Find all tabs and subflow templates // Find all tabs and subflow templates
for (i=0;i<newNodes.length;i++) { for (i=0;i<newNodes.length;i++) {
@ -830,11 +832,19 @@ RED.nodes = (function() {
if (!existingConfigNode) { //} || !compareNodes(existingConfigNode,n,true) || existingConfigNode._def.exclusive || existingConfigNode.z !== n.z) { if (!existingConfigNode) { //} || !compareNodes(existingConfigNode,n,true) || existingConfigNode._def.exclusive || existingConfigNode.z !== n.z) {
configNode = {id:n.id, z:n.z, type:n.type, users:[]}; configNode = {id:n.id, z:n.z, type:n.type, users:[]};
for (var d in def.defaults) { for (d in def.defaults) {
if (def.defaults.hasOwnProperty(d)) { if (def.defaults.hasOwnProperty(d)) {
configNode[d] = n[d]; configNode[d] = n[d];
} }
} }
if (def.hasOwnProperty('credentials') && n.hasOwnProperty('credentials')) {
configNode.credentials = {};
for (d in def.credentials) {
if (def.credentials.hasOwnProperty(d) && n.credentials.hasOwnProperty(d)) {
configNode.credentials[d] = n.credentials[d];
}
}
}
configNode.label = def.label; configNode.label = def.label;
configNode._def = def; configNode._def = def;
if (createNewIds) { if (createNewIds) {
@ -934,13 +944,24 @@ RED.nodes = (function() {
if (node._def.category != "config") { if (node._def.category != "config") {
node.inputs = n.inputs||node._def.inputs; node.inputs = n.inputs||node._def.inputs;
node.outputs = n.outputs||node._def.outputs; node.outputs = n.outputs||node._def.outputs;
for (var d2 in node._def.defaults) { for (d in node._def.defaults) {
if (node._def.defaults.hasOwnProperty(d2)) { if (node._def.defaults.hasOwnProperty(d)) {
node[d2] = n[d2]; node[d] = n[d];
}
}
if (node._def.hasOwnProperty('credentials') && n.hasOwnProperty('credentials')) {
node.credentials = {};
for (d in node._def.credentials) {
if (node._def.credentials.hasOwnProperty(d) && n.credentials.hasOwnProperty(d)) {
node.credentials[d] = n.credentials[d];
}
} }
} }
} }
} }
if (node.credentials) {
console.log(node);
}
addNode(node); addNode(node);
RED.editor.validateNode(node); RED.editor.validateNode(node);
node_map[n.id] = node; node_map[n.id] = node;

View File

@ -2281,6 +2281,9 @@ RED.view = (function() {
subflows:new_subflows, subflows:new_subflows,
dirty:RED.nodes.dirty() dirty:RED.nodes.dirty()
}; };
if (new_ms.length === 0) {
RED.nodes.dirty(true);
}
if (activeSubflow) { if (activeSubflow) {
var subflowRefresh = RED.subflow.refresh(true); var subflowRefresh = RED.subflow.refresh(true);
if (subflowRefresh) { if (subflowRefresh) {