fix: Fix foreign credentials being shown for new nodes (#4622)

* feat: Extract usedCredentials into separate store entry and fix foreign credentials being shown for new nodes

* chore: adjust spacing
This commit is contained in:
Alex Grozav
2022-11-17 16:22:46 +02:00
committed by GitHub
parent 7483e147fc
commit dea67ca6b7
5 changed files with 27 additions and 11 deletions

View File

@@ -49,9 +49,6 @@ export const useCredentialsStore = defineStore(STORES.CREDENTIALS, {
getCredentialById() {
return (id: string): ICredentialsResponse => this.credentials[id];
},
foreignCredentialsById(): ICredentialMap {
return Object.fromEntries(Object.entries(this.credentials).filter(([_, credential]) => credential.hasOwnProperty('currentUserHasAccess')));
},
getCredentialByIdAndType() {
return (id: string, type: string): ICredentialsResponse | undefined => {
const credential = this.credentials[id];
@@ -226,7 +223,7 @@ export const useCredentialsStore = defineStore(STORES.CREDENTIALS, {
return credential;
},
async deleteCredential({ id }: {id: string}): void {
async deleteCredential({ id }: {id: string}) {
const rootStore = useRootStore();
const deleted = await deleteCredential(rootStore.getRestApiContext, id);
if (deleted) {
@@ -263,10 +260,10 @@ export const useCredentialsStore = defineStore(STORES.CREDENTIALS, {
},
// Enterprise edition actions
setCredentialOwnedBy(payload: { credentialId: string, ownedBy: Partial<IUser> }): void {
setCredentialOwnedBy(payload: { credentialId: string, ownedBy: Partial<IUser> }) {
Vue.set(this.credentials[payload.credentialId], 'ownedBy', payload.ownedBy);
},
async setCredentialSharedWith(payload: { sharedWith: IUser[]; credentialId: string; }): void {
async setCredentialSharedWith(payload: { sharedWith: IUser[]; credentialId: string; }) {
if(useSettingsStore().isEnterpriseFeatureEnabled(EnterpriseEditionFeature.Sharing)) {
await setCredentialSharedWith(
useRootStore().getRestApiContext,

View File

@@ -7,6 +7,7 @@ import {
STORES,
} from "@/constants";
import {
ICredentialMap,
IExecutionResponse,
IExecutionsCurrentSummaryExtended,
IExecutionsSummary,
@@ -16,6 +17,7 @@ import {
IPushDataExecutionFinished,
IPushDataNodeExecuteAfter,
IUpdateInformation,
IUsedCredential,
IWorkflowDb,
IWorkflowsMap,
WorkflowsState,
@@ -37,6 +39,7 @@ import {
IWorkflowSettings,
} from 'n8n-workflow';
import Vue from "vue";
import {useRootStore} from "./n8nRootStore";
import {
getActiveWorkflows,
@@ -73,6 +76,7 @@ const createEmptyWorkflow = (): IWorkflowDb => ({
export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, {
state: (): WorkflowsState => ({
workflow: createEmptyWorkflow(),
usedCredentials: {},
activeWorkflows: [],
activeExecutions: [],
currentWorkflowExecutions: [],
@@ -266,6 +270,13 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, {
this.workflow.id = id === 'new' ? PLACEHOLDER_EMPTY_WORKFLOW_ID : id;
},
setUsedCredentials(data: IUsedCredential[]) {
this.usedCredentials = data.reduce<{ [name: string]: IUsedCredential }>((accu, credential) => {
accu[credential.id!] = credential;
return accu;
}, {});
},
setWorkflowName(data: { newName: string, setStateDirty: boolean }): void {
if (data.setStateDirty === true) {
const uiStore = useUIStore();