mirror of
https://github.com/ash-project/ash.git
synced 2024-09-19 21:13:10 +12:00
fix: honor authorize?
option for calls to aggregate
This commit is contained in:
parent
0ded7366f9
commit
3782f1cfe2
2 changed files with 13 additions and 1 deletions
|
@ -245,7 +245,15 @@ defmodule Ash.Api.Interface do
|
|||
end
|
||||
|
||||
defp split_aggregate_opts(opts) do
|
||||
Keyword.split(opts, Ash.Query.Aggregate.opt_keys())
|
||||
{left, right} = Keyword.split(opts, Ash.Query.Aggregate.opt_keys())
|
||||
|
||||
case Keyword.fetch(left, :authorize?) do
|
||||
{:ok, value} ->
|
||||
{left, Keyword.put(right, :authorize?, value)}
|
||||
|
||||
:error ->
|
||||
{left, right}
|
||||
end
|
||||
end
|
||||
|
||||
def aggregate(query, aggregate_or_aggregates, opts \\ []) do
|
||||
|
|
|
@ -115,17 +115,21 @@ defmodule Ash.Test.Actions.AggregateTest do
|
|||
test "runs authorization" do
|
||||
assert %{count: 0} = Api.aggregate!(Post, {:count, :count}, authorize?: true)
|
||||
|
||||
assert 0 = Api.count!(Post, authorize?: true)
|
||||
|
||||
Post
|
||||
|> Ash.Changeset.for_create(:create, %{title: "title"})
|
||||
|> Api.create!()
|
||||
|
||||
assert %{count: 0} = Api.aggregate!(Post, {:count, :count}, authorize?: true)
|
||||
assert 0 = Api.count!(Post, authorize?: true)
|
||||
|
||||
Post
|
||||
|> Ash.Changeset.for_create(:create, %{title: "title", public: true})
|
||||
|> Api.create!()
|
||||
|
||||
assert %{count: 1} = Api.aggregate!(Post, {:count, :count}, authorize?: true)
|
||||
assert 1 = Api.count!(Post, authorize?: true)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue