Merge pull request #4983 from node-red/gg-changes-2

Rework saving of credentials to undo history
This commit is contained in:
Nick O'Leary 2024-12-10 15:43:08 +00:00 committed by GitHub
commit a50a37ac26
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 4 deletions

View File

@ -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];

View File

@ -812,6 +812,9 @@ RED.editor = (function() {
if (editing_node._def.credentials) { if (editing_node._def.credentials) {
for (const prop in editing_node._def.credentials) { for (const prop in editing_node._def.credentials) {
if (Object.prototype.hasOwnProperty.call(editing_node._def.credentials, prop)) { if (Object.prototype.hasOwnProperty.call(editing_node._def.credentials, prop)) {
if (editing_node._def.credentials[prop].type === 'password') {
oldCreds['has_' + prop] = editing_node.credentials['has_' + prop];
}
if (prop in editing_node.credentials) { if (prop in editing_node.credentials) {
oldCreds[prop] = editing_node.credentials[prop]; oldCreds[prop] = editing_node.credentials[prop];
} }
@ -862,6 +865,7 @@ RED.editor = (function() {
continue; continue;
} }
editState.changes.credentials = editState.changes.credentials || {}; editState.changes.credentials = editState.changes.credentials || {};
editState.changes.credentials['has_' + prop] = oldCreds['has_' + prop];
editState.changes.credentials[prop] = oldCreds[prop]; editState.changes.credentials[prop] = oldCreds[prop];
editState.changed = true; editState.changed = true;
} }

View File

@ -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;
} }