ash_oban/lib/checks/ash_oban_interaction.ex

29 lines
791 B
Elixir
Raw Normal View History

2023-04-28 14:07:05 +12:00
defmodule AshOban.Checks.AshObanInteraction do
@moduledoc """
This check is true if the context `private.ash_oban?` is set to true.
This context will only ever be set in code that is called internally by
`ash_oban`, allowing you to create a bypass in your policies on your
user/user_token resources.
```elixir
policies do
bypass AshObanInteraction do
authorize_if always()
end
end
```
"""
use Ash.Policy.SimpleCheck
@impl Ash.Policy.Check
def describe(_) do
"AshOban is performing this interaction"
end
@impl Ash.Policy.SimpleCheck
def match?(_, %{query: %{context: %{private: %{ash_oban?: true}}}}, _), do: true
def match?(_, %{changeset: %{context: %{private: %{ash_oban?: true}}}}, _), do: true
def match?(_, _, _), do: false
end