mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +12:00
fix: always return all notifications if return_notifications?: true
This commit is contained in:
parent
084b998cab
commit
e19ca1ec66
6 changed files with 19 additions and 7 deletions
|
@ -51,6 +51,7 @@ defmodule Ash.Actions.Create do
|
|||
authorize?: authorize?,
|
||||
notification_metadata: opts[:notification_metadata],
|
||||
timeout: opts[:timeout] || changeset.timeout || Ash.Api.timeout(api),
|
||||
return_notifications?: opts[:return_notifications?],
|
||||
transaction?: Keyword.get(opts, :transaction?, true)
|
||||
)
|
||||
|> case do
|
||||
|
|
|
@ -58,6 +58,7 @@ defmodule Ash.Actions.Destroy do
|
|||
resource: resource,
|
||||
verbose?: verbose?,
|
||||
actor: actor,
|
||||
return_notifications?: opts[:return_notifications?],
|
||||
notification_metadata: opts[:notification_metadata],
|
||||
authorize?: authorize?,
|
||||
timeout: opts[:timeout] || changeset.timeout || Ash.Api.timeout(api),
|
||||
|
|
|
@ -42,6 +42,7 @@ defmodule Ash.Actions.Update do
|
|||
verbose?: verbose?,
|
||||
actor: actor,
|
||||
notification_metadata: opts[:notification_metadata],
|
||||
return_notifications?: opts[:return_notifications?],
|
||||
authorize?: authorize?,
|
||||
timeout: opts[:timeout] || changeset.timeout || Ash.Api.timeout(api),
|
||||
default_timeout: Ash.Api.timeout(api),
|
||||
|
|
|
@ -57,6 +57,7 @@ defmodule Ash.Engine do
|
|||
# There are no other failure modes, but this is there
|
||||
# to express the intent for there to eventually be.
|
||||
failure_mode: :complete,
|
||||
return_notifications?: false,
|
||||
opts: [],
|
||||
requests: [],
|
||||
data: %{},
|
||||
|
@ -99,8 +100,14 @@ defmodule Ash.Engine do
|
|||
end
|
||||
|> case do
|
||||
{:ok, %{resource_notifications: resource_notifications} = result} ->
|
||||
unsent = Ash.Notifier.notify(resource_notifications)
|
||||
{:ok, %{result | resource_notifications: unsent}}
|
||||
notifications =
|
||||
if opts[:return_notifications?] do
|
||||
resource_notifications
|
||||
else
|
||||
Ash.Notifier.notify(resource_notifications)
|
||||
end
|
||||
|
||||
{:ok, %{result | resource_notifications: notifications}}
|
||||
|
||||
other ->
|
||||
other
|
||||
|
@ -114,6 +121,7 @@ defmodule Ash.Engine do
|
|||
id: System.unique_integer([:positive, :monotonic]),
|
||||
resolved_fields: %{},
|
||||
actor: opts[:actor],
|
||||
return_notifications?: opts[:return_notifications?],
|
||||
concurrency_limit: System.schedulers_online() * 2,
|
||||
authorize?: opts[:authorize?] || false,
|
||||
verbose?: opts[:verbose?] || false,
|
||||
|
@ -711,12 +719,13 @@ defmodule Ash.Engine do
|
|||
end
|
||||
|
||||
defp add_resource_notification(state, resource_notification) do
|
||||
if Ash.DataLayer.in_transaction?(resource_notification.resource) do
|
||||
if Ash.DataLayer.in_transaction?(resource_notification.resource) ||
|
||||
state.return_notifications? do
|
||||
%{state | resource_notifications: [resource_notification | state.resource_notifications]}
|
||||
else
|
||||
Ash.Notifier.notify(resource_notification)
|
||||
unsent = Ash.Notifier.notify(resource_notification)
|
||||
|
||||
state
|
||||
%{state | resource_notifications: unsent ++ state.resource_notifications}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ defmodule Ash.Resource.Dsl do
|
|||
examples: [
|
||||
"""
|
||||
attribute :first_name, :string do
|
||||
primary_key? true
|
||||
allow_nil? false
|
||||
end
|
||||
"""
|
||||
],
|
||||
|
|
|
@ -155,7 +155,7 @@ defmodule Ash.Test.Actions.DestroyTest do
|
|||
|
||||
post_id = post.id
|
||||
|
||||
assert {:ok, %{id: ^post_id}, []} =
|
||||
assert {:ok, %{id: ^post_id}, [_]} =
|
||||
Api.destroy(post, return_destroyed?: true, return_notifications?: true)
|
||||
|
||||
refute Api.read_one!(Ash.Query.filter(Post, id == ^post.id))
|
||||
|
|
Loading…
Reference in a new issue