prop/vendor/oban_web/lib/oban/web/authentication.ex
Graham McIntire caad7d90a7 Mount Oban Web dashboard at /admin/oban
Vendor oban_web 2.12.1 and oban_met 1.1.0 (taken from the
towerops-web2 vendor tree), bump oban to ~> 2.21, and mount the Oban
dashboard at /admin/oban behind the existing require_admin on_mount
hook. Adds an admin-only "Oban" nav link and extends the Dockerfile
to copy vendor/ before deps.get so production builds pick up the
path dependencies.
2026-04-09 14:07:33 -05:00

30 lines
786 B
Elixir

defmodule Oban.Web.Authentication do
@moduledoc false
import Phoenix.Component
import Phoenix.LiveView
alias Oban.Web.{Resolver, Telemetry}
def on_mount(:default, params, session, socket) do
%{"oban" => oban, "resolver" => resolver, "user" => user} = session
conf = if Oban.whereis(oban), do: Oban.config(oban), else: nil
socket = assign(socket, conf: conf, user: user)
Telemetry.action(:mount, socket, [params: params], fn ->
case Resolver.call_with_fallback(resolver, :resolve_access, [user]) do
{:forbidden, path} ->
socket =
socket
|> put_flash(:error, "Access forbidden")
|> redirect(to: path)
{:halt, socket}
_ ->
{:cont, socket}
end
end)
end
end