curiosum-dev / permit

An uniform authorization library for Elixir. Supports Plug and Phoenix LiveView, aims for much more.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Condition defining with operators other than equality

vincentvanbush opened this issue · comments

Prerequisite for #2.

We would like to be able to define queries like this:

def can(%{role: :visitor} = role) do
  grant(role)
  |> read(Record, approved: true, rating: {:>=, 5))
  |> read(Record, public: true)
end

Because we want Ecto query creation in #2, we would like to use operators that can be transformed to both plain-Elixir usage and transformation to Ecto queries:

  • Comparison operators: ==, !=, <=, >=, <, > aliased to :eq, :neq, :gt, :gte, :lt, :lte
  • Search functions: like/2 and ilike/2, mapped to appropriate regexps (expressions will have to be somehow translated from e.g. "%FOO" to /.*FOO/
  • Regexp matching via SQL ~ (:~, :match) - for this purpose Ecto fragments will have to be used
  • Null check functions: is_nil/1