From bd02a6127e9cb7074f3a4241d9bc81507718dc29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Mon, 2 May 2022 18:51:36 +0200 Subject: [PATCH] :zap: Fix marking as required after cred deletion --- .../src/components/mixins/nodeHelpers.ts | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/packages/editor-ui/src/components/mixins/nodeHelpers.ts b/packages/editor-ui/src/components/mixins/nodeHelpers.ts index b6bd096aef..de4fd62f0f 100644 --- a/packages/editor-ui/src/components/mixins/nodeHelpers.ts +++ b/packages/editor-ui/src/components/mixins/nodeHelpers.ts @@ -210,6 +210,10 @@ export const nodeHelpers = mixins( nodeCredentialType: string; }; + /** + * For HTTP Request node, report missing credential if no selected credential + * or if no selected credentials of the chosen generic auth type. + */ if ( node.type === HTTP_REQUEST_NODE_TYPE && node.typeVersion === 2 && @@ -228,6 +232,39 @@ export const nodeHelpers = mixins( }; } + /** + * For HTTP Request node, report missing credential if no selected credential + * and if ID of chosen credential ID does not match ID in DB, so it was deleted. + */ + if ( + node.type === HTTP_REQUEST_NODE_TYPE && + node.typeVersion === 2 && + authenticateWith === 'nodeCredential' && + nodeCredentialType !== '' && + node.credentials !== undefined + ) { + const credentialType = this.getCredentialTypeByName(nodeCredentialType); + + const dbCredentialsForType: ICredentialsResponse[] | null = this.$store.getters['credentials/getCredentialsByType'](nodeCredentialType); + + const selectedCredentials = node.credentials[nodeCredentialType]; + + if (dbCredentialsForType !== null) { + const idMatch = dbCredentialsForType.find((c) => c.id === selectedCredentials.id); + if (!idMatch) { + return { + credentials: { + [credentialType.name]: [`Credentials for "${credentialType.displayName}" are not set.`], + }, + }; + } + } + } + + /** + * For HTTP Request node, report missing credential if no selected credential + * or if no selected credentials of the chosen node credential type. + */ if ( node.type === HTTP_REQUEST_NODE_TYPE && node.typeVersion === 2 &&