Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Credentials dropdown for HTTP Request node #3222

Merged
merged 26 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2808ee9
:sparkles: Added node credentials type proxy. Changed node credential…
alexgrozav Apr 26, 2022
d074e52
:zap: Add computed property from versioning branch
ivov Apr 28, 2022
403e570
:bug: Fix cred ref lost and unsaved
ivov Apr 29, 2022
59cb1a2
:zap: Make options consistent with cred type names
ivov May 2, 2022
ca0f0df
:zap: Use prop to set component order
ivov May 2, 2022
81aeefa
:zap: Use constant and version
ivov May 2, 2022
3d5b92b
:zap: Fix rendering for generic auth creds
ivov May 2, 2022
452139f
:zap: Mark as required on first selection
ivov May 2, 2022
9b3e9a2
:zap: Mark as required on subsequent selections
ivov May 2, 2022
bd02a61
:zap: Fix marking as required after cred deletion
ivov May 2, 2022
791ed95
:zap: Refactor to clean up
ivov May 3, 2022
aedbbe5
:twisted_rightwards_arrows: Merge parent branch
ivov May 3, 2022
cacd43f
:zap: Detect position automatically
ivov May 3, 2022
75eea89
:zap: Generalize cred component positioning
ivov May 4, 2022
2eaf05e
:rewind: Revert "Generalize cred comp positioning"
ivov May 5, 2022
fec2fc1
:zap: Consolidate HTTPRN check
ivov May 5, 2022
24b8a56
:zap: Fix hue percentage to degree
ivov May 5, 2022
cb96d78
:fire: Remove unused import
ivov May 5, 2022
b8357e0
:fire: Remove unused import
ivov May 5, 2022
9151dec
:fire: Remove unused class
ivov May 5, 2022
cf54e6a
:fire: Remove unused import
ivov May 5, 2022
f7cff03
:blue_book: Create type for HTTPRN v2 auth params
ivov May 5, 2022
bc4aaa6
:pencil2: Rename check
ivov May 5, 2022
43f7e2c
:fire: Remove unused import
ivov May 5, 2022
760ef5a
:pencil2: Add i18n to `reportUnsetCredential()`
ivov May 5, 2022
0a221f3
:zap: Refactor Alex's spacing changes
ivov May 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions packages/editor-ui/src/components/NodeCredentials.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div v-if="credentialTypesNodeDescriptionDisplayed.length" :class="$style.container">
<div v-if="credentialTypesNodeDescriptionDisplayed.length" :class="['node-credentials', $style.container]">
<div v-for="credentialTypeDescription in credentialTypesNodeDescriptionDisplayed" :key="credentialTypeDescription.name">
<n8n-input-label
:label="$locale.baseText(
Expand All @@ -11,15 +11,20 @@
}
)"
:bold="false"
size="small"

:set="issues = getIssues(credentialTypeDescription.name)"
size="small"
>
<div v-if="isReadOnly">
<n8n-input disabled :value="selected && selected[credentialTypeDescription.name] && selected[credentialTypeDescription.name].name" size="small" />
<n8n-input
:value="selected && selected[credentialTypeDescription.name] && selected[credentialTypeDescription.name].name"
disabled
size="small"
/>
</div>

<div :class="issues.length ? $style.hasIssues : $style.input" v-else >
<div
v-else
:class="issues.length ? $style.hasIssues : $style.input"
>
<n8n-select :value="getSelectedId(credentialTypeDescription.name)" @change="(value) => onCredentialSelected(credentialTypeDescription.name, value)" :placeholder="$locale.baseText('nodeCredentials.selectCredential')" size="small">
<n8n-option
v-for="(item) in credentialOptions[credentialTypeDescription.name]"
Expand Down Expand Up @@ -72,6 +77,7 @@ import { showMessage } from '@/components/mixins/showMessage';
import { mapGetters } from "vuex";

import mixins from 'vue-typed-mixins';
import { HTTP_REQUEST_NODE_TYPE } from '@/constants';

export default mixins(
genericHelpers,
Expand All @@ -92,7 +98,18 @@ export default mixins(
computed: {
...mapGetters('credentials', {
credentialOptions: 'allCredentialsByType',
getCredentialTypeByName: 'getCredentialTypeByName',
}),
isProxyAuth(): boolean {
return this.node.type === HTTP_REQUEST_NODE_TYPE
&& this.node.typeVersion === 2
ivov marked this conversation as resolved.
Show resolved Hide resolved
&& this.node.parameters.authenticateWith === 'nodeCredential';
},
isGenericAuth(): boolean {
return this.node.type === HTTP_REQUEST_NODE_TYPE
&& this.node.typeVersion === 2
&& this.node.parameters.authenticateWith === 'genericAuth';
},
credentialTypesNode (): string[] {
return this.credentialTypesNodeDescription
.map((credentialTypeDescription) => credentialTypeDescription.name);
Expand All @@ -106,6 +123,18 @@ export default mixins(
credentialTypesNodeDescription (): INodeCredentialDescription[] {
const node = this.node as INodeUi;

if (this.isGenericAuth) {
const { genericAuthType } = this.node.parameters as { genericAuthType: string };

return [this.getCredentialTypeByName(genericAuthType)];
}

if (this.isProxyAuth) {
const { nodeCredentialType } = this.node.parameters as { nodeCredentialType?: string };

if (nodeCredentialType) return [this.getCredentialTypeByName(nodeCredentialType)];
}

const activeNodeType = this.$store.getters.nodeType(node.type, node.typeVersion) as INodeTypeDescription | null;
if (activeNodeType && activeNodeType.credentials) {
return activeNodeType.credentials;
Expand Down Expand Up @@ -295,7 +324,7 @@ export default mixins(

<style lang="scss" module>
.container {
margin: var(--spacing-xs) 0;
margin: 0;

> * {
margin-bottom: var(--spacing-xs);
Expand Down
21 changes: 17 additions & 4 deletions packages/editor-ui/src/components/NodeSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,23 @@
</div>
<div class="node-parameters-wrapper" v-if="node && nodeValid">
<div v-show="openPanel === 'params'">
<node-credentials :node="node" @credentialSelected="credentialSelected"></node-credentials>
<node-webhooks :node="node" :nodeType="nodeType" />
<parameter-input-list :parameters="parametersNoneSetting" :hideDelete="true" :nodeValues="nodeValues" path="parameters" @valueChanged="valueChanged" />
<node-webhooks
:node="node"
:nodeType="nodeType"
/>
<parameter-input-list
:parameters="parametersNoneSetting"
:hideDelete="true"
:nodeValues="nodeValues" path="parameters" @valueChanged="valueChanged"
>
<node-credentials
:node="node"
@credentialSelected="credentialSelected"
/>
</parameter-input-list>
<div v-if="parametersNoneSetting.length === 0" class="no-parameters">
<n8n-text>
{{ $locale.baseText('nodeSettings.thisNodeDoesNotHaveAnyParameters') }}
{{ $locale.baseText('nodeSettings.thisNodeDoesNotHaveAnyParameters') }}
</n8n-text>
</div>
</div>
Expand Down Expand Up @@ -70,6 +81,8 @@ import { nodeHelpers } from '@/components/mixins/nodeHelpers';
import mixins from 'vue-typed-mixins';
import NodeExecuteButton from './NodeExecuteButton.vue';

import { HTTP_REQUEST_NODE_TYPE } from '@/constants';
ivov marked this conversation as resolved.
Show resolved Hide resolved

export default mixins(
externalHooks,
genericHelpers,
Expand Down
23 changes: 19 additions & 4 deletions packages/editor-ui/src/components/ParameterInputList.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<template>
<div class="paramter-input-list-wrapper">
<div v-for="parameter in filteredParameters" :key="parameter.name" :class="{indent}">
<div class="parameter-input-list-wrapper">
<div v-for="(parameter, index) in filteredParameters" :key="parameter.name" :class="{indent}">
ivov marked this conversation as resolved.
Show resolved Hide resolved
<slot v-if="indexToShowSlotAt === index" />

<div
v-if="multipleValues(parameter) === true && parameter.type !== 'fixedCollection'"
class="parameter-item"
Expand Down Expand Up @@ -86,6 +88,7 @@
<script lang="ts">

import {
INode,
INodeParameters,
INodeProperties,
NodeParameterValue,
Expand All @@ -101,6 +104,7 @@ import ParameterInputFull from '@/components/ParameterInputFull.vue';
import { get, set } from 'lodash';

import mixins from 'vue-typed-mixins';
import { HTTP_REQUEST_NODE_TYPE } from '@/constants';

export default mixins(
genericHelpers,
Expand Down Expand Up @@ -129,6 +133,13 @@ export default mixins(
node (): INodeUi {
return this.$store.getters.activeNode;
},
indexToShowSlotAt (): number {
if (this.node.type === HTTP_REQUEST_NODE_TYPE && this.node.typeVersion === 2) {
return 2;
}

return 0;
},
},
methods: {
multipleValues (parameter: INodeProperties): boolean {
Expand Down Expand Up @@ -260,7 +271,11 @@ export default mixins(
</script>

<style lang="scss">
.paramter-input-list-wrapper {
.parameter-input-list-wrapper {
display: flex;
flex-direction: column;
padding-top: var(--spacing-xs);
mutdmour marked this conversation as resolved.
Show resolved Hide resolved

.delete-option {
display: none;
position: absolute;
Expand Down Expand Up @@ -293,7 +308,7 @@ export default mixins(

.parameter-item {
position: relative;
margin: var(--spacing-xs) 0;
margin: 0 0 var(--spacing-xs);

>.delete-option {
top: var(--spacing-5xs);
Expand Down
83 changes: 83 additions & 0 deletions packages/editor-ui/src/components/mixins/nodeHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
HTTP_REQUEST_NODE_TYPE,
PLACEHOLDER_FILLED_AT_EXECUTION_TIME,
} from '@/constants';

Expand Down Expand Up @@ -32,11 +33,15 @@ import { restApi } from '@/components/mixins/restApi';
import { get } from 'lodash';

import mixins from 'vue-typed-mixins';
import { mapGetters } from 'vuex';

export const nodeHelpers = mixins(
restApi,
)
.extend({
computed: {
...mapGetters('credentials', [ 'getCredentialTypeByName', 'getCredentialsByType' ]),
},
methods: {

// Returns the parameter value
Expand Down Expand Up @@ -198,6 +203,46 @@ export const nodeHelpers = mixins(
let credentialType: ICredentialType | null;
let credentialDisplayName: string;
let selectedCredentials: INodeCredentialsDetails;

const { authenticateWith, genericAuthType, nodeCredentialType } = node.parameters as {
authenticateWith: 'none' | 'genericAuth' | 'nodeCredential';
ivov marked this conversation as resolved.
Show resolved Hide resolved
genericAuthType: string;
nodeCredentialType: string;
};

if (
isHttpRequestNodeV2(node) &&
authenticateWith === 'genericAuth' &&
selectedCredsAreUnusable(node, genericAuthType)
) {
const credential = this.getCredentialTypeByName(genericAuthType);
return reportUnsetCredential(credential);
}

if (
isHttpRequestNodeV2(node) &&
authenticateWith === 'nodeCredential' &&
nodeCredentialType !== '' &&
node.credentials !== undefined
) {
const stored = this.getCredentialsByType(nodeCredentialType);

if (selectedCredsWereDeleted(node, nodeCredentialType, stored)) {
const credential = this.getCredentialTypeByName(nodeCredentialType);
return reportUnsetCredential(credential);
}
}

if (
isHttpRequestNodeV2(node) &&
authenticateWith === 'nodeCredential' &&
nodeCredentialType !== '' &&
selectedCredsAreUnusable(node, nodeCredentialType)
) {
const credential = this.getCredentialTypeByName(nodeCredentialType);
return reportUnsetCredential(credential);
}

for (const credentialTypeDescription of nodeType!.credentials!) {
// Check if credentials should be displayed else ignore
if (this.displayParameter(node.parameters, credentialTypeDescription, '', node) !== true) {
Expand Down Expand Up @@ -394,3 +439,41 @@ export const nodeHelpers = mixins(
},
},
});

function isHttpRequestNodeV2(node: INodeUi) {
return node.type === HTTP_REQUEST_NODE_TYPE && node.typeVersion === 2;
}

/**
* Whether the node has no selected credentials, or none of the node's
* selected credentials are of the specified type.
*/
function selectedCredsAreUnusable(node: INodeUi, credentialType: string) {
return node.credentials === undefined || Object.keys(node.credentials).includes(credentialType) === false;
}

/**
* Whether the node's selected credentials of the specified type
* can no longer be found in the database.
*/
function selectedCredsWereDeleted(
ivov marked this conversation as resolved.
Show resolved Hide resolved
node: INodeUi,
nodeCredentialType: string,
storedCredsByType: ICredentialsResponse[] | null,
) {
if (!node.credentials || !storedCredsByType) return false;

const selectedCredsByType = node.credentials[nodeCredentialType];

if (!selectedCredsByType) return false;

return !storedCredsByType.find((c) => c.id === selectedCredsByType.id);
}

function reportUnsetCredential(credentialType: ICredentialType) {
return {
credentials: {
[credentialType.name]: [`Credentials for "${credentialType.displayName}" are not set.`],
ivov marked this conversation as resolved.
Show resolved Hide resolved
},
};
}
8 changes: 8 additions & 0 deletions packages/editor-ui/src/components/mixins/workflowHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
START_NODE_TYPE,
WEBHOOK_NODE_TYPE,
VIEWS,
HTTP_REQUEST_NODE_TYPE,
} from '@/constants';

import {
Expand Down Expand Up @@ -326,10 +327,17 @@ export const workflowHelpers = mixins(
const nodeParameters = NodeHelpers.getNodeParameters(nodeType.properties, node.parameters, false, false, node);
nodeData.parameters = nodeParameters !== null ? nodeParameters : {};

const fullAccess = node.type === HTTP_REQUEST_NODE_TYPE && node.typeVersion === 2;

// Add the node credentials if there are some set and if they should be displayed
if (node.credentials !== undefined && nodeType.credentials !== undefined) {
const saveCredenetials: INodeCredentials = {};
for (const nodeCredentialTypeName of Object.keys(node.credentials)) {
if (fullAccess) {
saveCredenetials[nodeCredentialTypeName] = node.credentials[nodeCredentialTypeName];
continue;
}
mutdmour marked this conversation as resolved.
Show resolved Hide resolved

const credentialTypeDescription = nodeType.credentials
.find((credentialTypeDescription) => credentialTypeDescription.name === nodeCredentialTypeName);

Expand Down
Loading