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