Ash FrameworkAF
Ash Framework3y ago
9 replies
rohan

Having some trouble with a custom policy

Hi! I'm using a custom policy like this:

    policy action(:request_generation) do
      forbid_unless Scribble.Checks.ActorIsPayingOrTrialing
    end

and then I have:
defmodule Scribble.Checks.ActorIsPayingOrTrialing do
  use Ash.Policy.SimpleCheck
  require Logger

  def describe(_) do
    "actor is paying or trialing"
  end

  def match?(%Scribble.EmailHandler.User{} = user, _context, _options) do
    Logger.error("\n\n\n============================CHECKING\n\n\n")
    IO.puts("======")
    IO.inspect(user)
    # Scribble.EmailHandler.User.is_paying_or_trialing!(user)
    true
  end

  def match?(_, _, _) do
    Logger.error("===========WHAT IS THIS")
    true
  end
end


However even with this policy with everything set to true, the match? is failing. And my logs aren't showing up.

If I delete the policy, it does what I expect (allow even non paying users through). But adding the policy makes it forbid every user
Was this page helpful?