Skip to content

Commit

Permalink
Fixed from reviewers
Browse files Browse the repository at this point in the history
  • Loading branch information
krynble committed Jan 31, 2022
1 parent 99cc33e commit 61a541b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
4 changes: 2 additions & 2 deletions packages/cli/commands/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from '../src';

import { getLogger } from '../src/Logger';
import { getInstanceowner } from '../src/UserManagement/UserManagementHelper';
import { getInstanceOwner } from '../src/UserManagement/UserManagementHelper';

export class Execute extends Command {
static description = '\nExecutes a given workflow';
Expand Down Expand Up @@ -166,7 +166,7 @@ export class Execute extends Command {
startNodes: [startNode.name],
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
workflowData: workflowData!,
user: await getInstanceowner(),
user: await getInstanceOwner(),
};

const workflowRunner = new WorkflowRunner();
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/commands/executeBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
WorkflowRunner,
} from '../src';
import { User } from '../src/databases/entities/User';
import { getInstanceowner } from '../src/UserManagement/UserManagementHelper';
import { getInstanceOwner } from '../src/UserManagement/UserManagementHelper';

export class ExecuteBatch extends Command {
static description = '\nExecutes multiple workflows once';
Expand Down Expand Up @@ -280,7 +280,7 @@ export class ExecuteBatch extends Command {
// Wait till the database is ready
await startDbInitPromise;

ExecuteBatch.instanceOwner = await getInstanceowner();
ExecuteBatch.instanceOwner = await getInstanceOwner();

let allWorkflows;

Expand Down
11 changes: 6 additions & 5 deletions packages/cli/src/UserManagement/UserManagementHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,16 @@ export async function saveCredentialOwnership(
})) as SharedCredentials;
}

export async function getWorkflowOwner(workflowId: string) {
const workflowDb = await Db.collections.Workflow!.findOneOrFail(workflowId, {
relations: ['shared', 'shared.user', 'shared.user.globalRole'],
export async function getWorkflowOwner(workflowId: string | number) {
const sharedWorkflow = await Db.collections.SharedWorkflow!.findOneOrFail({
where: { workflow: { id: workflowId } },
relations: ['user', 'user.globalRole'],
});

return workflowDb.shared[0].user;
return sharedWorkflow.user;
}

export async function getInstanceowner() {
export async function getInstanceOwner() {
const qb = Db.collections.User!.createQueryBuilder('u');
qb.innerJoin('u.globalRole', 'gr');
qb.andWhere('gr.name = :name and gr.scope = :scope', { name: 'owner', scope: 'global' });
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/WebhookHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export async function executeWebhook(
try {
user = await getWorkflowOwner(workflowData.id.toString());
} catch (error) {
throw new ResponseHelper.ResponseError('Cannot find workflow', 500, 500);
throw new ResponseHelper.ResponseError('Cannot find workflow', undefined, 404);
}
}

Expand Down
9 changes: 2 additions & 7 deletions packages/cli/src/WorkflowExecuteAdditionalData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,9 +818,7 @@ export async function executeWorkflow(
const nodeTypes = NodeTypes();

const workflowData =
loadedWorkflowData !== undefined
? loadedWorkflowData
: await getWorkflowData(workflowInfo, additionalData.user);
loadedWorkflowData ?? (await getWorkflowData(workflowInfo, additionalData.user));

const workflowName = workflowData ? workflowData.name : undefined;
const workflow = new Workflow({
Expand All @@ -833,10 +831,7 @@ export async function executeWorkflow(
staticData: workflowData.staticData,
});

const runData =
loadedRunData !== undefined
? loadedRunData
: await getRunData(workflowData, additionalData.user, inputData);
const runData = loadedRunData ?? (await getRunData(workflowData, additionalData.user, inputData));

let executionId;

Expand Down

0 comments on commit 61a541b

Please sign in to comment.