mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Rework saving of credentials to undo history
This commit is contained in:
parent
66bd1feb47
commit
89e40a0b8f
@ -495,11 +495,12 @@ RED.history = (function() {
|
|||||||
// Reset - Only want to keep the changes
|
// Reset - Only want to keep the changes
|
||||||
inverseEv.changes[i] = {};
|
inverseEv.changes[i] = {};
|
||||||
for (const [key, value] of Object.entries(ev.changes[i])) {
|
for (const [key, value] of Object.entries(ev.changes[i])) {
|
||||||
inverseEv.changes[i][key] = ev.node.credentials[key];
|
// Edge case: node.credentials is cleared after a deploy, so we can't
|
||||||
ev.node.credentials[key] = value;
|
// capture values for the inverse event when undoing past a deploy
|
||||||
if (ev.node._def.credentials[key]?.type === 'password') {
|
if (ev.node.credentials) {
|
||||||
ev.node.credentials['has_' + key] = !!value;
|
inverseEv.changes[i][key] = ev.node.credentials[key];
|
||||||
}
|
}
|
||||||
|
ev.node.credentials[key] = value;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ev.node[i] = ev.changes[i];
|
ev.node[i] = ev.changes[i];
|
||||||
|
@ -808,17 +808,6 @@ RED.editor = (function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const oldCreds = {};
|
|
||||||
if (editing_node._def.credentials) {
|
|
||||||
for (const prop in editing_node._def.credentials) {
|
|
||||||
if (Object.prototype.hasOwnProperty.call(editing_node._def.credentials, prop)) {
|
|
||||||
if (prop in editing_node.credentials) {
|
|
||||||
oldCreds[prop] = editing_node.credentials[prop];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const rc = editing_node._def.oneditsave.call(editing_node);
|
const rc = editing_node._def.oneditsave.call(editing_node);
|
||||||
if (rc === true) {
|
if (rc === true) {
|
||||||
@ -850,24 +839,6 @@ RED.editor = (function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (editing_node._def.credentials) {
|
|
||||||
for (const prop in editing_node._def.credentials) {
|
|
||||||
if (Object.prototype.hasOwnProperty.call(editing_node._def.credentials, prop)) {
|
|
||||||
if (oldCreds[prop] !== editing_node.credentials[prop]) {
|
|
||||||
if (editing_node.credentials[prop] === '__PWRD__') {
|
|
||||||
// The password may not exist in oldCreds
|
|
||||||
// The value '__PWRD__' means the password exists,
|
|
||||||
// so ignore this change
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
editState.changes.credentials = editState.changes.credentials || {};
|
|
||||||
editState.changes.credentials[prop] = oldCreds[prop];
|
|
||||||
editState.changed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,6 +195,7 @@
|
|||||||
// Like the user sets a value, saves the config,
|
// Like the user sets a value, saves the config,
|
||||||
// reopens the config and save the config again
|
// reopens the config and save the config again
|
||||||
} else {
|
} else {
|
||||||
|
changes['has_' + cred] = node.credentials['has_' + cred];
|
||||||
changes[cred] = node.credentials[cred];
|
changes[cred] = node.credentials[cred];
|
||||||
node.credentials[cred] = value;
|
node.credentials[cred] = value;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user