analytics/lib/plausible_web/plugs/crm_auth_plug.ex
RobertJoonas 6b22806e1f
Allow admin access to locked dashboards (#1710)
* added super-admin access to locked dashboards

* fixed formatting
2022-02-23 13:48:33 -06:00

25 lines
538 B
Elixir

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
id ->
user = Repo.get_by(Plausible.Auth.User, id: id)
if user && Plausible.Auth.is_super_admin?(user.id) do
assign(conn, :current_user, user)
else
conn |> send_resp(403, "Not allowed") |> halt
end
end
end
end