mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix: Remove foreign credentials when copying nodes or duplicating workflow (#4880)
* fix: Remove foreign credentials when copying nodes or duplicating workflow * chore: fix linting issue
This commit is contained in:
@@ -67,6 +67,7 @@ import { useTemplatesStore } from '@/stores/templates';
|
||||
import { useNodeTypesStore } from '@/stores/nodeTypes';
|
||||
import useWorkflowsEEStore from "@/stores/workflows.ee";
|
||||
import {useUsersStore} from "@/stores/users";
|
||||
import {ICredentialMap, ICredentialsResponse, IUsedCredential} from "@/Interface";
|
||||
|
||||
let cachedWorkflowKey: string | null = '';
|
||||
let cachedWorkflow: Workflow | null = null;
|
||||
@@ -928,5 +929,23 @@ export const workflowHelpers = mixins(
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
removeForeignCredentialsFromWorkflow(workflow: IWorkflowData | IWorkflowDataUpdate, usableCredentials: ICredentialsResponse[]): void {
|
||||
workflow.nodes.forEach((node: INode) => {
|
||||
if (!node.credentials) {
|
||||
return;
|
||||
}
|
||||
|
||||
node.credentials = Object.entries(node.credentials)
|
||||
.reduce<INodeCredentials>((acc, [credentialType, credential]) => {
|
||||
const isUsableCredential = usableCredentials.some((ownCredential) => `${ownCredential.id}` === `${credential.id}`);
|
||||
if (credential.id && isUsableCredential) {
|
||||
acc[credentialType] = node.credentials![credentialType];
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user