1
1
mirror of https://github.com/plausible/analytics.git synced 2024-12-21 16:41:31 +03:00
analytics/lib/plausible_web/plugs/crm_auth_plug.ex

25 lines
538 B
Elixir
Raw Normal View History

2021-01-07 11:42:45 +03:00
defmodule PlausibleWeb.CRMAuthPlug do
import Plug.Conn
use Plausible.Repo
def init(options) do
options
end
def call(conn, _opts) do
case get_session(conn, :current_user_id) do
nil ->
conn |> send_resp(403, "Not allowed") |> halt
2021-01-07 11:42:45 +03:00
id ->
user = Repo.get_by(Plausible.Auth.User, id: id)
if user && Plausible.Auth.is_super_admin?(user.id) do
2021-01-07 11:42:45 +03:00
assign(conn, :current_user, user)
else
conn |> send_resp(403, "Not allowed") |> halt
end
end
end
end