fix: Fix template credential setup for nodes that dont have credentials (#8208)
Fix template credential setup for templates whose workflow includes nodes that require credentials but the workflow definition does not have them defined. Like for example https://n8n.io/workflows/1344-save-email-attachments-to-nextcloud/
This commit is contained in:
33
packages/editor-ui/src/utils/nodes/nodeTransforms.ts
Normal file
33
packages/editor-ui/src/utils/nodes/nodeTransforms.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import type { INodeUi } from '@/Interface';
|
||||
import type { NodeTypeProvider } from '@/utils/nodeTypes/nodeTypeTransforms';
|
||||
import type { INodeCredentialDescription } from 'n8n-workflow';
|
||||
import { NodeHelpers } from 'n8n-workflow';
|
||||
|
||||
/**
|
||||
* Returns the credentials that are displayable for the given node.
|
||||
*/
|
||||
export function getNodeTypeDisplayableCredentials(
|
||||
nodeTypeProvider: NodeTypeProvider,
|
||||
node: Pick<INodeUi, 'parameters' | 'type' | 'typeVersion'>,
|
||||
): INodeCredentialDescription[] {
|
||||
const nodeType = nodeTypeProvider.getNodeType(node.type, node.typeVersion);
|
||||
if (!nodeType?.credentials) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const nodeTypeCreds = nodeType.credentials;
|
||||
|
||||
// We must populate the node's parameters with the default values
|
||||
// before we can check which credentials are available, because
|
||||
// credentials can have conditional requirements that depend on
|
||||
// node parameters.
|
||||
const nodeParameters =
|
||||
NodeHelpers.getNodeParameters(nodeType.properties, node.parameters, true, false, node) ??
|
||||
node.parameters;
|
||||
|
||||
const displayableCredentials = nodeTypeCreds.filter((credentialTypeDescription) => {
|
||||
return NodeHelpers.displayParameter(nodeParameters, credentialTypeDescription, node);
|
||||
});
|
||||
|
||||
return displayableCredentials;
|
||||
}
|
||||
Reference in New Issue
Block a user