mobilizon/lib/mobilizon_web/context.ex
Thomas Citharel cb0808dbad
Introduce admin and moderator role, check role on list_users action
Signed-off-by: Thomas Citharel <tcit@tcit.fr>

Add test for guards
2019-03-07 14:18:11 +01:00

23 lines
410 B
Elixir

defmodule MobilizonWeb.Context do
@moduledoc """
Guardian context for MobilizonWeb
"""
@behaviour Plug
import Plug.Conn
alias Mobilizon.Users.User
def init(opts) do
opts
end
def call(conn, _) do
with %User{} = user <- Guardian.Plug.current_resource(conn) do
put_private(conn, :absinthe, %{context: %{current_user: user}})
else
nil ->
conn
end
end
end