From 36dc5f0e66d267e7f8f14c73ed3251b611b1d965 Mon Sep 17 00:00:00 2001 From: Omar Ajoue Date: Wed, 23 Nov 2022 15:34:17 +0100 Subject: [PATCH] refactor: Add credential information to workflow list (no-changelog) (#4700) --- .../src/workflows/workflows.services.ee.ts | 19 +++++++++++++++++-- packages/cli/src/workflows/workflows.types.ts | 2 ++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/workflows/workflows.services.ee.ts b/packages/cli/src/workflows/workflows.services.ee.ts index ae15435943..21ce1cfbd1 100644 --- a/packages/cli/src/workflows/workflows.services.ee.ts +++ b/packages/cli/src/workflows/workflows.services.ee.ts @@ -9,7 +9,10 @@ import { WorkflowEntity } from '@db/entities/WorkflowEntity'; import { RoleService } from '@/role/role.service'; import { UserService } from '@/user/user.service'; import { WorkflowsService } from './workflows.services'; -import type { WorkflowWithSharingsAndCredentials } from './workflows.types'; +import type { + CredentialUsedByWorkflow, + WorkflowWithSharingsAndCredentials, +} from './workflows.types'; import { EECredentialsService as EECredentials } from '@/credentials/credentials.service.ee'; import { getSharedWorkflowIds } from '@/WorkflowHelpers'; @@ -129,16 +132,28 @@ export class EEWorkflowsService extends WorkflowsService { where: { id: In(Array.from(credentialIdsUsedByWorkflow)), }, + relations: ['shared', 'shared.user', 'shared.role'], }); const userCredentialIds = userCredentials.map((credential) => credential.id.toString()); workflowCredentials.forEach((credential) => { const credentialId = credential.id.toString(); - workflow.usedCredentials?.push({ + const workflowCredential: CredentialUsedByWorkflow = { id: credential.id.toString(), name: credential.name, type: credential.type, currentUserHasAccess: userCredentialIds.includes(credentialId), + sharedWith: [], + ownedBy: null, + }; + credential.shared?.forEach(({ user, role }) => { + const { id, email, firstName, lastName } = user; + if (role.name === 'owner') { + workflowCredential.ownedBy = { id, email, firstName, lastName }; + } else { + workflowCredential.sharedWith?.push({ id, email, firstName, lastName }); + } }); + workflow.usedCredentials?.push(workflowCredential); }); return workflow; diff --git a/packages/cli/src/workflows/workflows.types.ts b/packages/cli/src/workflows/workflows.types.ts index 01cfe8fdcb..38215fe778 100644 --- a/packages/cli/src/workflows/workflows.types.ts +++ b/packages/cli/src/workflows/workflows.types.ts @@ -14,4 +14,6 @@ export interface CredentialUsedByWorkflow { name: string; type?: string; currentUserHasAccess: boolean; + ownedBy?: IUser | null; + sharedWith?: IUser[]; }