authy v0.1.1 Authy.Controller

Import this in your Phoenix or Plug application controller to gain convenience macros for doing authorization.

Summary

Macros

Authorizes the controller action for the current user and executes the given block if successful

Scopes the current resource based on the action and user

Macros

authorize(term, opts \\ [], list)

Authorizes the controller action for the current user and executes the given block if successful.

def index(conn, _params) do
  authorize Post do
    # ...
  end
end

def show(conn, %{id: id}) do
  post = Repo.get(Post, id)
  authorize post do
    # ...
  end
end
scope(term, opts \\ [])

Scopes the current resource based on the action and user.

def index(conn, _params) do
  authorize Post do
    posts = scope(Post) |> Repo.all
    # ...
  end
end

def show(conn, %{id: id}) do
  post = scope(Post) |> Repo.get(id)
  authorize post do
    # ...
  end
end