fix: copy tenant to step on flow build (#603)

This commit is contained in:
kernel-io 2023-06-07 01:27:02 +12:00 committed by GitHub
parent c4bb198d0c
commit 5b6c81d800
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,12 +17,12 @@ defmodule Ash.Flow.Executor.AshEngine do
defstruct [:steps, :flow, :returns] defstruct [:steps, :flow, :returns]
end end
def build(flow, input, _opts) do def build(flow, input, opts) do
steps = steps =
flow flow
|> Ash.Flow.Info.steps() |> Ash.Flow.Info.steps()
|> to_steps(input) |> to_steps(input, opts)
|> hydrate_flows() |> hydrate_flows(opts)
{:ok, {:ok,
%Flow{ %Flow{
@ -32,7 +32,7 @@ defmodule Ash.Flow.Executor.AshEngine do
}} }}
end end
defp to_steps(steps, input) do defp to_steps(steps, input, opts) do
Enum.map(steps, fn step -> Enum.map(steps, fn step ->
step = step =
case step do case step do
@ -48,7 +48,10 @@ defmodule Ash.Flow.Executor.AshEngine do
step step
end 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 ->
step step
@ -58,7 +61,7 @@ defmodule Ash.Flow.Executor.AshEngine do
end) end)
end end
defp hydrate_flows(steps) do defp hydrate_flows(steps, opts) do
Enum.flat_map(steps, fn Enum.flat_map(steps, fn
%Step{ %Step{
input: input, input: input,
@ -71,7 +74,7 @@ defmodule Ash.Flow.Executor.AshEngine do
} }
} = run_flow_step -> } = run_flow_step ->
{run_flow_input, _} = Ash.Flow.Template.handle_input_template(run_flow_input, input) {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 = built_steps =
hydrated_steps hydrated_steps
@ -119,7 +122,8 @@ defmodule Ash.Flow.Executor.AshEngine do
|> handle_input_templates() |> handle_input_templates()
%Step{step: %{steps: steps} = inner_step} = step -> %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 ->
[step] |> handle_input_templates() [step] |> handle_input_templates()