From 5b6c81d8008c0dea86c5820ba7834c5d8e078782 Mon Sep 17 00:00:00 2001 From: kernel-io Date: Wed, 7 Jun 2023 01:27:02 +1200 Subject: [PATCH] fix: copy tenant to step on flow build (#603) --- lib/ash/flow/executor/ash_engine.ex | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/ash/flow/executor/ash_engine.ex b/lib/ash/flow/executor/ash_engine.ex index 49acd8c6..25ac6233 100644 --- a/lib/ash/flow/executor/ash_engine.ex +++ b/lib/ash/flow/executor/ash_engine.ex @@ -17,12 +17,12 @@ defmodule Ash.Flow.Executor.AshEngine do defstruct [:steps, :flow, :returns] end - def build(flow, input, _opts) do + def build(flow, input, opts) do steps = flow |> Ash.Flow.Info.steps() - |> to_steps(input) - |> hydrate_flows() + |> to_steps(input, opts) + |> hydrate_flows(opts) {:ok, %Flow{ @@ -32,7 +32,7 @@ defmodule Ash.Flow.Executor.AshEngine do }} end - defp to_steps(steps, input) do + defp to_steps(steps, input, opts) do Enum.map(steps, fn step -> step = case step do @@ -48,7 +48,10 @@ defmodule Ash.Flow.Executor.AshEngine do step end - %{step | steps: to_steps(steps, input)} + %{step | steps: to_steps(steps, input, opts)} + + %{tenant: _tenant} = step -> + %{step | tenant: Keyword.get(opts, :tenant)} step -> step @@ -58,7 +61,7 @@ defmodule Ash.Flow.Executor.AshEngine do end) end - defp hydrate_flows(steps) do + defp hydrate_flows(steps, opts) do Enum.flat_map(steps, fn %Step{ input: input, @@ -71,7 +74,7 @@ defmodule Ash.Flow.Executor.AshEngine do } } = run_flow_step -> {run_flow_input, _} = Ash.Flow.Template.handle_input_template(run_flow_input, input) - {:ok, %{steps: hydrated_steps}} = build(flow, run_flow_input, []) + {:ok, %{steps: hydrated_steps}} = build(flow, run_flow_input, opts) built_steps = hydrated_steps @@ -119,7 +122,8 @@ defmodule Ash.Flow.Executor.AshEngine do |> handle_input_templates() %Step{step: %{steps: steps} = inner_step} = step -> - [%{step | step: %{inner_step | steps: hydrate_flows(steps)}}] |> handle_input_templates() + [%{step | step: %{inner_step | steps: hydrate_flows(steps, opts)}}] + |> handle_input_templates() step -> [step] |> handle_input_templates()