Skip to content

Commit

Permalink
fix: ensure changeset filters are applied on bulk destroy/update
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Apr 16, 2024
1 parent fb90709 commit 3b8a15f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/ash/actions/destroy/bulk.ex
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ defmodule Ash.Actions.Destroy.Bulk do
with {:ok, query} <- authorize_bulk_query(query, atomic_changeset, opts),
{:ok, atomic_changeset, query} <-
authorize_atomic_changeset(query, atomic_changeset, opts),
{query, atomic_changeset} <- add_changeset_filters(query, atomic_changeset),
{:ok, data_layer_query} <- Ash.Query.data_layer_query(query) do
case Ash.DataLayer.destroy_query(
data_layer_query,
Expand Down Expand Up @@ -530,6 +531,10 @@ defmodule Ash.Actions.Destroy.Bulk do
end
end

defp add_changeset_filters(query, changeset) do
{Ash.Query.filter(query, changeset.filter), %{changeset | filter: nil}}
end

defp do_run(domain, stream, action, input, opts, not_atomic_reason) do
resource = opts[:resource]
opts = Ash.Actions.Helpers.set_opts(opts, domain)
Expand Down
5 changes: 5 additions & 0 deletions lib/ash/actions/update/bulk.ex
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ defmodule Ash.Actions.Update.Bulk do
authorize_bulk_query(query, atomic_changeset, opts),
{:ok, atomic_changeset, query} <-
authorize_atomic_changeset(query, atomic_changeset, opts),
{query, atomic_changeset} <- add_changeset_filters(query, atomic_changeset),
{:ok, data_layer_query} <- Ash.Query.data_layer_query(query) do
case Ash.DataLayer.update_query(
data_layer_query,
Expand Down Expand Up @@ -955,6 +956,10 @@ defmodule Ash.Actions.Update.Bulk do
|> Enum.with_index()
end

defp add_changeset_filters(query, changeset) do
{Ash.Query.filter(query, changeset.filter), %{changeset | filter: nil}}
end

defp pre_template(opts, changeset, actor) do
if Ash.Expr.template_references_context?(opts) do
opts
Expand Down

0 comments on commit 3b8a15f

Please sign in to comment.