Merge pull request #1233 from automatisch/enhance-variable-coverage
feat: enhance step variable coverage
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import Context from '../../types/express/context';
|
import Context from '../../types/express/context';
|
||||||
import testRun from '../../services/test-run';
|
import testRun from '../../services/test-run';
|
||||||
|
import Step from '../../models/step';
|
||||||
|
|
||||||
type Params = {
|
type Params = {
|
||||||
input: {
|
input: {
|
||||||
@@ -12,12 +13,16 @@ const executeFlow = async (
|
|||||||
params: Params,
|
params: Params,
|
||||||
context: Context
|
context: Context
|
||||||
) => {
|
) => {
|
||||||
context.currentUser.can('update', 'Flow');
|
const conditions = context.currentUser.can('update', 'Flow');
|
||||||
|
const isCreator = conditions.isCreator;
|
||||||
|
const allSteps = Step.query();
|
||||||
|
const userSteps = context.currentUser.$relatedQuery('steps');
|
||||||
|
const baseQuery = isCreator ? userSteps : allSteps;
|
||||||
|
|
||||||
const { stepId } = params.input;
|
const { stepId } = params.input;
|
||||||
|
|
||||||
const untilStep = await context.currentUser
|
const untilStep = await baseQuery
|
||||||
.$relatedQuery('steps')
|
.clone()
|
||||||
.findById(stepId)
|
.findById(stepId)
|
||||||
.throwIfNotFound();
|
.throwIfNotFound();
|
||||||
|
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
import Flow from '../../models/flow';
|
||||||
import Context from '../../types/express/context';
|
import Context from '../../types/express/context';
|
||||||
import flowQueue from '../../queues/flow';
|
import flowQueue from '../../queues/flow';
|
||||||
import { REMOVE_AFTER_30_DAYS_OR_150_JOBS, REMOVE_AFTER_7_DAYS_OR_50_JOBS } from '../../helpers/remove-job-configuration';
|
import { REMOVE_AFTER_30_DAYS_OR_150_JOBS, REMOVE_AFTER_7_DAYS_OR_50_JOBS } from '../../helpers/remove-job-configuration';
|
||||||
@@ -18,10 +19,14 @@ const updateFlowStatus = async (
|
|||||||
params: Params,
|
params: Params,
|
||||||
context: Context
|
context: Context
|
||||||
) => {
|
) => {
|
||||||
context.currentUser.can('publish', 'Flow');
|
const conditions = context.currentUser.can('publish', 'Flow');
|
||||||
|
const isCreator = conditions.isCreator;
|
||||||
|
const allFlows = Flow.query();
|
||||||
|
const userFlows = context.currentUser.$relatedQuery('flows');
|
||||||
|
const baseQuery = isCreator ? userFlows : allFlows;
|
||||||
|
|
||||||
let flow = await context.currentUser
|
let flow = await baseQuery
|
||||||
.$relatedQuery('flows')
|
.clone()
|
||||||
.findOne({
|
.findOne({
|
||||||
id: params.input.id,
|
id: params.input.id,
|
||||||
})
|
})
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import { IJSONObject } from '@automatisch/types';
|
import { IJSONObject } from '@automatisch/types';
|
||||||
import App from '../../models/app';
|
import App from '../../models/app';
|
||||||
import Step from '../../models/step';
|
import Step from '../../models/step';
|
||||||
|
import Connection from '../../models/connection';
|
||||||
import Context from '../../types/express/context';
|
import Context from '../../types/express/context';
|
||||||
|
|
||||||
type Params = {
|
type Params = {
|
||||||
@@ -23,12 +24,14 @@ const updateStep = async (
|
|||||||
params: Params,
|
params: Params,
|
||||||
context: Context
|
context: Context
|
||||||
) => {
|
) => {
|
||||||
context.currentUser.can('update', 'Flow');
|
const { isCreator } = context.currentUser.can('update', 'Flow');
|
||||||
|
const userSteps = context.currentUser.$relatedQuery('steps');
|
||||||
|
const allSteps = Step.query();
|
||||||
|
const baseQuery = isCreator ? userSteps : allSteps;
|
||||||
|
|
||||||
const { input } = params;
|
const { input } = params;
|
||||||
|
|
||||||
let step = await context.currentUser
|
let step = await baseQuery
|
||||||
.$relatedQuery('steps')
|
|
||||||
.findOne({
|
.findOne({
|
||||||
'steps.id': input.id,
|
'steps.id': input.id,
|
||||||
flow_id: input.flow.id,
|
flow_id: input.flow.id,
|
||||||
@@ -36,11 +39,24 @@ const updateStep = async (
|
|||||||
.throwIfNotFound();
|
.throwIfNotFound();
|
||||||
|
|
||||||
if (input.connection.id) {
|
if (input.connection.id) {
|
||||||
const hasConnection = await context.currentUser
|
let canSeeAllConnections = false;
|
||||||
.$relatedQuery('connections')
|
try {
|
||||||
.findById(input.connection?.id);
|
const conditions = context.currentUser.can('read', 'Connection');
|
||||||
|
|
||||||
if (!hasConnection) {
|
canSeeAllConnections = !conditions.isCreator;
|
||||||
|
} catch {
|
||||||
|
// void
|
||||||
|
}
|
||||||
|
|
||||||
|
const userConnections = context.currentUser.$relatedQuery('connections');
|
||||||
|
const allConnections = Connection.query();
|
||||||
|
const baseConnectionsQuery = canSeeAllConnections ? allConnections : userConnections;
|
||||||
|
|
||||||
|
const connection = await baseConnectionsQuery
|
||||||
|
.clone()
|
||||||
|
.findById(input.connection?.id)
|
||||||
|
|
||||||
|
if (!connection) {
|
||||||
throw new Error('The connection does not exist!');
|
throw new Error('The connection does not exist!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,8 +2,7 @@ import Step from '../models/step';
|
|||||||
import ExecutionStep from '../models/execution-step';
|
import ExecutionStep from '../models/execution-step';
|
||||||
import get from 'lodash.get';
|
import get from 'lodash.get';
|
||||||
|
|
||||||
// INFO: don't remove space in allowed character group!
|
const variableRegExp = /({{step\.[\da-zA-Z-]+(?:\.[^.}{]+)+}})/g;
|
||||||
const variableRegExp = /({{step\.[\da-zA-Z-]+(?:\.[\da-zA-Z-_ :]+)+}})/g;
|
|
||||||
|
|
||||||
export default function computeParameters(
|
export default function computeParameters(
|
||||||
parameters: Step['parameters'],
|
parameters: Step['parameters'],
|
||||||
|
Reference in New Issue
Block a user