diff --git a/packages/cli/src/PublicApi/v1/handlers/executions/executions.service.ts b/packages/cli/src/PublicApi/v1/handlers/executions/executions.service.ts index d05a9142ae..a82fc2f5dd 100644 --- a/packages/cli/src/PublicApi/v1/handlers/executions/executions.service.ts +++ b/packages/cli/src/PublicApi/v1/handlers/executions/executions.service.ts @@ -123,7 +123,7 @@ export async function getExecutionsCount(data: { export async function getExecutionInWorkflows( id: number, - workflows: number[], + workflows: string[], includeData?: boolean, ): Promise { const execution = await Db.collections.Execution.findOne({ diff --git a/packages/cli/src/PublicApi/v1/handlers/workflows/workflows.service.ts b/packages/cli/src/PublicApi/v1/handlers/workflows/workflows.service.ts index 7193d3e67f..a831858c1e 100644 --- a/packages/cli/src/PublicApi/v1/handlers/workflows/workflows.service.ts +++ b/packages/cli/src/PublicApi/v1/handlers/workflows/workflows.service.ts @@ -15,12 +15,12 @@ function insertIf(condition: boolean, elements: string[]): string[] { return condition ? elements : []; } -export async function getSharedWorkflowIds(user: User): Promise { +export async function getSharedWorkflowIds(user: User): Promise { const sharedWorkflows = await Db.collections.SharedWorkflow.find({ where: { user }, }); - return sharedWorkflows.map((workflow) => workflow.workflowId); + return sharedWorkflows.map(({ workflowId }) => workflowId.toString()); } export async function getSharedWorkflow( diff --git a/packages/cli/src/Server.ts b/packages/cli/src/Server.ts index e9f4ea863f..e5b99748db 100644 --- a/packages/cli/src/Server.ts +++ b/packages/cli/src/Server.ts @@ -1345,9 +1345,7 @@ class App { const filter = req.query.filter ? jsonParse(req.query.filter) : {}; - const sharedWorkflowIds = await getSharedWorkflowIds(req.user).then((ids) => - ids.map((id) => id.toString()), - ); + const sharedWorkflowIds = await getSharedWorkflowIds(req.user); for (const data of executingWorkflows) { if ( diff --git a/packages/cli/src/WorkflowHelpers.ts b/packages/cli/src/WorkflowHelpers.ts index d0498e11fe..83bd0b0b7b 100644 --- a/packages/cli/src/WorkflowHelpers.ts +++ b/packages/cli/src/WorkflowHelpers.ts @@ -405,13 +405,13 @@ export async function replaceInvalidCredentials(workflow: WorkflowEntity): Promi * Get the IDs of the workflows that have been shared with the user. * Returns all IDs if user is global owner (see `whereClause`) */ -export async function getSharedWorkflowIds(user: User, roles?: string[]): Promise { +export async function getSharedWorkflowIds(user: User, roles?: string[]): Promise { const sharedWorkflows = await Db.collections.SharedWorkflow.find({ relations: ['workflow', 'role'], where: whereClause({ user, entityType: 'workflow', roles }), }); - return sharedWorkflows.map(({ workflow }) => workflow.id); + return sharedWorkflows.map(({ workflowId }) => workflowId.toString()); } /** diff --git a/packages/cli/src/executions/executions.service.ee.ts b/packages/cli/src/executions/executions.service.ee.ts index 6df410a562..8d60cf3d02 100644 --- a/packages/cli/src/executions/executions.service.ee.ts +++ b/packages/cli/src/executions/executions.service.ee.ts @@ -6,7 +6,7 @@ export class EEExecutionsService extends ExecutionsService { /** * Function to get the workflow Ids for a User regardless of role */ - static async getWorkflowIdsForUser(user: User): Promise { + static async getWorkflowIdsForUser(user: User): Promise { // Get all workflows return getSharedWorkflowIds(user); } diff --git a/packages/cli/src/executions/executions.service.ts b/packages/cli/src/executions/executions.service.ts index 139b927818..8ca2ef2540 100644 --- a/packages/cli/src/executions/executions.service.ts +++ b/packages/cli/src/executions/executions.service.ts @@ -55,7 +55,7 @@ export class ExecutionsService { * Function to get the workflow Ids for a User * Overridden in EE version to ignore roles */ - static async getWorkflowIdsForUser(user: User): Promise { + static async getWorkflowIdsForUser(user: User): Promise { // Get all workflows using owner role return getSharedWorkflowIds(user, ['owner']); } @@ -160,18 +160,16 @@ export class ExecutionsService { } // safeguard against querying workflowIds not shared with the user - if (filter?.workflowId !== undefined) { - const workflowId = parseInt(filter.workflowId.toString()); - if (workflowId && !sharedWorkflowIds.includes(workflowId)) { - LoggerProxy.verbose( - `User ${req.user.id} attempted to query non-shared workflow ${workflowId}`, - ); - return { - count: 0, - estimated: false, - results: [], - }; - } + const workflowId = filter?.workflowId?.toString(); + if (workflowId !== undefined && !sharedWorkflowIds.includes(workflowId)) { + LoggerProxy.verbose( + `User ${req.user.id} attempted to query non-shared workflow ${workflowId}`, + ); + return { + count: 0, + estimated: false, + results: [], + }; } const limit = req.query.limit diff --git a/packages/cli/src/workflows/workflows.services.ts b/packages/cli/src/workflows/workflows.services.ts index dbb2dffd23..ffff2a3eb5 100644 --- a/packages/cli/src/workflows/workflows.services.ts +++ b/packages/cli/src/workflows/workflows.services.ts @@ -116,7 +116,7 @@ export class WorkflowsService { } // Warning: this function is overriden by EE to disregard role list. - static async getWorkflowIdsForUser(user: User, roles?: string[]) { + static async getWorkflowIdsForUser(user: User, roles?: string[]): Promise { return getSharedWorkflowIds(user, roles); } @@ -152,12 +152,10 @@ export class WorkflowsService { } // safeguard against querying ids not shared with the user - if (filter?.id !== undefined) { - const workflowId = parseInt(filter.id.toString()); - if (workflowId && !sharedWorkflowIds.includes(workflowId)) { - LoggerProxy.verbose(`User ${user.id} attempted to query non-shared workflow ${workflowId}`); - return []; - } + const workflowId = filter?.id?.toString(); + if (workflowId !== undefined && !sharedWorkflowIds.includes(workflowId)) { + LoggerProxy.verbose(`User ${user.id} attempted to query non-shared workflow ${workflowId}`); + return []; } const fields: Array = ['id', 'name', 'active', 'createdAt', 'updatedAt'];