Declarative action authorization library for Elixir, inspired by CanCanCan.
Provide simple ability rules for your application using idiomatic Elixir patterns, just like this:
defmodule YourApp.Abilities do
import Cantare.Abilities
alias YourApp.Schemas.User
alias YourApp.Schemas.{Item, Post}
use Cantare.Abilities, repo: YourApp.Repo
def abilities(User) do
User
|> can(:show, Item, fn %User{} = user, %Item{} = item -> item.active end)
|> can(:edit, Post, fn %User{} = user, %Post{} = post -> Ecto.DateTime.compare(post.created_at, user.created_at) == :gt end)
|> can(:create, League, fn current_user -> [name: current_user.email] end)
end
end
Further README steps coming soon... This is still a very work-in-progress library that has just been separated out of a private project from which it originated. There is still plenty of problems to resolve - perhaps most importantly, it still needs to be adapted to Ecto 3.
Stay tuned!
If available in Hex, the package can be installed
by adding cantare
to your list of dependencies in mix.exs
:
def deps do
[
{:cantare, "~> 0.1.0"}
]
end
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/cantare.