From e9d8928bb61928f3581d9281d9361c4d771cbd8b Mon Sep 17 00:00:00 2001 From: Torkild Gundersen Kjevik Date: Fri, 12 Jul 2024 01:39:58 +0200 Subject: [PATCH] fix: Make action ctx-values from reactor-ctx take precedence if set. (#1308) --- lib/ash/reactor/steps/action_step.ex | 12 ++++++++++-- lib/ash/reactor/steps/bulk_create_step.ex | 13 +++++++++++-- lib/ash/reactor/steps/bulk_update_step.ex | 13 +++++++++++-- lib/ash/reactor/steps/create_step.ex | 8 ++++++++ lib/ash/reactor/steps/destroy_step.ex | 10 +++++++++- lib/ash/reactor/steps/read_one_step.ex | 6 +++++- lib/ash/reactor/steps/read_step.ex | 6 +++++- lib/ash/reactor/steps/update_step.ex | 8 ++++++++ 8 files changed, 67 insertions(+), 9 deletions(-) diff --git a/lib/ash/reactor/steps/action_step.ex b/lib/ash/reactor/steps/action_step.ex index b40eaf72..ef56cd38 100644 --- a/lib/ash/reactor/steps/action_step.ex +++ b/lib/ash/reactor/steps/action_step.ex @@ -9,9 +9,13 @@ defmodule Ash.Reactor.ActionStep do @doc false @impl true - def run(arguments, _context, options) do + def run(arguments, context, options) do action_input_options = options + |> maybe_set_kw(:authorize?, context[:authorize?]) + |> maybe_set_kw(:actor, context[:actor]) + |> maybe_set_kw(:tenant, context[:tenant]) + |> maybe_set_kw(:tracer, context[:tracer]) |> maybe_set_kw(:authorize?, options[:authorize?]) |> maybe_set_kw(:actor, arguments[:actor]) |> maybe_set_kw(:tenant, arguments[:tenant]) @@ -27,9 +31,13 @@ defmodule Ash.Reactor.ActionStep do @doc false @impl true - def undo(record, arguments, _context, options) do + def undo(record, arguments, context, options) do action_input_options = options + |> maybe_set_kw(:authorize?, context[:authorize?]) + |> maybe_set_kw(:actor, context[:actor]) + |> maybe_set_kw(:tenant, context[:tenant]) + |> maybe_set_kw(:tracer, context[:tracer]) |> maybe_set_kw(:authorize?, options[:authorize?]) |> maybe_set_kw(:actor, arguments[:actor]) |> maybe_set_kw(:tenant, arguments[:tenant]) diff --git a/lib/ash/reactor/steps/bulk_create_step.ex b/lib/ash/reactor/steps/bulk_create_step.ex index 4443a86f..f58acdc8 100644 --- a/lib/ash/reactor/steps/bulk_create_step.ex +++ b/lib/ash/reactor/steps/bulk_create_step.ex @@ -38,6 +38,10 @@ defmodule Ash.Reactor.BulkCreateStep do :upsert_identity, :upsert? ]) + |> maybe_set_kw(:authorize?, context[:authorize?]) + |> maybe_set_kw(:actor, context[:actor]) + |> maybe_set_kw(:tenant, context[:tenant]) + |> maybe_set_kw(:tracer, context[:tracer]) |> maybe_set_kw(:actor, arguments[:actor]) |> maybe_set_kw(:tenant, arguments[:tenant]) |> maybe_set_kw(:notification_metadata, arguments[:notification_metadata]) @@ -68,10 +72,15 @@ defmodule Ash.Reactor.BulkCreateStep do @doc false @impl true - def undo(bulk_result, arguments, _context, options) when is_struct(bulk_result, BulkResult) do + def undo(bulk_result, arguments, context, options) when is_struct(bulk_result, BulkResult) do action_options = options - |> Keyword.take([:authorize?, :domain]) + |> Keyword.take([:domain]) + |> maybe_set_kw(:authorize?, context[:authorize?]) + |> maybe_set_kw(:actor, context[:actor]) + |> maybe_set_kw(:tenant, context[:tenant]) + |> maybe_set_kw(:tracer, context[:tracer]) + |> maybe_set_kw(:authorize?, options[:authorize?]) |> maybe_set_kw(:actor, arguments[:actor]) |> maybe_set_kw(:tenant, arguments[:tenant]) diff --git a/lib/ash/reactor/steps/bulk_update_step.ex b/lib/ash/reactor/steps/bulk_update_step.ex index 9fb9d78e..22e40794 100644 --- a/lib/ash/reactor/steps/bulk_update_step.ex +++ b/lib/ash/reactor/steps/bulk_update_step.ex @@ -47,6 +47,10 @@ defmodule Ash.Reactor.BulkUpdateStep do |> maybe_set_kw(:actor, arguments[:actor]) |> maybe_set_kw(:tenant, arguments[:tenant]) |> maybe_set_kw(:notification_metadata, arguments[:notification_metadata]) + |> maybe_set_kw(:authorize?, context[:authorize?]) + |> maybe_set_kw(:actor, context[:actor]) + |> maybe_set_kw(:tenant, context[:tenant]) + |> maybe_set_kw(:tracer, context[:tracer]) success_states = options[:success_state] @@ -74,10 +78,15 @@ defmodule Ash.Reactor.BulkUpdateStep do @doc false @impl true - def undo(bulk_result, arguments, _context, options) when is_struct(bulk_result, BulkResult) do + def undo(bulk_result, arguments, context, options) when is_struct(bulk_result, BulkResult) do action_options = options - |> Keyword.take([:authorize?, :domain]) + |> Keyword.take([:domain]) + |> maybe_set_kw(:authorize?, context[:authorize?]) + |> maybe_set_kw(:actor, context[:actor]) + |> maybe_set_kw(:tenant, context[:tenant]) + |> maybe_set_kw(:tracer, context[:tracer]) + |> maybe_set_kw(:authorize?, options[:authorize?]) |> maybe_set_kw(:actor, arguments[:actor]) |> maybe_set_kw(:tenant, arguments[:tenant]) diff --git a/lib/ash/reactor/steps/create_step.ex b/lib/ash/reactor/steps/create_step.ex index a8edf401..8cc28673 100644 --- a/lib/ash/reactor/steps/create_step.ex +++ b/lib/ash/reactor/steps/create_step.ex @@ -12,6 +12,10 @@ defmodule Ash.Reactor.CreateStep do def run(arguments, context, options) do changeset_options = options + |> maybe_set_kw(:authorize?, context[:authorize?]) + |> maybe_set_kw(:actor, context[:actor]) + |> maybe_set_kw(:tenant, context[:tenant]) + |> maybe_set_kw(:tracer, context[:tracer]) |> maybe_set_kw(:authorize?, options[:authorize?]) |> maybe_set_kw(:upsert_identity, options[:upsert_identity]) |> maybe_set_kw(:upsert?, options[:upsert?]) @@ -57,6 +61,10 @@ defmodule Ash.Reactor.CreateStep do def undo(record, arguments, context, options) do changeset_options = [] + |> maybe_set_kw(:authorize?, context[:authorize?]) + |> maybe_set_kw(:actor, context[:actor]) + |> maybe_set_kw(:tenant, context[:tenant]) + |> maybe_set_kw(:tracer, context[:tracer]) |> maybe_set_kw(:authorize?, options[:authorize?]) |> maybe_set_kw(:actor, arguments[:actor]) |> maybe_set_kw(:tenant, arguments[:tenant]) diff --git a/lib/ash/reactor/steps/destroy_step.ex b/lib/ash/reactor/steps/destroy_step.ex index 74e7694f..841cbdf2 100644 --- a/lib/ash/reactor/steps/destroy_step.ex +++ b/lib/ash/reactor/steps/destroy_step.ex @@ -14,6 +14,10 @@ defmodule Ash.Reactor.DestroyStep do changeset_options = options + |> maybe_set_kw(:authorize?, context[:authorize?]) + |> maybe_set_kw(:actor, context[:actor]) + |> maybe_set_kw(:tenant, context[:tenant]) + |> maybe_set_kw(:tracer, context[:tracer]) |> maybe_set_kw(:authorize?, options[:authorize?]) |> maybe_set_kw(:actor, arguments[:actor]) |> maybe_set_kw(:tenant, arguments[:tenant]) @@ -49,9 +53,13 @@ defmodule Ash.Reactor.DestroyStep do @doc false @impl true - def undo(record, arguments, _context, options) do + def undo(record, arguments, context, options) do changeset_options = options + |> maybe_set_kw(:authorize?, context[:authorize?]) + |> maybe_set_kw(:actor, context[:actor]) + |> maybe_set_kw(:tenant, context[:tenant]) + |> maybe_set_kw(:tracer, context[:tracer]) |> maybe_set_kw(:authorize?, options[:authorize?]) |> maybe_set_kw(:actor, arguments[:actor]) |> maybe_set_kw(:tenant, arguments[:tenant]) diff --git a/lib/ash/reactor/steps/read_one_step.ex b/lib/ash/reactor/steps/read_one_step.ex index 53c6bc52..ceed8191 100644 --- a/lib/ash/reactor/steps/read_one_step.ex +++ b/lib/ash/reactor/steps/read_one_step.ex @@ -7,9 +7,13 @@ defmodule Ash.Reactor.ReadOneStep do alias Ash.Query - def run(arguments, _context, options) do + def run(arguments, context, options) do query_options = options + |> maybe_set_kw(:tracer, context[:tracer]) + |> maybe_set_kw(:authorize?, context[:authorize?]) + |> maybe_set_kw(:actor, context[:actor]) + |> maybe_set_kw(:tenant, context[:tenant]) |> maybe_set_kw(:authorize?, options[:authorize?]) |> maybe_set_kw(:actor, arguments[:actor]) |> maybe_set_kw(:tenant, arguments[:tenant]) diff --git a/lib/ash/reactor/steps/read_step.ex b/lib/ash/reactor/steps/read_step.ex index 148625ff..fb62700a 100644 --- a/lib/ash/reactor/steps/read_step.ex +++ b/lib/ash/reactor/steps/read_step.ex @@ -7,9 +7,13 @@ defmodule Ash.Reactor.ReadStep do alias Ash.Query - def run(arguments, _context, options) do + def run(arguments, context, options) do query_options = options + |> maybe_set_kw(:authorize?, context[:authorize?]) + |> maybe_set_kw(:actor, context[:actor]) + |> maybe_set_kw(:tenant, context[:tenant]) + |> maybe_set_kw(:tracer, context[:tracer]) |> maybe_set_kw(:authorize?, options[:authorize?]) |> maybe_set_kw(:actor, arguments[:actor]) |> maybe_set_kw(:tenant, arguments[:tenant]) diff --git a/lib/ash/reactor/steps/update_step.ex b/lib/ash/reactor/steps/update_step.ex index 25d38074..febeed24 100644 --- a/lib/ash/reactor/steps/update_step.ex +++ b/lib/ash/reactor/steps/update_step.ex @@ -12,6 +12,10 @@ defmodule Ash.Reactor.UpdateStep do def run(arguments, context, options) do changeset_options = options + |> maybe_set_kw(:authorize?, context[:authorize?]) + |> maybe_set_kw(:actor, context[:actor]) + |> maybe_set_kw(:tenant, context[:tenant]) + |> maybe_set_kw(:tracer, context[:tracer]) |> maybe_set_kw(:authorize?, options[:authorize?]) |> maybe_set_kw(:actor, arguments[:actor]) |> maybe_set_kw(:tenant, arguments[:tenant]) @@ -44,6 +48,10 @@ defmodule Ash.Reactor.UpdateStep do def undo(record, arguments, context, options) do changeset_options = options + |> maybe_set_kw(:authorize?, context[:authorize?]) + |> maybe_set_kw(:actor, context[:actor]) + |> maybe_set_kw(:tenant, context[:tenant]) + |> maybe_set_kw(:tracer, context[:tracer]) |> maybe_set_kw(:authorize?, options[:authorize?]) |> maybe_set_kw(:actor, arguments[:actor]) |> maybe_set_kw(:tenant, arguments[:tenant])