2021-09-11 01:15:36 -07:00
|
|
|
<template>
|
|
|
|
<Modal
|
|
|
|
:name="modalName"
|
|
|
|
:customClass="$style.credentialModal"
|
|
|
|
:eventBus="modalBus"
|
|
|
|
:loading="loading"
|
|
|
|
:beforeClose="beforeClose"
|
2021-09-22 00:23:37 -07:00
|
|
|
width="70%"
|
|
|
|
height="80%"
|
2021-09-11 01:15:36 -07:00
|
|
|
>
|
2022-11-18 05:59:31 -08:00
|
|
|
<template #header>
|
2022-09-21 01:20:29 -07:00
|
|
|
<div :class="$style.header">
|
2021-09-11 01:15:36 -07:00
|
|
|
<div :class="$style.credInfo">
|
|
|
|
<div :class="$style.credIcon">
|
2023-01-27 00:05:43 -08:00
|
|
|
<CredentialIcon :credentialTypeName="defaultCredentialTypeName" />
|
2021-09-11 01:15:36 -07:00
|
|
|
</div>
|
|
|
|
<InlineNameEdit
|
|
|
|
:name="credentialName"
|
2022-09-21 01:20:29 -07:00
|
|
|
:subtitle="credentialType ? credentialType.displayName : ''"
|
2023-01-27 00:05:43 -08:00
|
|
|
:readonly="!credentialPermissions.updateName || !credentialType"
|
2021-09-11 01:15:36 -07:00
|
|
|
type="Credential"
|
|
|
|
@input="onNameEdit"
|
2022-11-22 01:37:26 -08:00
|
|
|
data-test-id="credential-name"
|
2021-09-11 01:15:36 -07:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div :class="$style.credActions">
|
|
|
|
<n8n-icon-button
|
2022-09-21 01:20:29 -07:00
|
|
|
v-if="currentCredential && credentialPermissions.delete"
|
2021-12-15 04:16:53 -08:00
|
|
|
:title="$locale.baseText('credentialEdit.credentialEdit.delete')"
|
2021-09-11 01:15:36 -07:00
|
|
|
icon="trash"
|
2022-07-20 08:50:39 -07:00
|
|
|
size="medium"
|
|
|
|
type="tertiary"
|
2021-09-11 01:15:36 -07:00
|
|
|
:disabled="isSaving"
|
|
|
|
:loading="isDeleting"
|
|
|
|
@click="deleteCredential"
|
2022-11-22 01:37:26 -08:00
|
|
|
data-test-id="credential-delete-button"
|
2021-09-11 01:15:36 -07:00
|
|
|
/>
|
|
|
|
<SaveButton
|
2022-09-21 01:20:29 -07:00
|
|
|
v-if="(hasUnsavedChanges || credentialId) && credentialPermissions.save"
|
2021-09-11 01:15:36 -07:00
|
|
|
:saved="!hasUnsavedChanges && !isTesting"
|
|
|
|
:isSaving="isSaving || isTesting"
|
2022-12-14 01:04:10 -08:00
|
|
|
:savingLabel="
|
|
|
|
isTesting
|
|
|
|
? $locale.baseText('credentialEdit.credentialEdit.testing')
|
|
|
|
: $locale.baseText('credentialEdit.credentialEdit.saving')
|
|
|
|
"
|
2021-09-11 01:15:36 -07:00
|
|
|
@click="saveCredential"
|
2022-11-22 01:37:26 -08:00
|
|
|
data-test-id="credential-save-button"
|
2021-09-11 01:15:36 -07:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<hr />
|
|
|
|
</template>
|
2022-11-18 05:59:31 -08:00
|
|
|
<template #content>
|
2023-01-27 00:05:43 -08:00
|
|
|
<div :class="$style.container" data-test-id="credential-edit-dialog">
|
2021-09-11 01:15:36 -07:00
|
|
|
<div :class="$style.sidebar">
|
2022-12-14 01:04:10 -08:00
|
|
|
<n8n-menu mode="tabs" :items="sidebarItems" @select="onTabSelect"></n8n-menu>
|
2021-09-11 01:15:36 -07:00
|
|
|
</div>
|
|
|
|
<div v-if="activeTab === 'connection'" :class="$style.mainContent" ref="content">
|
|
|
|
<CredentialConfig
|
|
|
|
:credentialType="credentialType"
|
|
|
|
:credentialProperties="credentialProperties"
|
|
|
|
:credentialData="credentialData"
|
2022-09-21 01:20:29 -07:00
|
|
|
:credentialId="credentialId"
|
2021-09-11 01:15:36 -07:00
|
|
|
:showValidationWarning="showValidationWarning"
|
|
|
|
:authError="authError"
|
|
|
|
:testedSuccessfully="testedSuccessfully"
|
|
|
|
:isOAuthType="isOAuthType"
|
|
|
|
:isOAuthConnected="isOAuthConnected"
|
|
|
|
:isRetesting="isRetesting"
|
|
|
|
:parentTypes="parentTypes"
|
|
|
|
:requiredPropertiesFilled="requiredPropertiesFilled"
|
2022-09-21 01:20:29 -07:00
|
|
|
:credentialPermissions="credentialPermissions"
|
2023-01-27 00:05:43 -08:00
|
|
|
:mode="mode"
|
|
|
|
:selectedCredential="selectedCredential"
|
|
|
|
:showAuthTypeSelector="requiredCredentials"
|
2021-09-11 01:15:36 -07:00
|
|
|
@change="onDataChange"
|
|
|
|
@oauth="oAuthCredentialAuthorize"
|
|
|
|
@retest="retestCredential"
|
|
|
|
@scrollToTop="scrollToTop"
|
2023-01-27 00:05:43 -08:00
|
|
|
@authTypeChanged="onAuthTypeChanged"
|
2021-09-11 01:15:36 -07:00
|
|
|
/>
|
|
|
|
</div>
|
2022-12-21 07:42:07 -08:00
|
|
|
<div v-else-if="activeTab === 'sharing' && credentialType" :class="$style.mainContent">
|
2022-09-21 01:20:29 -07:00
|
|
|
<CredentialSharing
|
|
|
|
:credential="currentCredential"
|
|
|
|
:credentialData="credentialData"
|
|
|
|
:credentialId="credentialId"
|
|
|
|
:credentialPermissions="credentialPermissions"
|
2022-12-12 01:53:02 -08:00
|
|
|
:modalBus="modalBus"
|
2022-09-21 01:20:29 -07:00
|
|
|
@change="onChangeSharedWith"
|
|
|
|
/>
|
2022-12-21 07:42:07 -08:00
|
|
|
</div>
|
2022-09-21 01:20:29 -07:00
|
|
|
<div v-else-if="activeTab === 'details' && credentialType" :class="$style.mainContent">
|
2021-09-11 01:15:36 -07:00
|
|
|
<CredentialInfo
|
|
|
|
:nodeAccess="nodeAccess"
|
|
|
|
:nodesWithAccess="nodesWithAccess"
|
|
|
|
:currentCredential="currentCredential"
|
2022-09-21 01:20:29 -07:00
|
|
|
:credentialPermissions="credentialPermissions"
|
2021-09-11 01:15:36 -07:00
|
|
|
@accessChange="onNodeAccessChange"
|
|
|
|
/>
|
|
|
|
</div>
|
2022-09-21 01:20:29 -07:00
|
|
|
<div v-else-if="activeTab.startsWith('coming-soon')" :class="$style.mainContent">
|
2022-07-27 07:28:13 -07:00
|
|
|
<FeatureComingSoon :featureId="activeTab.split('/')[1]"></FeatureComingSoon>
|
|
|
|
</div>
|
2021-09-11 01:15:36 -07:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</Modal>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
|
|
|
|
2023-04-25 02:47:03 -07:00
|
|
|
import type { ICredentialsResponse, IUser } from '@/Interface';
|
2021-09-11 01:15:36 -07:00
|
|
|
|
2023-04-24 03:18:24 -07:00
|
|
|
import type {
|
2021-09-11 01:15:36 -07:00
|
|
|
CredentialInformation,
|
|
|
|
ICredentialDataDecryptedObject,
|
|
|
|
ICredentialNodeAccess,
|
|
|
|
ICredentialsDecrypted,
|
|
|
|
ICredentialType,
|
2022-07-27 07:28:13 -07:00
|
|
|
INode,
|
2023-01-27 00:05:43 -08:00
|
|
|
INodeCredentialDescription,
|
2021-09-11 01:15:36 -07:00
|
|
|
INodeParameters,
|
|
|
|
INodeProperties,
|
|
|
|
INodeTypeDescription,
|
2022-07-09 23:53:04 -07:00
|
|
|
ITelemetryTrackProperties,
|
2021-09-11 01:15:36 -07:00
|
|
|
} from 'n8n-workflow';
|
2023-04-24 03:18:24 -07:00
|
|
|
import { NodeHelpers } from 'n8n-workflow';
|
2021-09-11 01:15:36 -07:00
|
|
|
import CredentialIcon from '../CredentialIcon.vue';
|
|
|
|
|
|
|
|
import mixins from 'vue-typed-mixins';
|
2022-11-23 04:41:53 -08:00
|
|
|
import { nodeHelpers } from '@/mixins/nodeHelpers';
|
|
|
|
import { showMessage } from '@/mixins/showMessage';
|
2021-09-11 01:15:36 -07:00
|
|
|
|
|
|
|
import CredentialConfig from './CredentialConfig.vue';
|
|
|
|
import CredentialInfo from './CredentialInfo.vue';
|
2022-12-14 01:04:10 -08:00
|
|
|
import CredentialSharing from './CredentialSharing.ee.vue';
|
2021-09-11 01:15:36 -07:00
|
|
|
import SaveButton from '../SaveButton.vue';
|
|
|
|
import Modal from '../Modal.vue';
|
|
|
|
import InlineNameEdit from '../InlineNameEdit.vue';
|
2023-01-27 00:05:43 -08:00
|
|
|
import { CREDENTIAL_EDIT_MODAL_KEY, EnterpriseEditionFeature } from '@/constants';
|
2023-04-24 03:18:24 -07:00
|
|
|
import type { IDataObject } from 'n8n-workflow';
|
2022-07-27 07:28:13 -07:00
|
|
|
import FeatureComingSoon from '../FeatureComingSoon.vue';
|
2023-04-24 03:18:24 -07:00
|
|
|
import type { IPermissions } from '@/permissions';
|
|
|
|
import { getCredentialPermissions } from '@/permissions';
|
|
|
|
import type { IMenuItem } from 'n8n-design-system';
|
|
|
|
import { createEventBus } from 'n8n-design-system';
|
2022-11-04 06:04:31 -07:00
|
|
|
import { mapStores } from 'pinia';
|
|
|
|
import { useUIStore } from '@/stores/ui';
|
|
|
|
import { useSettingsStore } from '@/stores/settings';
|
|
|
|
import { useUsersStore } from '@/stores/users';
|
|
|
|
import { useWorkflowsStore } from '@/stores/workflows';
|
|
|
|
import { useNDVStore } from '@/stores/ndv';
|
2022-11-09 01:01:50 -08:00
|
|
|
import { useCredentialsStore } from '@/stores/credentials';
|
2023-01-27 00:05:43 -08:00
|
|
|
import {
|
|
|
|
isValidCredentialResponse,
|
|
|
|
getNodeAuthOptions,
|
|
|
|
getNodeCredentialForSelectedAuthType,
|
|
|
|
updateNodeAuthType,
|
|
|
|
isCredentialModalState,
|
|
|
|
} from '@/utils';
|
2021-09-11 01:15:36 -07:00
|
|
|
|
|
|
|
interface NodeAccessMap {
|
|
|
|
[nodeType: string]: ICredentialNodeAccess | null;
|
|
|
|
}
|
|
|
|
|
2021-12-07 07:14:40 -08:00
|
|
|
export default mixins(showMessage, nodeHelpers).extend({
|
2022-09-21 01:20:29 -07:00
|
|
|
name: 'CredentialEdit',
|
2021-09-11 01:15:36 -07:00
|
|
|
components: {
|
2022-09-21 01:20:29 -07:00
|
|
|
CredentialSharing,
|
2021-09-11 01:15:36 -07:00
|
|
|
CredentialConfig,
|
|
|
|
CredentialIcon,
|
|
|
|
CredentialInfo,
|
|
|
|
InlineNameEdit,
|
|
|
|
Modal,
|
|
|
|
SaveButton,
|
2022-07-27 07:28:13 -07:00
|
|
|
FeatureComingSoon,
|
2021-09-11 01:15:36 -07:00
|
|
|
},
|
|
|
|
props: {
|
|
|
|
modalName: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
activeId: {
|
2023-01-27 00:05:43 -08:00
|
|
|
type: [String, Number],
|
|
|
|
required: false,
|
2021-09-11 01:15:36 -07:00
|
|
|
},
|
|
|
|
mode: {
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
activeTab: 'connection',
|
|
|
|
authError: '',
|
2022-11-09 01:01:50 -08:00
|
|
|
credentialId: '',
|
2021-09-11 01:15:36 -07:00
|
|
|
credentialName: '',
|
|
|
|
credentialData: {} as ICredentialDataDecryptedObject,
|
2023-04-06 06:32:45 -07:00
|
|
|
modalBus: createEventBus(),
|
2021-09-11 01:15:36 -07:00
|
|
|
nodeAccess: {} as NodeAccessMap,
|
|
|
|
isDeleting: false,
|
|
|
|
isSaving: false,
|
|
|
|
isTesting: false,
|
|
|
|
hasUnsavedChanges: false,
|
|
|
|
loading: true,
|
|
|
|
showValidationWarning: false,
|
|
|
|
testedSuccessfully: false,
|
|
|
|
isRetesting: false,
|
2022-09-21 01:20:29 -07:00
|
|
|
EnterpriseEditionFeature,
|
2023-01-27 00:05:43 -08:00
|
|
|
selectedCredential: '',
|
|
|
|
requiredCredentials: false, // Are credentials required or optional for the node
|
|
|
|
hasUserSpecifiedName: false,
|
2021-09-11 01:15:36 -07:00
|
|
|
};
|
|
|
|
},
|
|
|
|
async mounted() {
|
2023-01-27 00:05:43 -08:00
|
|
|
this.requiredCredentials =
|
|
|
|
isCredentialModalState(this.uiStore.modals[CREDENTIAL_EDIT_MODAL_KEY]) &&
|
|
|
|
this.uiStore.modals[CREDENTIAL_EDIT_MODAL_KEY].showAuthSelector === true;
|
2021-09-11 01:15:36 -07:00
|
|
|
|
2023-01-27 00:05:43 -08:00
|
|
|
this.setupNodeAccess();
|
2021-09-11 01:15:36 -07:00
|
|
|
|
2022-11-09 01:01:50 -08:00
|
|
|
if (this.mode === 'new' && this.credentialTypeName) {
|
2022-12-14 01:04:10 -08:00
|
|
|
this.credentialName = await this.credentialsStore.getNewCredentialName({
|
2023-01-27 00:05:43 -08:00
|
|
|
credentialTypeName: this.defaultCredentialTypeName,
|
2022-12-14 01:04:10 -08:00
|
|
|
});
|
2022-09-21 01:20:29 -07:00
|
|
|
|
2022-11-09 01:01:50 -08:00
|
|
|
if (this.currentUser) {
|
|
|
|
Vue.set(this.credentialData, 'ownedBy', {
|
|
|
|
id: this.currentUser.id,
|
|
|
|
firstName: this.currentUser.firstName,
|
|
|
|
lastName: this.currentUser.lastName,
|
|
|
|
email: this.currentUser.email,
|
|
|
|
});
|
|
|
|
}
|
2021-09-11 01:15:36 -07:00
|
|
|
} else {
|
|
|
|
await this.loadCurrentCredential();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.credentialType) {
|
|
|
|
for (const property of this.credentialType.properties) {
|
2022-11-22 01:08:35 -08:00
|
|
|
if (
|
|
|
|
!this.credentialData.hasOwnProperty(property.name) &&
|
|
|
|
!this.credentialType.__overwrittenProperties?.includes(property.name)
|
|
|
|
) {
|
2022-01-20 23:52:39 -08:00
|
|
|
Vue.set(this.credentialData, property.name, property.default as CredentialInformation);
|
2021-09-11 01:15:36 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-05 11:28:37 -07:00
|
|
|
this.$externalHooks().run('credentialsEdit.credentialModalOpened', {
|
|
|
|
credentialType: this.credentialTypeName,
|
|
|
|
isEditingCredential: this.mode === 'edit',
|
2022-11-04 06:04:31 -07:00
|
|
|
activeNode: this.ndvStore.activeNode,
|
2021-10-05 11:28:37 -07:00
|
|
|
});
|
|
|
|
|
2021-10-09 11:42:30 -07:00
|
|
|
setTimeout(() => {
|
|
|
|
if (this.credentialId) {
|
2023-04-28 03:02:28 -07:00
|
|
|
if (!this.requiredPropertiesFilled && this.credentialPermissions.isOwner === true) {
|
|
|
|
// sharees can't see properties, so this check would always fail for them
|
|
|
|
// if the credential contains required fields.
|
2021-10-09 11:42:30 -07:00
|
|
|
this.showValidationWarning = true;
|
2022-12-14 01:04:10 -08:00
|
|
|
} else {
|
2021-10-09 11:42:30 -07:00
|
|
|
this.retestCredential();
|
|
|
|
}
|
2021-09-11 01:15:36 -07:00
|
|
|
}
|
2021-10-09 11:42:30 -07:00
|
|
|
}, 0);
|
2021-09-11 01:15:36 -07:00
|
|
|
|
|
|
|
this.loading = false;
|
|
|
|
},
|
|
|
|
computed: {
|
2022-11-04 06:04:31 -07:00
|
|
|
...mapStores(
|
2022-12-14 01:04:10 -08:00
|
|
|
useCredentialsStore,
|
|
|
|
useNDVStore,
|
|
|
|
useSettingsStore,
|
|
|
|
useUIStore,
|
|
|
|
useUsersStore,
|
|
|
|
useWorkflowsStore,
|
|
|
|
),
|
2023-01-27 00:05:43 -08:00
|
|
|
activeNodeType(): INodeTypeDescription | null {
|
|
|
|
const activeNode = this.ndvStore.activeNode;
|
|
|
|
|
|
|
|
if (activeNode) {
|
|
|
|
return this.nodeTypesStore.getNodeType(activeNode.type, activeNode.typeVersion);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
selectedCredentialType(): INodeCredentialDescription | null {
|
|
|
|
if (this.mode !== 'new') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is already selected type, use it
|
|
|
|
if (this.selectedCredential !== '') {
|
|
|
|
return this.credentialsStore.getCredentialTypeByName(this.selectedCredential);
|
|
|
|
} else if (this.requiredCredentials) {
|
|
|
|
// Otherwise, use credential type that corresponds to the first auth option in the node definition
|
|
|
|
const nodeAuthOptions = getNodeAuthOptions(this.activeNodeType);
|
|
|
|
// But only if there is zero or one auth options available
|
|
|
|
if (nodeAuthOptions.length > 0 && this.activeNodeType?.credentials) {
|
|
|
|
return getNodeCredentialForSelectedAuthType(
|
|
|
|
this.activeNodeType,
|
|
|
|
nodeAuthOptions[0].value,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return this.activeNodeType?.credentials ? this.activeNodeType.credentials[0] : null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
2022-11-09 01:01:50 -08:00
|
|
|
currentUser(): IUser | null {
|
|
|
|
return this.usersStore.currentUser;
|
2022-11-04 06:04:31 -07:00
|
|
|
},
|
2021-09-11 01:15:36 -07:00
|
|
|
currentCredential(): ICredentialsResponse | null {
|
|
|
|
if (!this.credentialId) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-11-09 01:01:50 -08:00
|
|
|
return this.credentialsStore.getCredentialById(this.credentialId);
|
2021-09-11 01:15:36 -07:00
|
|
|
},
|
|
|
|
credentialTypeName(): string | null {
|
|
|
|
if (this.mode === 'edit') {
|
|
|
|
if (this.currentCredential) {
|
|
|
|
return this.currentCredential.type;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2023-01-27 00:05:43 -08:00
|
|
|
if (this.selectedCredentialType) {
|
|
|
|
return this.selectedCredentialType.name;
|
|
|
|
}
|
2022-09-21 01:20:29 -07:00
|
|
|
return `${this.activeId}`;
|
2021-09-11 01:15:36 -07:00
|
|
|
},
|
|
|
|
credentialType(): ICredentialType | null {
|
|
|
|
if (!this.credentialTypeName) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-11-09 01:01:50 -08:00
|
|
|
const type = this.credentialsStore.getCredentialTypeByName(this.credentialTypeName);
|
2021-09-11 01:15:36 -07:00
|
|
|
|
2022-09-21 01:20:29 -07:00
|
|
|
if (!type) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-09-11 01:15:36 -07:00
|
|
|
return {
|
|
|
|
...type,
|
|
|
|
properties: this.getCredentialProperties(this.credentialTypeName),
|
|
|
|
};
|
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
isCredentialTestable(): boolean {
|
2023-04-28 03:02:28 -07:00
|
|
|
// Sharees can always test since they can't see the data.
|
|
|
|
if (this.credentialPermissions.isOwner === false) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-09-11 01:15:36 -07:00
|
|
|
if (this.isOAuthType || !this.requiredPropertiesFilled) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-09-21 01:20:29 -07:00
|
|
|
const { ownedBy, sharedWith, ...credentialData } = this.credentialData;
|
2022-12-14 01:04:10 -08:00
|
|
|
const hasExpressions = Object.values(credentialData).reduce(
|
|
|
|
(accu: boolean, value: CredentialInformation) =>
|
|
|
|
accu || (typeof value === 'string' && value.startsWith('=')),
|
|
|
|
false,
|
|
|
|
);
|
2021-09-11 01:15:36 -07:00
|
|
|
if (hasExpressions) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
const nodesThatCanTest = this.nodesWithAccess.filter((node) => {
|
2021-09-11 01:15:36 -07:00
|
|
|
if (node.credentials) {
|
|
|
|
// Returns a list of nodes that can test this credentials
|
2022-12-14 01:04:10 -08:00
|
|
|
const eligibleTesters = node.credentials.filter((credential) => {
|
2021-09-11 01:15:36 -07:00
|
|
|
return credential.name === this.credentialTypeName && credential.testedBy;
|
|
|
|
});
|
|
|
|
// If we have any node that can test, return true.
|
|
|
|
return !!eligibleTesters.length;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2022-02-05 13:55:43 -08:00
|
|
|
return !!nodesThatCanTest.length || (!!this.credentialType && !!this.credentialType.test);
|
2021-09-11 01:15:36 -07:00
|
|
|
},
|
|
|
|
nodesWithAccess(): INodeTypeDescription[] {
|
|
|
|
if (this.credentialTypeName) {
|
2022-11-09 01:01:50 -08:00
|
|
|
return this.credentialsStore.getNodesWithAccess(this.credentialTypeName);
|
2021-09-11 01:15:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
parentTypes(): string[] {
|
|
|
|
if (this.credentialTypeName) {
|
|
|
|
return this.getParentTypes(this.credentialTypeName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
isOAuthType(): boolean {
|
2022-12-14 01:04:10 -08:00
|
|
|
return (
|
|
|
|
!!this.credentialTypeName &&
|
|
|
|
(((this.credentialTypeName === 'oAuth2Api' || this.parentTypes.includes('oAuth2Api')) &&
|
|
|
|
this.credentialData.grantType === 'authorizationCode') ||
|
2022-06-13 22:27:19 -07:00
|
|
|
this.credentialTypeName === 'oAuth1Api' ||
|
2022-12-14 01:04:10 -08:00
|
|
|
this.parentTypes.includes('oAuth1Api'))
|
2021-09-11 01:15:36 -07:00
|
|
|
);
|
|
|
|
},
|
|
|
|
isOAuthConnected(): boolean {
|
|
|
|
return this.isOAuthType && !!this.credentialData.oauthTokenData;
|
|
|
|
},
|
|
|
|
credentialProperties(): INodeProperties[] {
|
|
|
|
if (!this.credentialType) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
return this.credentialType.properties.filter((propertyData: INodeProperties) => {
|
|
|
|
if (!this.displayCredentialParameter(propertyData)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
!this.credentialType!.__overwrittenProperties ||
|
|
|
|
!this.credentialType!.__overwrittenProperties.includes(propertyData.name)
|
|
|
|
);
|
|
|
|
});
|
2021-09-11 01:15:36 -07:00
|
|
|
},
|
|
|
|
requiredPropertiesFilled(): boolean {
|
|
|
|
for (const property of this.credentialProperties) {
|
|
|
|
if (property.required !== true) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-10-09 11:42:30 -07:00
|
|
|
if (property.type === 'string' && !this.credentialData[property.name]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (property.type === 'number' && typeof this.credentialData[property.name] !== 'number') {
|
2021-09-11 01:15:36 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
2022-09-21 01:20:29 -07:00
|
|
|
credentialPermissions(): IPermissions {
|
|
|
|
if (this.loading) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
return getCredentialPermissions(
|
|
|
|
this.currentUser,
|
|
|
|
(this.credentialId ? this.currentCredential : this.credentialData) as ICredentialsResponse,
|
|
|
|
);
|
2022-09-21 01:20:29 -07:00
|
|
|
},
|
2022-10-10 09:17:39 -07:00
|
|
|
sidebarItems(): IMenuItem[] {
|
2022-12-21 07:42:07 -08:00
|
|
|
return [
|
2022-12-14 01:04:10 -08:00
|
|
|
{
|
|
|
|
id: 'connection',
|
|
|
|
label: this.$locale.baseText('credentialEdit.credentialEdit.connection'),
|
|
|
|
position: 'top',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'sharing',
|
|
|
|
label: this.$locale.baseText('credentialEdit.credentialEdit.sharing'),
|
|
|
|
position: 'top',
|
2022-12-21 07:42:07 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'details',
|
|
|
|
label: this.$locale.baseText('credentialEdit.credentialEdit.details'),
|
|
|
|
position: 'top',
|
2022-12-14 01:04:10 -08:00
|
|
|
},
|
|
|
|
];
|
2022-10-10 09:17:39 -07:00
|
|
|
},
|
|
|
|
isSharingAvailable(): boolean {
|
2022-11-04 06:04:31 -07:00
|
|
|
return this.settingsStore.isEnterpriseFeatureEnabled(EnterpriseEditionFeature.Sharing);
|
2022-10-10 09:17:39 -07:00
|
|
|
},
|
2023-01-27 00:05:43 -08:00
|
|
|
defaultCredentialTypeName(): string {
|
|
|
|
let credentialTypeName = this.credentialTypeName;
|
|
|
|
if (!credentialTypeName || credentialTypeName === 'null') {
|
|
|
|
if (this.activeNodeType && this.activeNodeType.credentials) {
|
|
|
|
credentialTypeName = this.activeNodeType.credentials[0].name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return credentialTypeName || '';
|
|
|
|
},
|
2021-09-11 01:15:36 -07:00
|
|
|
},
|
|
|
|
methods: {
|
2022-01-21 09:00:00 -08:00
|
|
|
async beforeClose() {
|
2021-09-11 01:15:36 -07:00
|
|
|
let keepEditing = false;
|
|
|
|
|
|
|
|
if (this.hasUnsavedChanges) {
|
|
|
|
const displayName = this.credentialType ? this.credentialType.displayName : '';
|
|
|
|
keepEditing = await this.confirmMessage(
|
2022-12-14 01:04:10 -08:00
|
|
|
this.$locale.baseText(
|
|
|
|
'credentialEdit.credentialEdit.confirmMessage.beforeClose1.message',
|
|
|
|
{ interpolate: { credentialDisplayName: displayName } },
|
|
|
|
),
|
|
|
|
this.$locale.baseText(
|
|
|
|
'credentialEdit.credentialEdit.confirmMessage.beforeClose1.headline',
|
|
|
|
),
|
2021-09-11 01:15:36 -07:00
|
|
|
null,
|
2022-12-14 01:04:10 -08:00
|
|
|
this.$locale.baseText(
|
|
|
|
'credentialEdit.credentialEdit.confirmMessage.beforeClose1.cancelButtonText',
|
|
|
|
),
|
|
|
|
this.$locale.baseText(
|
|
|
|
'credentialEdit.credentialEdit.confirmMessage.beforeClose1.confirmButtonText',
|
|
|
|
),
|
2021-09-11 01:15:36 -07:00
|
|
|
);
|
2022-09-21 01:20:29 -07:00
|
|
|
} else if (this.credentialPermissions.isOwner && this.isOAuthType && !this.isOAuthConnected) {
|
2021-09-11 01:15:36 -07:00
|
|
|
keepEditing = await this.confirmMessage(
|
2022-12-14 01:04:10 -08:00
|
|
|
this.$locale.baseText(
|
|
|
|
'credentialEdit.credentialEdit.confirmMessage.beforeClose2.message',
|
|
|
|
),
|
|
|
|
this.$locale.baseText(
|
|
|
|
'credentialEdit.credentialEdit.confirmMessage.beforeClose2.headline',
|
|
|
|
),
|
2021-09-11 01:15:36 -07:00
|
|
|
null,
|
2022-12-14 01:04:10 -08:00
|
|
|
this.$locale.baseText(
|
|
|
|
'credentialEdit.credentialEdit.confirmMessage.beforeClose2.cancelButtonText',
|
|
|
|
),
|
|
|
|
this.$locale.baseText(
|
|
|
|
'credentialEdit.credentialEdit.confirmMessage.beforeClose2.confirmButtonText',
|
|
|
|
),
|
2021-09-11 01:15:36 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!keepEditing) {
|
2022-01-21 09:00:00 -08:00
|
|
|
return true;
|
2022-12-14 01:04:10 -08:00
|
|
|
} else if (!this.requiredPropertiesFilled) {
|
2021-09-11 01:15:36 -07:00
|
|
|
this.showValidationWarning = true;
|
|
|
|
this.scrollToTop();
|
2022-12-14 01:04:10 -08:00
|
|
|
} else if (this.isOAuthType) {
|
2021-09-11 01:15:36 -07:00
|
|
|
this.scrollToBottom();
|
|
|
|
}
|
2022-01-21 09:00:00 -08:00
|
|
|
|
|
|
|
return false;
|
2021-09-11 01:15:36 -07:00
|
|
|
},
|
|
|
|
displayCredentialParameter(parameter: INodeProperties): boolean {
|
|
|
|
if (parameter.type === 'hidden') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parameter.displayOptions === undefined) {
|
|
|
|
// If it is not defined no need to do a proper check
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
return this.displayParameter(this.credentialData as INodeParameters, parameter, '', null);
|
2021-09-11 01:15:36 -07:00
|
|
|
},
|
|
|
|
getCredentialProperties(name: string): INodeProperties[] {
|
2022-11-09 01:01:50 -08:00
|
|
|
const credentialTypeData = this.credentialsStore.getCredentialTypeByName(name);
|
2021-09-11 01:15:36 -07:00
|
|
|
|
2022-09-21 01:20:29 -07:00
|
|
|
if (!credentialTypeData) {
|
|
|
|
return [];
|
2021-09-11 01:15:36 -07:00
|
|
|
}
|
|
|
|
|
2022-09-21 01:20:29 -07:00
|
|
|
if (credentialTypeData.extends === undefined) {
|
|
|
|
return credentialTypeData.properties;
|
2021-09-11 01:15:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const combineProperties = [] as INodeProperties[];
|
2022-09-21 01:20:29 -07:00
|
|
|
for (const credentialsTypeName of credentialTypeData.extends) {
|
2022-12-14 01:04:10 -08:00
|
|
|
const mergeCredentialProperties = this.getCredentialProperties(credentialsTypeName);
|
|
|
|
NodeHelpers.mergeNodeProperties(combineProperties, mergeCredentialProperties);
|
2021-09-11 01:15:36 -07:00
|
|
|
}
|
|
|
|
|
2022-11-22 01:08:35 -08:00
|
|
|
// The properties defined on the parent credentials take precedence
|
2022-12-14 01:04:10 -08:00
|
|
|
NodeHelpers.mergeNodeProperties(combineProperties, credentialTypeData.properties);
|
2021-09-11 01:15:36 -07:00
|
|
|
|
|
|
|
return combineProperties;
|
|
|
|
},
|
|
|
|
|
|
|
|
async loadCurrentCredential() {
|
|
|
|
this.credentialId = this.activeId;
|
|
|
|
|
|
|
|
try {
|
2022-12-14 01:04:10 -08:00
|
|
|
const currentCredentials = await this.credentialsStore.getCredentialData({
|
|
|
|
id: this.credentialId,
|
|
|
|
});
|
2022-09-21 01:20:29 -07:00
|
|
|
|
2021-09-11 01:15:36 -07:00
|
|
|
if (!currentCredentials) {
|
|
|
|
throw new Error(
|
2022-12-14 01:04:10 -08:00
|
|
|
this.$locale.baseText('credentialEdit.credentialEdit.couldNotFindCredentialWithId') +
|
|
|
|
':' +
|
|
|
|
this.credentialId,
|
2021-09-11 01:15:36 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.credentialData = currentCredentials.data || {};
|
2022-09-21 01:20:29 -07:00
|
|
|
if (currentCredentials.sharedWith) {
|
|
|
|
Vue.set(this.credentialData, 'sharedWith', currentCredentials.sharedWith);
|
|
|
|
}
|
|
|
|
if (currentCredentials.ownedBy) {
|
|
|
|
Vue.set(this.credentialData, 'ownedBy', currentCredentials.ownedBy);
|
|
|
|
}
|
|
|
|
|
2021-09-11 01:15:36 -07:00
|
|
|
this.credentialName = currentCredentials.name;
|
2022-12-14 01:04:10 -08:00
|
|
|
currentCredentials.nodesAccess.forEach((access: { nodeType: string }) => {
|
|
|
|
// keep node access structure to keep dates when updating
|
|
|
|
this.nodeAccess[access.nodeType] = access;
|
|
|
|
});
|
2021-11-10 10:41:40 -08:00
|
|
|
} catch (error) {
|
2021-09-11 01:15:36 -07:00
|
|
|
this.$showError(
|
2021-11-10 10:41:40 -08:00
|
|
|
error,
|
2021-12-15 04:16:53 -08:00
|
|
|
this.$locale.baseText('credentialEdit.credentialEdit.showError.loadCredential.title'),
|
2021-09-11 01:15:36 -07:00
|
|
|
);
|
|
|
|
this.closeDialog();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onTabSelect(tab: string) {
|
|
|
|
this.activeTab = tab;
|
2022-07-27 07:28:13 -07:00
|
|
|
const tabName: string = tab.replaceAll('coming-soon/', '');
|
|
|
|
const credType: string = this.credentialType ? this.credentialType.name : '';
|
2022-11-04 06:04:31 -07:00
|
|
|
const activeNode: INode | null = this.ndvStore.activeNode;
|
2022-07-27 07:28:13 -07:00
|
|
|
|
|
|
|
this.$telemetry.track('User viewed credential tab', {
|
|
|
|
credential_type: credType,
|
|
|
|
node_type: activeNode ? activeNode.type : null,
|
|
|
|
tab: tabName,
|
2022-11-04 06:04:31 -07:00
|
|
|
workflow_id: this.workflowsStore.workflowId,
|
2022-09-21 01:20:29 -07:00
|
|
|
credential_id: this.credentialId,
|
|
|
|
sharing_enabled: EnterpriseEditionFeature.Sharing,
|
2022-07-27 07:28:13 -07:00
|
|
|
});
|
2021-09-11 01:15:36 -07:00
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
onNodeAccessChange({ name, value }: { name: string; value: boolean }) {
|
2021-09-11 01:15:36 -07:00
|
|
|
this.hasUnsavedChanges = true;
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
this.nodeAccess = {
|
|
|
|
...this.nodeAccess,
|
|
|
|
[name]: {
|
|
|
|
nodeType: name,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
this.nodeAccess = {
|
|
|
|
...this.nodeAccess,
|
|
|
|
[name]: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
2022-09-21 01:20:29 -07:00
|
|
|
onChangeSharedWith(sharees: IDataObject[]) {
|
|
|
|
Vue.set(this.credentialData, 'sharedWith', sharees);
|
|
|
|
this.hasUnsavedChanges = true;
|
|
|
|
},
|
2022-12-15 05:06:00 -08:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2022-12-14 01:04:10 -08:00
|
|
|
onDataChange({ name, value }: { name: string; value: any }) {
|
2021-09-11 01:15:36 -07:00
|
|
|
this.hasUnsavedChanges = true;
|
|
|
|
|
|
|
|
const { oauthTokenData, ...credData } = this.credentialData;
|
|
|
|
|
|
|
|
this.credentialData = {
|
|
|
|
...credData,
|
|
|
|
[name]: value,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
closeDialog() {
|
2023-04-06 06:32:45 -07:00
|
|
|
this.modalBus.emit('close');
|
2021-09-11 01:15:36 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
getParentTypes(name: string): string[] {
|
2022-11-09 01:01:50 -08:00
|
|
|
const credentialType = this.credentialsStore.getCredentialTypeByName(name);
|
2021-09-11 01:15:36 -07:00
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
if (credentialType === undefined || credentialType.extends === undefined) {
|
2021-09-11 01:15:36 -07:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
const types: string[] = [];
|
|
|
|
for (const typeName of credentialType.extends) {
|
|
|
|
types.push(typeName);
|
2022-09-23 07:14:28 -07:00
|
|
|
types.push.apply(types, this.getParentTypes(typeName)); // eslint-disable-line prefer-spread
|
2021-09-11 01:15:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return types;
|
|
|
|
},
|
|
|
|
|
|
|
|
onNameEdit(text: string) {
|
|
|
|
this.hasUnsavedChanges = true;
|
2023-01-27 00:05:43 -08:00
|
|
|
this.hasUserSpecifiedName = true;
|
2021-09-11 01:15:36 -07:00
|
|
|
this.credentialName = text;
|
|
|
|
},
|
|
|
|
|
|
|
|
scrollToTop() {
|
|
|
|
setTimeout(() => {
|
2023-04-21 06:59:04 -07:00
|
|
|
const contentRef = this.$refs.content as Element | undefined;
|
|
|
|
if (contentRef) {
|
|
|
|
contentRef.scrollTop = 0;
|
2021-09-11 01:15:36 -07:00
|
|
|
}
|
|
|
|
}, 0);
|
|
|
|
},
|
|
|
|
|
|
|
|
scrollToBottom() {
|
|
|
|
setTimeout(() => {
|
2023-04-21 06:59:04 -07:00
|
|
|
const contentRef = this.$refs.content as Element | undefined;
|
|
|
|
if (contentRef) {
|
|
|
|
contentRef.scrollTop = contentRef.scrollHeight;
|
2021-09-11 01:15:36 -07:00
|
|
|
}
|
|
|
|
}, 0);
|
|
|
|
},
|
|
|
|
|
|
|
|
async retestCredential() {
|
|
|
|
if (!this.isCredentialTestable) {
|
|
|
|
this.authError = '';
|
|
|
|
this.testedSuccessfully = false;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nodesAccess = Object.values(this.nodeAccess).filter(
|
|
|
|
(access) => !!access,
|
|
|
|
) as ICredentialNodeAccess[];
|
|
|
|
|
2022-09-21 01:20:29 -07:00
|
|
|
const { ownedBy, sharedWith, ...credentialData } = this.credentialData;
|
2021-09-11 01:15:36 -07:00
|
|
|
const details: ICredentialsDecrypted = {
|
2021-10-13 15:21:00 -07:00
|
|
|
id: this.credentialId,
|
2021-09-11 01:15:36 -07:00
|
|
|
name: this.credentialName,
|
|
|
|
type: this.credentialTypeName!,
|
2022-09-21 01:20:29 -07:00
|
|
|
data: credentialData,
|
2021-09-11 01:15:36 -07:00
|
|
|
nodesAccess,
|
|
|
|
};
|
|
|
|
|
|
|
|
this.isRetesting = true;
|
|
|
|
await this.testCredential(details);
|
|
|
|
this.isRetesting = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
async testCredential(credentialDetails: ICredentialsDecrypted) {
|
2022-11-09 01:01:50 -08:00
|
|
|
const result = await this.credentialsStore.testCredential(credentialDetails);
|
2021-09-11 01:15:36 -07:00
|
|
|
if (result.status === 'Error') {
|
|
|
|
this.authError = result.message;
|
|
|
|
this.testedSuccessfully = false;
|
2022-12-14 01:04:10 -08:00
|
|
|
} else {
|
2021-09-11 01:15:36 -07:00
|
|
|
this.authError = '';
|
|
|
|
this.testedSuccessfully = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.scrollToTop();
|
|
|
|
},
|
|
|
|
|
|
|
|
async saveCredential(): Promise<ICredentialsResponse | null> {
|
|
|
|
if (!this.requiredPropertiesFilled) {
|
|
|
|
this.showValidationWarning = true;
|
|
|
|
this.scrollToTop();
|
2022-12-14 01:04:10 -08:00
|
|
|
} else {
|
2021-09-11 01:15:36 -07:00
|
|
|
this.showValidationWarning = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.isSaving = true;
|
|
|
|
const nodesAccess = Object.values(this.nodeAccess).filter(
|
|
|
|
(access) => !!access,
|
|
|
|
) as ICredentialNodeAccess[];
|
|
|
|
|
|
|
|
// Save only the none default data
|
|
|
|
const data = NodeHelpers.getNodeParameters(
|
|
|
|
this.credentialType!.properties,
|
|
|
|
this.credentialData as INodeParameters,
|
|
|
|
false,
|
|
|
|
false,
|
2022-04-28 10:04:09 -07:00
|
|
|
null,
|
2021-09-11 01:15:36 -07:00
|
|
|
);
|
|
|
|
|
2022-09-21 01:20:29 -07:00
|
|
|
let sharedWith: IUser[] | undefined;
|
|
|
|
let ownedBy: IUser | undefined;
|
2022-11-04 06:04:31 -07:00
|
|
|
if (this.settingsStore.isEnterpriseFeatureEnabled(EnterpriseEditionFeature.Sharing)) {
|
2022-09-21 01:20:29 -07:00
|
|
|
sharedWith = this.credentialData.sharedWith as unknown as IUser[];
|
|
|
|
ownedBy = this.credentialData.ownedBy as unknown as IUser;
|
|
|
|
}
|
|
|
|
|
2021-09-11 01:15:36 -07:00
|
|
|
const credentialDetails: ICredentialsDecrypted = {
|
2021-10-13 15:21:00 -07:00
|
|
|
id: this.credentialId,
|
2021-09-11 01:15:36 -07:00
|
|
|
name: this.credentialName,
|
|
|
|
type: this.credentialTypeName!,
|
|
|
|
data: data as unknown as ICredentialDataDecryptedObject,
|
|
|
|
nodesAccess,
|
2022-09-21 01:20:29 -07:00
|
|
|
sharedWith,
|
|
|
|
ownedBy,
|
2021-09-11 01:15:36 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
let credential;
|
|
|
|
|
2022-07-09 23:53:04 -07:00
|
|
|
const isNewCredential = this.mode === 'new' && !this.credentialId;
|
|
|
|
|
|
|
|
if (isNewCredential) {
|
2022-12-14 01:04:10 -08:00
|
|
|
credential = await this.createCredential(credentialDetails);
|
2021-09-11 01:15:36 -07:00
|
|
|
} else {
|
2022-12-14 01:04:10 -08:00
|
|
|
credential = await this.updateCredential(credentialDetails);
|
2021-09-11 01:15:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
this.isSaving = false;
|
|
|
|
if (credential) {
|
|
|
|
this.credentialId = credential.id as string;
|
|
|
|
|
|
|
|
if (this.isCredentialTestable) {
|
|
|
|
this.isTesting = true;
|
2022-01-24 08:37:07 -08:00
|
|
|
// Add the full data including defaults for testing
|
|
|
|
credentialDetails.data = this.credentialData;
|
|
|
|
|
2022-07-19 01:09:06 -07:00
|
|
|
credentialDetails.id = this.credentialId;
|
|
|
|
|
2021-09-11 01:15:36 -07:00
|
|
|
await this.testCredential(credentialDetails);
|
|
|
|
this.isTesting = false;
|
2022-12-14 01:04:10 -08:00
|
|
|
} else {
|
2021-09-11 01:15:36 -07:00
|
|
|
this.authError = '';
|
|
|
|
this.testedSuccessfully = false;
|
|
|
|
}
|
2022-07-09 23:53:04 -07:00
|
|
|
|
|
|
|
const trackProperties: ITelemetryTrackProperties = {
|
|
|
|
credential_type: credentialDetails.type,
|
2022-11-04 06:04:31 -07:00
|
|
|
workflow_id: this.workflowsStore.workflowId,
|
2022-07-09 23:53:04 -07:00
|
|
|
credential_id: credential.id,
|
|
|
|
is_complete: !!this.requiredPropertiesFilled,
|
|
|
|
is_new: isNewCredential,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (this.isOAuthType) {
|
|
|
|
trackProperties.is_valid = !!this.isOAuthConnected;
|
|
|
|
} else if (this.isCredentialTestable) {
|
|
|
|
trackProperties.is_valid = !!this.testedSuccessfully;
|
|
|
|
}
|
|
|
|
|
2022-11-04 06:04:31 -07:00
|
|
|
if (this.ndvStore.activeNode) {
|
|
|
|
trackProperties.node_type = this.ndvStore.activeNode.type;
|
2022-07-09 23:53:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.authError && this.authError !== '') {
|
|
|
|
trackProperties.authError = this.authError;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$telemetry.track('User saved credentials', trackProperties);
|
2022-08-19 06:35:39 -07:00
|
|
|
this.$externalHooks().run('credentialEdit.saveCredential', trackProperties);
|
2021-09-11 01:15:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return credential;
|
|
|
|
},
|
|
|
|
|
|
|
|
async createCredential(
|
|
|
|
credentialDetails: ICredentialsDecrypted,
|
|
|
|
): Promise<ICredentialsResponse | null> {
|
|
|
|
let credential;
|
|
|
|
|
|
|
|
try {
|
2022-11-09 01:01:50 -08:00
|
|
|
credential = await this.credentialsStore.createNewCredential(credentialDetails);
|
2021-09-11 01:15:36 -07:00
|
|
|
this.hasUnsavedChanges = false;
|
|
|
|
} catch (error) {
|
|
|
|
this.$showError(
|
|
|
|
error,
|
2021-12-15 04:16:53 -08:00
|
|
|
this.$locale.baseText('credentialEdit.credentialEdit.showError.createCredential.title'),
|
2021-09-11 01:15:36 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-09-21 01:20:29 -07:00
|
|
|
this.$externalHooks().run('credential.saved', {
|
|
|
|
credential_type: credentialDetails.type,
|
|
|
|
credential_id: credential.id,
|
|
|
|
is_new: true,
|
2021-09-11 01:15:36 -07:00
|
|
|
});
|
|
|
|
|
2022-09-21 01:20:29 -07:00
|
|
|
this.$telemetry.track('User created credentials', {
|
|
|
|
credential_type: credentialDetails.type,
|
|
|
|
credential_id: credential.id,
|
2022-11-04 06:04:31 -07:00
|
|
|
workflow_id: this.workflowsStore.workflowId,
|
2022-09-21 01:20:29 -07:00
|
|
|
});
|
2021-10-18 20:57:49 -07:00
|
|
|
|
2021-09-11 01:15:36 -07:00
|
|
|
return credential;
|
|
|
|
},
|
|
|
|
|
|
|
|
async updateCredential(
|
|
|
|
credentialDetails: ICredentialsDecrypted,
|
|
|
|
): Promise<ICredentialsResponse | null> {
|
|
|
|
let credential;
|
|
|
|
try {
|
2022-12-14 01:04:10 -08:00
|
|
|
credential = await this.credentialsStore.updateCredential({
|
|
|
|
id: this.credentialId,
|
|
|
|
data: credentialDetails,
|
|
|
|
});
|
2021-09-11 01:15:36 -07:00
|
|
|
this.hasUnsavedChanges = false;
|
|
|
|
} catch (error) {
|
|
|
|
this.$showError(
|
|
|
|
error,
|
2021-12-15 04:16:53 -08:00
|
|
|
this.$locale.baseText('credentialEdit.credentialEdit.showError.updateCredential.title'),
|
2021-09-11 01:15:36 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-09-21 01:20:29 -07:00
|
|
|
this.$externalHooks().run('credential.saved', {
|
|
|
|
credential_type: credentialDetails.type,
|
|
|
|
credential_id: credential.id,
|
|
|
|
is_new: false,
|
|
|
|
});
|
|
|
|
|
2021-09-11 01:15:36 -07:00
|
|
|
// Now that the credentials changed check if any nodes use credentials
|
|
|
|
// which have now a different name
|
|
|
|
this.updateNodesCredentialsIssues();
|
|
|
|
|
|
|
|
return credential;
|
|
|
|
},
|
|
|
|
|
|
|
|
async deleteCredential() {
|
|
|
|
if (!this.currentCredential) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const savedCredentialName = this.currentCredential.name;
|
|
|
|
|
|
|
|
const deleteConfirmed = await this.confirmMessage(
|
2022-12-14 01:04:10 -08:00
|
|
|
this.$locale.baseText(
|
|
|
|
'credentialEdit.credentialEdit.confirmMessage.deleteCredential.message',
|
|
|
|
{ interpolate: { savedCredentialName } },
|
|
|
|
),
|
|
|
|
this.$locale.baseText(
|
|
|
|
'credentialEdit.credentialEdit.confirmMessage.deleteCredential.headline',
|
|
|
|
),
|
2021-09-11 01:15:36 -07:00
|
|
|
null,
|
2022-12-14 01:04:10 -08:00
|
|
|
this.$locale.baseText(
|
|
|
|
'credentialEdit.credentialEdit.confirmMessage.deleteCredential.confirmButtonText',
|
|
|
|
),
|
2021-09-11 01:15:36 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
if (deleteConfirmed === false) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
this.isDeleting = true;
|
2022-11-09 01:01:50 -08:00
|
|
|
this.credentialsStore.deleteCredential({ id: this.credentialId });
|
2021-09-11 01:15:36 -07:00
|
|
|
this.hasUnsavedChanges = false;
|
|
|
|
} catch (error) {
|
|
|
|
this.$showError(
|
|
|
|
error,
|
2021-12-15 04:16:53 -08:00
|
|
|
this.$locale.baseText('credentialEdit.credentialEdit.showError.deleteCredential.title'),
|
2021-09-11 01:15:36 -07:00
|
|
|
);
|
|
|
|
this.isDeleting = false;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.isDeleting = false;
|
|
|
|
// Now that the credentials were removed check if any nodes used them
|
|
|
|
this.updateNodesCredentialsIssues();
|
2023-01-27 00:05:43 -08:00
|
|
|
this.credentialData = {};
|
2021-09-11 01:15:36 -07:00
|
|
|
|
|
|
|
this.$showMessage({
|
2021-12-15 04:16:53 -08:00
|
|
|
title: this.$locale.baseText('credentialEdit.credentialEdit.showMessage.title'),
|
2021-09-11 01:15:36 -07:00
|
|
|
type: 'success',
|
|
|
|
});
|
|
|
|
this.closeDialog();
|
|
|
|
},
|
|
|
|
|
|
|
|
async oAuthCredentialAuthorize() {
|
|
|
|
let url;
|
|
|
|
|
|
|
|
const credential = await this.saveCredential();
|
|
|
|
if (!credential) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const types = this.parentTypes;
|
|
|
|
|
|
|
|
try {
|
2022-11-09 01:01:50 -08:00
|
|
|
const credData = { id: credential.id, ...this.credentialData };
|
2022-12-14 01:04:10 -08:00
|
|
|
if (this.credentialTypeName === 'oAuth2Api' || types.includes('oAuth2Api')) {
|
2022-11-09 01:01:50 -08:00
|
|
|
if (isValidCredentialResponse(credData)) {
|
|
|
|
url = await this.credentialsStore.oAuth2Authorize(credData);
|
|
|
|
}
|
2022-12-14 01:04:10 -08:00
|
|
|
} else if (this.credentialTypeName === 'oAuth1Api' || types.includes('oAuth1Api')) {
|
2022-11-09 01:01:50 -08:00
|
|
|
if (isValidCredentialResponse(credData)) {
|
|
|
|
url = await this.credentialsStore.oAuth1Authorize(credData);
|
|
|
|
}
|
2021-09-11 01:15:36 -07:00
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
this.$showError(
|
|
|
|
error,
|
2022-12-14 01:04:10 -08:00
|
|
|
this.$locale.baseText(
|
|
|
|
'credentialEdit.credentialEdit.showError.generateAuthorizationUrl.title',
|
|
|
|
),
|
|
|
|
this.$locale.baseText(
|
|
|
|
'credentialEdit.credentialEdit.showError.generateAuthorizationUrl.message',
|
|
|
|
),
|
2021-09-11 01:15:36 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-29 03:20:43 -08:00
|
|
|
const params =
|
|
|
|
'scrollbars=no,resizable=yes,status=no,titlebar=noe,location=no,toolbar=no,menubar=no,width=500,height=700';
|
2021-09-11 01:15:36 -07:00
|
|
|
const oauthPopup = window.open(url, 'OAuth2 Authorization', params);
|
|
|
|
Vue.set(this.credentialData, 'oauthTokenData', null);
|
|
|
|
|
|
|
|
const receiveMessage = (event: MessageEvent) => {
|
|
|
|
// // TODO: Add check that it came from n8n
|
|
|
|
// if (event.origin !== 'http://example.org:8080') {
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
if (event.data === 'success') {
|
|
|
|
window.removeEventListener('message', receiveMessage, false);
|
|
|
|
|
|
|
|
// Set some kind of data that status changes.
|
|
|
|
// As data does not get displayed directly it does not matter what data.
|
|
|
|
Vue.set(this.credentialData, 'oauthTokenData', {});
|
2022-11-09 01:01:50 -08:00
|
|
|
this.credentialsStore.enableOAuthCredential(credential);
|
2021-09-11 01:15:36 -07:00
|
|
|
|
|
|
|
// Close the window
|
|
|
|
if (oauthPopup) {
|
|
|
|
oauthPopup.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
window.addEventListener('message', receiveMessage, false);
|
|
|
|
},
|
2023-01-27 00:05:43 -08:00
|
|
|
async onAuthTypeChanged(type: string): Promise<void> {
|
|
|
|
if (!this.activeNodeType?.credentials) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const credentialsForType = getNodeCredentialForSelectedAuthType(this.activeNodeType, type);
|
|
|
|
if (credentialsForType) {
|
|
|
|
this.selectedCredential = credentialsForType.name;
|
|
|
|
this.resetCredentialData();
|
|
|
|
this.setupNodeAccess();
|
|
|
|
// Update current node auth type so credentials dropdown can be displayed properly
|
|
|
|
updateNodeAuthType(this.ndvStore.activeNode, type);
|
|
|
|
// Also update credential name but only if the default name is still used
|
|
|
|
if (this.hasUnsavedChanges && !this.hasUserSpecifiedName) {
|
|
|
|
const newDefaultName = await this.credentialsStore.getNewCredentialName({
|
|
|
|
credentialTypeName: this.defaultCredentialTypeName,
|
|
|
|
});
|
|
|
|
this.credentialName = newDefaultName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setupNodeAccess(): void {
|
|
|
|
this.nodeAccess = this.nodesWithAccess.reduce(
|
|
|
|
(accu: NodeAccessMap, node: { name: string }) => {
|
|
|
|
if (this.mode === 'new') {
|
|
|
|
accu[node.name] = { nodeType: node.name }; // enable all nodes by default
|
|
|
|
} else {
|
|
|
|
accu[node.name] = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return accu;
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
resetCredentialData(): void {
|
|
|
|
if (!this.credentialType) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (const property of this.credentialType.properties) {
|
|
|
|
if (!this.credentialType.__overwrittenProperties?.includes(property.name)) {
|
|
|
|
Vue.set(this.credentialData, property.name, property.default as CredentialInformation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-09-11 01:15:36 -07:00
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style module lang="scss">
|
|
|
|
.credentialModal {
|
2022-09-21 01:20:29 -07:00
|
|
|
--dialog-max-width: 900px;
|
|
|
|
--dialog-close-top: 31px;
|
2021-09-11 01:15:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
.mainContent {
|
2022-09-21 01:20:29 -07:00
|
|
|
flex: 1;
|
2021-09-11 01:15:36 -07:00
|
|
|
overflow: auto;
|
|
|
|
padding-bottom: 100px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.sidebar {
|
|
|
|
max-width: 170px;
|
|
|
|
min-width: 170px;
|
|
|
|
margin-right: var(--spacing-l);
|
|
|
|
flex-grow: 1;
|
2022-10-10 09:17:39 -07:00
|
|
|
|
|
|
|
ul {
|
|
|
|
padding: 0 !important;
|
|
|
|
}
|
2021-09-11 01:15:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
.header {
|
|
|
|
display: flex;
|
|
|
|
}
|
|
|
|
|
|
|
|
.container {
|
|
|
|
display: flex;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.credInfo {
|
|
|
|
display: flex;
|
2022-09-21 01:20:29 -07:00
|
|
|
align-items: center;
|
|
|
|
flex-direction: row;
|
2021-09-11 01:15:36 -07:00
|
|
|
flex-grow: 1;
|
2022-09-21 01:20:29 -07:00
|
|
|
margin-bottom: var(--spacing-l);
|
2021-09-11 01:15:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
.credActions {
|
2022-07-20 08:50:39 -07:00
|
|
|
display: flex;
|
2022-09-21 01:20:29 -07:00
|
|
|
flex-direction: row;
|
|
|
|
align-items: center;
|
2021-09-11 01:15:36 -07:00
|
|
|
margin-right: var(--spacing-xl);
|
2022-09-21 01:20:29 -07:00
|
|
|
margin-bottom: var(--spacing-l);
|
|
|
|
|
2021-09-11 01:15:36 -07:00
|
|
|
> * {
|
|
|
|
margin-left: var(--spacing-2xs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.credIcon {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
margin-right: var(--spacing-xs);
|
|
|
|
}
|
|
|
|
</style>
|