mirror of
https://github.com/ash-project/ash.git
synced 2024-09-19 13:03:02 +12:00
fix: support passing a forbidden error to policies per the docs
fixes #1443
This commit is contained in:
parent
0dde9f0fc1
commit
4f31109bd9
2 changed files with 19 additions and 0 deletions
|
@ -70,6 +70,12 @@ defmodule Ash.Error.Forbidden.Policy do
|
|||
|
||||
- `:help_text?`: Defaults to true. Displays help text at the top of the policy breakdown.
|
||||
"""
|
||||
def report(%Ash.Error.Forbidden{errors: errors}) do
|
||||
errors
|
||||
|> Enum.filter(&(&1.__struct__ == __MODULE__))
|
||||
|> Enum.map_join("\n\n", &report/1)
|
||||
end
|
||||
|
||||
def report(error, opts \\ []) do
|
||||
error
|
||||
|> get_errors()
|
||||
|
|
|
@ -190,6 +190,19 @@ defmodule Ash.Test.Policy.SimpleTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "breakdowns can be shown for all policy errors in a forbidden error" do
|
||||
res =
|
||||
assert_raise Ash.Error.Forbidden,
|
||||
~r/No policy conditions applied to this request/,
|
||||
fn ->
|
||||
ResourceWithAPolicyThatDoesntApply
|
||||
|> Ash.read!()
|
||||
end
|
||||
|
||||
assert Ash.Error.Forbidden.Policy.report(res) =~
|
||||
~r/No policy conditions applied to this request/
|
||||
end
|
||||
|
||||
test "an impossible create policy shows the correct error message" do
|
||||
assert_raise Ash.Error.Forbidden, ~r/Cannot use a filter to authorize a create/, fn ->
|
||||
ResourceWithAnImpossibleCreatePolicy
|
||||
|
|
Loading…
Reference in a new issue